Catalog PyPI
PACKAGE EXPLORERView in registry

agentity-middleware-python

PyPI

Agentity middleware for FastAPI

Versions collected1
Direct dependencies5From release 0.1.1
Last observed20 Oct, 22:28 UTC

README

Version 0.1.1 documentation

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

  1. Extracts Agentity-Token, Agentity-Nonce, Agentity-Timestamp headers
  2. Validates nonce uniqueness (anti-replay)
  3. Checks timestamp is within tolerance window (default ±300s)
  4. Decodes and verifies the Ed25519 AID signature
  5. If registry_url is set, checks GET /did/{did}/status for active status
  6. Injects request.state.agent_did and request.state.agent_scopes
  7. Returns 400 (malformed), 401 (missing), or 403 (invalid/revoked) on failure

Error responses

StatusCondition
400Missing or malformed headers
401Token not provided
403Invalid signature, expired, revoked, or scope violation

Tests

pip install -e .[dev]
pytest ../tests/

License: Apache 2.0

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
0.1.117 May 20265

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
agenttity/agentity

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 22:28 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:e78f1d57c2bf93f14abe0a56fe88e2301b8e8c1641d87300769a5576b82d8c9b