Call ASGI Python application from command line, just like CURL
Project description
ASGI CLI
Call ASGI Python application from command line, just like CURL.
If you’re using this tool, ★Star this repository to show your interest, please!
Install
pip install -U asgi-cli
Usage
asgi-cli --help
usage: asgi-cli [-h] [-V] [-X COMMAND] [-H HEADER] [-d DATA | -F MULTIPART]
[-I] [-b] [-p] [-n NUMBER] [-v]
app [url]
positional arguments:
app an application module
url a uniform resource locator or path (default /)
optional arguments:
-h, --help show this help message and exit
-V, --version show program's version number and exit
-X COMMAND, --request COMMAND
specify request command to use, e.g. POST (default
GET)
-H HEADER, --header HEADER
pass custom header line, e.g. -H='Accept:
application/json'
-d DATA, --data DATA request body data, e.g. '{"msg":"hello"}', 'msg=hello'
-F MULTIPART, --form MULTIPART
specify HTTP multipart POST data, e.g. name=value or
name=@file
-I, --head show status and headers only
-b, --benchmark issue a number of requests through repeated iterations
(reports throughtput and average call time)
-p, --profile prints out a report of top 10 functions ordered by
internal time, saves to 'stats.cprof' file
-n NUMBER a number of requests to issue (default 100K)
-v, --verbose make the operation more talkative
Examples
example.py:
START = {
"type": "http.response.start",
"status": 200,
"headers": [
(b"content-length", b"13"),
(b"content-type", b"text/html; charset=utf-8"),
],
}
BODY1 = {"type": "http.response.body", "body": b"Hello"}
BODY2 = {"type": "http.response.body", "body": b", world!"}
async def app(scope, receive, send) -> None:
await send(START)
await send(BODY1)
await send(BODY2)
Then run the examples:
asgi-cli example:app prints response body:
Hello, world!
asgi-cli -v example:app pretty prints scope and sent messages:
{'scope': {'asgi': {'spec_version': '2.1', 'version': '3.0'},
'client': ('127.0.0.1', 49327),
'headers': [(b'accept', b'*/*'),
(b'user-agent', b'asgi-cli/0.0.1'),
(b'host', b'127.0.0.1:8000')],
'http_version': '1.1',
'method': 'GET',
'path': '/',
'query_string': b'',
'raw_path': b'/',
'root_path': '',
'scheme': 'http',
'server': ('127.0.0.1', 8000),
'type': 'http'}}
{'message': {'headers': [(b'content-length', b'13'),
(b'content-type', b'text/html; charset=utf-8')],
'status': 200,
'type': 'http.response.start'}}
{'message': {'body': b'Hello', 'type': 'http.response.body'}}
{'message': {'body': b', world!', 'type': 'http.response.body'}}
asgi-cli -b example:app shows execution stats (runs in 3 iterations, for each iteration displays requests per second and an average call time):
#1 => 477.74K, 2.09μs
#2 => 438.12K, 2.28μs
#3 => 446.90K, 2.24μs
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file asgi-cli-0.4.3.tar.gz.
File metadata
- Download URL: asgi-cli-0.4.3.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
517a0c0269b2e7ce6c1828e9be61dc440fc5543298243351d1aaaeeb91c4f351
|
|
| MD5 |
137df3d20c05494d598894f774be8650
|
|
| BLAKE2b-256 |
c206ee41f3c192c2e75f23fe29f0b9703fb086b103de09aaee10179826584303
|
File details
Details for the file asgi_cli-0.4.3-py3-none-any.whl.
File metadata
- Download URL: asgi_cli-0.4.3-py3-none-any.whl
- Upload date:
- Size: 11.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48f552e08a3d35c1754e4b00afcfb9960a5e96e56e604f98650d6f8f439c0917
|
|
| MD5 |
31eac4c884d93c7056fda1cb2e36795a
|
|
| BLAKE2b-256 |
80588c671ee144d36eaaa16dfb0ee5be978652f49eeee4e05a45d16c9484d6cc
|