Skip to main content

ubag (Python)

UBAG Web Layer — agent identity and routing at the web edge. FastAPI / Starlette middleware.

When an autonomous agent visits a website, UBAG verifies who it is and routes accordingly: humans to your normal site, credentialed agents to clean JSON-LD, unknown automation to a cryptographic challenge. Identity verification and site authorization are separate. Asymmetric by design — agent identity is an Ed25519 keypair; credentials are ES256 JWTs verifiable via JWKS, no shared secrets.

Early but real, pre-1.0, unaudited. See the full README and SECURITY.md.

Install

pip install "ubag[fastapi]"

Quick start

from fastapi import FastAPI
from ubag import UBAGMiddleware, generate_issuer_keypair

issuer_private, _ = generate_issuer_keypair()   # EC P-256 (ES256)
trusted_agents = {"ubag:replace-with-an-approved-agent-id"}

app = FastAPI()
app.add_middleware(
    UBAGMiddleware,
    origin="https://yoursite.com",
    issuer_key=issuer_private,                  # mints + verifies credentials
    server_secret="a-separate-random-32+char-secret",
    authorize_agent=lambda identity, request: identity["agent_id"] in trusted_agents,
    # site_meta is OPTIONAL — Branch B auto-extracts structured data from your
    # origin's HTML (JSON-LD/OpenGraph/meta). Pass site_meta only to override.
)

Your site now serves credentialed agents auto-extracted JSON-LD plus a labeled Markdown content layer (no hand-written metadata), proxies humans to your origin, challenges unknown automation, exposes /.well-known/ubag.json for discovery, and serves its issuer key as JWKS at /.well-known/jwks.json. Credentials are holder-of-key: agents attach a one-time request-bound proof-of-possession via agent.headers(method, absolute_url).

A Node/Express SDK with an identical, cross-verifiable wire format is in the same repo. Full docs, a runnable demo, and the protocol details: https://github.com/mohameduk/Ubag_protocol

MIT licensed.

Release files for ubag 0.5.0

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

Source distribution (sdist)

Source distribution for ubag 0.5.0
File Size Uploaded
ubag-0.5.0.tar.gz 39.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ubag 0.5.0
File Interpreter ABI Platform
ubag-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 72.0 kB

Release files / ubag-0.5.0.tar.gz

Download URL ubag-0.5.0.tar.gz
Size 39.4 kB
Tags Source
SHA-256 checksum
How to use checksums
74e02da37f3395bcc12242094d5c47ed9b5bc55691e071c25ba7dae9938fbd92
BLAKE2b-256 checksum
How to use checksums
1c3f80c48c33046ad04525e2ccbae80f163e86a129db7f90077ca8a0da326bdb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 13, 2026.

Transparency log

Release files / ubag-0.5.0-py3-none-any.whl

Download URL ubag-0.5.0-py3-none-any.whl
Size 32.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9beb285d02814855f54e5bafb93744c538e63dcb11a3e18dbfa00d85b5af534f
BLAKE2b-256 checksum
How to use checksums
63c1c0eedffb61d573aa856624673278189fbd3d5a4c5ac71459587120e39370
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 13, 2026.

Transparency log

Release history Release notifications | RSS feed

0.7.0

2 release files

0.6.0

2 release files

This release

0.5.0 This release

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

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