A minimalist REST API wrapper for python's subprocess API.
Project description
Flask-Shell2HTTP
A minimalist REST API wrapper for python's subprocess API.
Execute shell commands asynchronously and safely from flask's endpoints.
Inspired by the work of awesome folks over at msoap/shell2http.
You can use this for
- Set a script that runs on a succesful POST request to an endpoint of your choice. See Example code
- Map a base command to an endpoint and passing dynamic arguments to it. See Example code
- Can also process uploaded files. See Example code
- Choose to run a command asynchronously or not. (upcoming feature)
Quick Start
Dependencies
- Python:
>=v3.6
- Flask
- Flask-Executor
Install
$ pip install flask_shell2http flask_executor
Example
from flask import Flask
from flask_executor import Executor
from flask_shell2http import Shell2HTTP
# Flask application instance
app = Flask(__name__)
executor = Executor(app)
shell2http = Shell2HTTP(app=app, executor=executor, base_url_prefix="/commands/")
shell2http.register_command(endpoint="saythis", command_name="echo")
Run the application server with, $ flask run -p 4000
.
Make HTTP calls
$ curl -X POST -d '{"args": ["Hello", "World!"]}' http://localhost:4000/commands/saythis
or using python's requests module,
data = {"args": ["Hello", "World!"]}
resp = requests.post("http://localhost:4000/commands/saythis", json=data)
print("Result:", resp.json())
returns JSON,
{
"key": "ddbe0a94847c65f9b8198424ffd07c50",
"status": "running"
}
Then using this key
you can query for the result,
$ curl http://localhost:4000/commands/saythis?key=ddbe0a94847c65f9b8198424ffd07c50
Returns result in JSON,
{
"end_time": 1593019807.782958,
"error": "",
"md5": "ddbe0a94847c65f9b8198424ffd07c50",
"process_time": 0.00748753547668457,
"report": {
"result": "Hello World!\n"
},
"start_time": 1593019807.7754705,
"status": "success"
}
Why?
This was made to integrate various command-line tools easily with IntelOwl.
Various examples
You can find various examples under examples
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file Flask-Shell2HTTP-1.0.0.tar.gz
.
File metadata
- Download URL: Flask-Shell2HTTP-1.0.0.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5dcb59cd9f169698147e4727e8d0496e96cc9de5fb89a91bb21a45403a062913 |
|
MD5 | 0fa0c25d9844858fedfa3fbcfbe8dfe1 |
|
BLAKE2b-256 | 4f9df4da34200cd4c62024f49a7cda35e2328ad1d95f3637ca04dcca85f3ce99 |
File details
Details for the file Flask_Shell2HTTP-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: Flask_Shell2HTTP-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1086cc22151d81fc347493ee614d494ddc66756a93b89007b997d02114bd396 |
|
MD5 | 078e9979680525e31c647f3a058d82e9 |
|
BLAKE2b-256 | 7e6a6f3399c6f7d517a6d5abfbad7d96a247046f0b14c3c60928bb4e13e9c0b8 |