Skip to main content

Codios Python SDK — offline contract verification and FastAPI middleware

Project description

codios-sdk

Python SDK for Codios — A2A Agent Security Layer.

Installation

pip install codios-sdk

# With FastAPI middleware
pip install "codios-sdk[fastapi]"

Quick start

Verify a contract (in your agent)

import os
from codios import verify_contract

CODIOS_PUBLIC_KEY = os.environ["CODIOS_PUBLIC_KEY"]

# contract dict comes from the X-Codios-Contract header sent by the caller
result = verify_contract(contract, CODIOS_PUBLIC_KEY, requested_action="summarize")

if not result.valid:
    raise PermissionError(f"Rejected: {result.reason}")
    # reason: contract_expired | invalid_signature | action_not_permitted | action_forbidden

FastAPI middleware

import os
from fastapi import FastAPI, Depends
from codios.middleware.fastapi import require_contract, ContractClaims

app = FastAPI()

# Set CODIOS_PUBLIC_KEY in your environment (from Codios dashboard)

@app.post("/summarize")
async def summarize(
    body: dict,
    claims: ContractClaims = Depends(require_contract("summarize")),
):
    # Contract is already verified at this point
    print(f"Caller: {claims.issuer_did}")
    return {"result": "..."}

The middleware reads X-Codios-Contract from the request header, verifies the Ed25519 signature offline (no network call), checks expiry, and validates the requested action is in allowed_actions.

Generate a keypair (for registering a new agent)

from codios import generate_keypair

kp = generate_keypair()
print(kp.did)         # did:key:z6Mk...
print(kp.public_key)  # base64 — register this with Codios
print(kp.private_key) # base64 — store securely, never share

How it works

  1. Agent A wants to call Agent B. It requests a signed contract from Codios API (POST /contracts).
  2. Codios signs the contract with its Ed25519 platform key and returns it.
  3. Agent A sends the contract in the X-Codios-Contract header when calling Agent B.
  4. Agent B's SDK verifies the signature locally — zero network latency, no single point of failure.
  5. If valid, the call proceeds. The result is logged to the Codios audit trail.

Environment variables

Variable Description
CODIOS_PUBLIC_KEY Base64 Ed25519 public key — from Codios dashboard Settings

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codios_sdk-0.1.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codios_sdk-0.1.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file codios_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: codios_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for codios_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e3ec5091c7bc501ccce1cf9c0415f9b7f52d08485c0f1af263900f82e84d500d
MD5 5af3a67c8254e1d8f1fd81b1ea04dc81
BLAKE2b-256 bd1015ec5d145bb21369be102d1abe824a0b6f77f608d2844e6f2afd1a86121c

See more details on using hashes here.

File details

Details for the file codios_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: codios_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for codios_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a7fe3c677da4f798af7288fa9a537eaca1993d40e8afb054f304748f71122184
MD5 16338344dc437b62e0aa3022c0b8d25c
BLAKE2b-256 b2c69539f24cf14c09cd18469ab782f66fb6bebaccc177ccf8c4bc39660ac115

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page