neva-asgi
ASGI middleware for the Neva framework.
python-neva is the framework-agnostic core: it must not import an ASGI
framework. This package holds the middleware that used to live in
neva.obs.middleware, so that boundary holds.
It sits below the protocol integrations rather than inside one — neva-fastapi
and neva-faststream (in its ASGI mode) can both consume it without depending
on each other.
Install
uv add neva-asgi
Middleware
CorrelationMiddleware
Assigns a correlation ID to every HTTP and WebSocket request, reusing an
inbound X-Request-ID or X-Correlation-ID when it is a valid UUID and
generating one otherwise. The ID is published on scope["state"]["correlation_id"]
and echoed on the response. It is also bound into structlog's context, so every
log line emitted while handling the request carries correlation_id without the
caller threading it through — structlog's default processor chain merges
contextvars, so this needs no logging configuration.
from neva.asgi import CorrelationMiddleware
app.add_middleware(CorrelationMiddleware, header_name="X-Request-ID")
generator and validator are both injectable, so a service that uses ULIDs or
a non-UUID scheme can swap them.
ProfilerMiddleware
Profiles each HTTP request with pyinstrument
and writes an HTML report per request. It names the file after the correlation
ID when CorrelationMiddleware runs ahead of it, and falls back to a timestamp.
from neva.asgi import ProfilerMiddleware
app.add_middleware(ProfilerMiddleware, path="./profiles", interval=0.001)
Intended for local and staging use: it profiles every request and writes a file per request.
Develop
uv sync --all-extras
poe lint && poe fmt && poe tc && poe test
Commits follow Conventional Commits with gitmoji via cz commit; releases are
cut with cz bump.
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 neva_asgi-0.1.1.tar.gz.
File metadata
- Download URL: neva_asgi-0.1.1.tar.gz
- Upload date:
- Size: 106.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8b2da8862e8d0d829551115ef7cef877f04355218af24ea98d27081ff48e5e6
|
|
| MD5 |
22c2af40a6e9aa25b6bbade9e513f04a
|
|
| BLAKE2b-256 |
4fb1163cf1221cc834e051010758c46761a471617e9e965289678860e367931e
|
File details
Details for the file neva_asgi-0.1.1-py3-none-any.whl.
File metadata
- Download URL: neva_asgi-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0583d0ff244f6a9b2ae5d4b325a1554e931bee494aae636db95bb8dda92aedd
|
|
| MD5 |
15d948aedbd509cfa01782b5c5954b72
|
|
| BLAKE2b-256 |
f2bc7e0aad9e02ef0f88abe16f790a6e95525fa80c411bacb71907671c832094
|