agentity-middleware-python
FastAPI middleware for the Agentity Protocol.
Automatically verify Agentity-signed requests — extract agent identity, validate nonce and timestamp, check status via registry, and inject request.state.agent_did + request.state.agent_scopes.
Installation
pip install agentity-middleware-python
Usage
from fastapi import FastAPI, Request
from agentity_middleware_python import AgentityMiddleware
app = FastAPI()
# Add middleware (optional registry check)
app.add_middleware(
AgentityMiddleware,
registry_url="http://localhost:8000", # Optional: verify DID status
tolerance_seconds=300, # Default: 5 min
)
@app.get("/api/data")
async def get_data(request: Request):
# Verified agent info automatically injected
agent_did = request.state.agent_did # "did:agentity:agent:..."
agent_scopes = request.state.agent_scopes # ["stripe:payments:read", ...]
return {"agent": agent_did, "scopes": agent_scopes}
What it does
- Extracts
Agentity-Token,Agentity-Nonce,Agentity-Timestampheaders - Validates nonce uniqueness (anti-replay)
- Checks timestamp is within tolerance window (default ±300s)
- Decodes and verifies the Ed25519 AID signature
- If
registry_urlis set, checksGET /did/{did}/statusfor active status - Injects
request.state.agent_didandrequest.state.agent_scopes - Returns
400(malformed),401(missing), or403(invalid/revoked) on failure
Error responses
| Status | Condition |
|---|---|
| 400 | Missing or malformed headers |
| 401 | Token not provided |
| 403 | Invalid signature, expired, revoked, or scope violation |
Tests
pip install -e .[dev]
pytest ../tests/
License: Apache 2.0
Metadata
Release files for agentity-middleware-python 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 | |
|---|---|---|---|---|
| agentity_middleware_python-0.1.1.tar.gz | 3.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| agentity_middleware_python-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.2 kB
Release files / agentity_middleware_python-0.1.1.tar.gz
| Download URL | agentity_middleware_python-0.1.1.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5706e6fd8e1a4cad060d59508a38a890d81115d4deeae7f839b193f598c29918
|
|
BLAKE2b-256 checksum How to use checksums |
a8ebe26b2dcf27f0414b8a6dc7a72cb2c979fe7e1bafda5b1abfded416d0c74e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / agentity_middleware_python-0.1.1-py3-none-any.whl
| Download URL | agentity_middleware_python-0.1.1-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
27fe44be2aa9fc25cce1213ae1b6249441ac3027d0c01599bea7900e50e96339
|
|
BLAKE2b-256 checksum How to use checksums |
5e2eb826d78d260deb2cd7daaa95eea00a739f417b8f0a516c1a88f019ac1fa7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Security for agentity-middleware-python 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.