Skip to main content

ASGI protocol inspector — validates, traces, and analyzes your ASGI app

Project description

asgion

PyPI Python License

ASGI protocol inspector — validates your ASGI application against the ASGI specification at runtime. Catches protocol violations, state machine errors, and event schema mismatches before they become production bugs.

Zero runtime dependencies. Python 3.12+.

Quickstart

Python API

pip install asgion
from asgion import inspect

app = inspect(app)  # wrap any ASGI app — zero config

Use with any ASGI server:

import uvicorn

uvicorn.run(inspect(app), host="127.0.0.1", port=8000)

CLI

pip install asgion[cli]
asgion check myapp:app

What It Catches

75 rules across 7 layers — from basic scope validation to HTTP/WebSocket/Lifespan state machine enforcement.

[G-005]  error    Message must be a dict
[HE-017] error    response.body 'body' must be bytes, got str
[HF-004] error    Duplicate http.response.start
[WE-012] warning  websocket.send has both 'bytes' and 'text' set

Every rule has an ID, severity, summary, and hint. See the full list: docs/rules.md

CLI Reference

asgion check

asgion check APP_PATH [OPTIONS]

Check an ASGI app for protocol violations.

Option Description
APP_PATH Module:attribute path (e.g. myapp:app)
--url PATH URL paths to check (repeatable, default /)
--strict Exit 1 on any violations
--format text|json Output format (default text)
--exclude-rules IDS Comma-separated rule IDs to skip
--min-severity LEVEL Minimum severity: perf, info, warning, error
--no-color Disable ANSI colors (also respects NO_COLOR env)
--no-lifespan Skip lifespan startup/shutdown checks

Exit codes: 0 = clean, 1 = violations (with --strict), 2 = runtime error.

asgion rules

asgion rules [OPTIONS]

List all 75 validation rules.

Option Description
--format text|json Output format (default text)
--layer LAYER Filter by layer: general, http, websocket, lifespan
--severity LEVEL Filter by severity: perf, info, warning, error
--no-color Disable ANSI colors

asgion --version

Print version and exit.

Python API

from asgion import inspect

wrapped = inspect(
    app,
    strict=False,                          # True to raise on violations
    on_violation=lambda v: print(v),       # real-time callback
    exclude_paths=["/health", "/metrics"], # skip these paths
    exclude_rules={"HE-012", "G-008"},     # suppress specific rules
)

Parameters

Parameter Type Default Description
app ASGIApp required The ASGI application to wrap
strict bool False Raise ASGIProtocolError on any violation
on_violation callback None Called with each Violation in real-time
exclude_paths list[str] None Paths to skip validation
exclude_rules set[str] None Rule IDs to suppress
registry ValidatorRegistry None Custom validator registry

Violation

@dataclass(frozen=True, slots=True)
class Violation:
    rule_id: str       # "HF-001", "G-010"
    severity: Severity # error, warning, info, perf
    message: str       # human-readable description
    hint: str          # suggestion for fixing
    scope_type: str    # "http", "websocket", "lifespan"
    path: str          # "/api/users"
    method: str        # "GET"

Comparison

Feature asgion asgiref.testing Manual testing
Scope validation 14 rules basic none
Event schema checks 40+ rules none manual
State machine (FSM) 21 rules none none
Real-time callbacks yes no n/a
CLI tool yes no no
Zero dependencies yes no (asgiref) n/a
Rule suppression per-rule no n/a

Contributing

git clone https://github.com/ack1d/asgion.git
cd asgion
uv sync --group dev
uv run pytest              # run tests
uv run ruff check src/     # lint
uv run mypy src/           # type check

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asgion-0.1.0.tar.gz (21.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

asgion-0.1.0-py3-none-any.whl (32.4 kB view details)

Uploaded Python 3

File details

Details for the file asgion-0.1.0.tar.gz.

File metadata

  • Download URL: asgion-0.1.0.tar.gz
  • Upload date:
  • Size: 21.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for asgion-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d0bb5da2d6ec4da390d412e0a1d0d3bb4e3f21797bf907fa0571e5c870a3413f
MD5 47212cebce18138a5764e24ad39c37da
BLAKE2b-256 90adda411d53d587eabb5790d863f5c771914590f6d32b07bc2fee5deb8a7286

See more details on using hashes here.

Provenance

The following attestation bundles were made for asgion-0.1.0.tar.gz:

Publisher: publish.yml on ack1d/asgion

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file asgion-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: asgion-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 32.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for asgion-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 32880869e1bb11a4c395cb69d1f95866152d2ed8b180b528c3af541bf52a044d
MD5 dcf7071bcdafa2c4e5abcae906d81e96
BLAKE2b-256 e97f4decf7ca5ce81bde9b7eac6f02c5c0d00cb5af6e6add732340b2fa67e626

See more details on using hashes here.

Provenance

The following attestation bundles were made for asgion-0.1.0-py3-none-any.whl:

Publisher: publish.yml on ack1d/asgion

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page