Skip to main content

ASGI CLI

tests Coverage Status pypi version

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] [--app-dir APP_DIR] [-X METHOD] [-H HEADER]
                [-d DATA | -F MULTIPART] [-I | -b | -p | -v]
                [--root-path ROOT_PATH] [-n NUMBER]
                app [url]

positional arguments:
  app                   an application module
  url                   a uniform resource locator or path (default /)

options:
  -h, --help            show this help message and exit
  -V, --version         show program's version number and exit
  --app-dir APP_DIR     look for APP in the specified directory, by adding this to the PYTHONPATH
  -X, --request METHOD  specify request method to use, e.g. POST (default GET)
  -H, --header HEADER   pass custom header line, e.g. -H='Accept: application/json'
  -d, --data DATA       request body data, e.g. '{"msg":"hello"}', 'msg=hello'
  -F, --form MULTIPART  specify HTTP multipart POST data, e.g. name=value or name=@file
  -I, --head            show status and headers only
  --root-path ROOT_PATH
                        set the ASGI 'root_path'
  -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

Metadata

Release files for asgi-cli 0.4.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for asgi-cli 0.4.5
File Size Uploaded Provenance
asgi_cli-0.4.5.tar.gz 11.7 kB Without provenance Details

Release files / asgi_cli-0.4.5.tar.gz

Download URL asgi_cli-0.4.5.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
17122e36e0a80935314e8bb78ab3c7685e07e163d47e3b80df3e2f7ab6f16fc4
BLAKE2b-256 checksum
How to use checksums
122526b5ffb7f867aee18c8ccbcd56aaa5417a248202fd2f8014d28e9e38cb8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Security for asgi-cli 0.4.5

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page