ACONS
An asynchronous command-line runner for use in async web-servers like fastapi.
Sometimes, you want to run command-line utilities and expose the output to a web-server. However, it's a bit tricky to capture the console output while it's running, and also allow the web-client to kill the job mid-process.
acons can execute command-line processes as an async function, where output can be retrieved via another async function, and a kill signal can be sent at any time.
Install
pip install acons
run
Function interface:
run(command, run_dir=None, is_parse=False, job_id=None)
command: str of command-line commandrun_dir: optional starting directory of the commandis_parse: optional flag to parse the output as tsv file into a list of dictionariesjob_id: optional id that will be used toflush_linesandkill_job
To use in an async function:
await acons.run('ls', job_id='my-special-id-123')
To test the output in a sync version:
import acons
output = acons.sync_run('ls')
flush_lines
In an async function:
lines = await acons.flush_lines('my-special-id-123')
This will return the console lines produced by the job since the last call to acons.flush_lines
kill_job
In an async function:
`await kill_job('my-special-id-123')
Sends the kill signal for the job.
Parameters d
acons.RUN_INTERVAL_IN_S = 0.2 - determines how long the function polls for each interval
acons.SLEEP_INTERVAL_IN_S = 0.5 - determines how long the function sleeps between intervals
acons.N_MAX_JOB = 100 - maximum number of jobs that stores output using an LRU cache
Example server
A simple fastapi-server/vue-client is included that demonstrates acons in action.
Concurrent command-line commands can be typed in and executed. The console output will be piped back into the web-client, and the job can be cancelled at any time.
When the job is completed, the entire console output is made available through the Monaco web-editor .
Download the .zip version of this package, then run the server:
./test-server.sh
which is essentially:
uvicorn server:app --reload --port=5200
Communication between client/server is via an rpc-json interface as described in rpcseed.
Metadata
Release files for acons 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| acons-0.1.1.tar.gz | 8.7 kB | Without provenance | Details for acons-0.1.1.tar.gz |
Release files / acons-0.1.1.tar.gz
| Download URL | acons-0.1.1.tar.gz |
|---|---|
| Size | 8.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
44edce3d61ec917437ac42209bef703feebc20b2d1eafcfad89a1da8873f9b28
|
|
BLAKE2b-256 checksum How to use checksums |
510b5de7a8ad50c4e74efcf22eb444dea59c45797ca8f882164b4d16b7f1b680
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.5
|
Security for acons 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.