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).

Teach your coding agent

ubag init            # you are serving a site through UBAG
ubag init --agent    # you are building an agent that reads UBAG-enabled sites
ubag init --both

Writes .agents/skills/ubag-*/SKILL.md into your project, and creates AGENTS.md and CLAUDE.md only if they do not already exist. An AGENTS.md you already have is never modified; the line to add is printed instead. Safe to re-run.

ubag init --check reports whether the copy in your repo is older than the installed SDK.

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.7.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.7.0
File Size Uploaded
ubag-0.7.0.tar.gz 62.8 kB Details

Built distribution (wheel)

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

Total release size: 116.5 kB

Release files / ubag-0.7.0.tar.gz

Download URL ubag-0.7.0.tar.gz
Size 62.8 kB
Tags Source
SHA-256 checksum
How to use checksums
455a9f9cc78627c161bf6fa4b7308c413b78b110e0053b1f142c33744b30da38
BLAKE2b-256 checksum
How to use checksums
f278717bd6918bb3aab20739a2d1dc9a8529b7a41b6b4f7ab36ccf0f30320b20
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 28, 2026.

Transparency log

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

Download URL ubag-0.7.0-py3-none-any.whl
Size 53.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2b081da2643c81ddf04f1f7042ad1542767abad840d83db7fe76486f8d10a550
BLAKE2b-256 checksum
How to use checksums
19363c2ec0536363de2e6d2e50b6eccbb5d02d049c0fc11160a8ea139e9b3344
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 28, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 release files

0.6.0

2 release files

0.5.0

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