Skip to main content

bpc-server

Python server-side middleware for the BPC (Bound Pair Credentials) protocol. Verifies BPC-signed requests in FastAPI and Flask applications using the full 12-step pipeline from the BPC spec v1.0.

Install

pip install bpc-server[fastapi]   # FastAPI + Starlette
pip install bpc-server[flask]     # Flask
pip install bpc-server[all]       # Both

FastAPI

from fastapi import FastAPI, Request
from bpc_server import BPCFastAPIMiddleware, InMemoryPairRegistry, PairRecord

app = FastAPI()
registry = InMemoryPairRegistry()

# Register a pair (in production, load from your database)
registry.register(PairRecord(
    pair_id="pair_abc123",
    name="my-agent",
    scope="read-write",
    mode="development",
    public_key_jwk={...},  # from bpc-client registration
    secret_hash="argon2id_hash_here",
))

app.add_middleware(BPCFastAPIMiddleware, registry=registry)

@app.get("/api/data")
async def get_data(request: Request):
    pair = request.state.bpc_pair  # BPCVerificationResult
    return {"pair_id": pair.pair_id, "scope": pair.pair.scope}

Flask

from flask import Flask, g
from bpc_server import BPCFlaskMiddleware, InMemoryPairRegistry

app = Flask(__name__)
registry = InMemoryPairRegistry()
BPCFlaskMiddleware(app, registry=registry)

@app.route("/api/data")
def get_data():
    return {"pair_id": g.bpc_pair_id}

Standalone Verifier

from bpc_server import BPCVerifier, InMemoryPairRegistry, InMemoryNonceStore

verifier = BPCVerifier(registry=registry, nonce_store=InMemoryNonceStore())
result = verifier.verify(headers=request.headers, method="GET", path="/api/data")
if not result.ok:
    return 401, result.error_code

12-Step Verification Pipeline

  1. Headers present (X-BPC-Pair-ID, X-BPC-Signature, X-BPC-Signed-Data, X-BPC-Version)
  2. Pair exists and is active (not revoked, not expired)
  3. Pair not locked out
  4. Decode and parse canonical payload
  5. Protocol version check ("1.0")
  6. Timestamp within ±60s window
  7. Nonce not seen before (replay prevention)
  8. Method and path match payload
  9. Body hash match (SHA-256)
  10. ECDSA-SHA-256 signature valid
  11. Scope enforcement (read / read-write / admin)

See the full spec.

Release files for bpc-server 1.0.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 bpc-server 1.0.0
File Size Uploaded
bpc_server-1.0.0.tar.gz 8.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bpc-server 1.0.0
File Interpreter ABI Platform
bpc_server-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.3 kB

Release files / bpc_server-1.0.0.tar.gz

Download URL bpc_server-1.0.0.tar.gz
Size 8.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5d24acaf62466c8692be471030dee74079304c89a7e428bb735f584dccbc1caf
BLAKE2b-256 checksum
How to use checksums
3dbf646f46fae3060b5c2073979d058aa6ae8704ae89d9068166081e827c8b38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.0rc1

Release files / bpc_server-1.0.0-py3-none-any.whl

Download URL bpc_server-1.0.0-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9dba93cba902bee3b67cc9d9887a250c870642d840d78cd0684ab124f8b645a6
BLAKE2b-256 checksum
How to use checksums
9eab7458524e1bdc6389b64e202d5ad2d5e920156a4d7bbe9e5f6621e5019908
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.0rc1

Release history Release notifications | RSS feed

This release

1.0.0 This release

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