insomnia-plugin-better-python
v0.1.2
Published
Run Python files from inside Insomnia!
Downloads
992
Readme
Better Python
Run Python files from inside Insomnia!
Installation
- Open Insomnia
- Go to Application > Preferences > Plugins
- Type
insomnia-plugin-better-python
in the search bar - Install the plugin
Usage
Write your Python code in a file and save it. The output from stdout will be used as the plugin's response.
For instance, inside a file called "example.py":
import sys
USAGE_MESSAGE = f'Usage: python {sys.argv[0]} <number>'
def square(n: int) -> int:
return n ** 2
if __name__ == '__main__':
try:
n = int(sys.argv[1])
print(square(n))
except (IndexError, ValueError):
print(USAGE_MESSAGE)
sys.exit(-1)
To run this script from Insomnia:
- Create a new request
- Hit
Ctrl+Space
to open the plugin dropdown - Select
Better Python
and click on the new button that was inserted
- Choose your Python interpreter and the file you want to run
- Provide any arguments you want to pass to the script
- Hit
Done
and thenRun
Credits
Heavily inspired by insomnia-plugin-python-script by @Wuerike.