Skip to main content

Python SDK for the Principal Agent Protocol (PAP)

Project description

pap — Python SDK for the Principal Agent Protocol

pip install pap-protocol

Python bindings (via PyO3) for the Principal Agent Protocol (PAP) — a cryptographic delegation framework that gives AI agents a verifiable chain of authority back to a human principal.

Quick start

import datetime
from pap import (
    PrincipalKeypair, SessionKeypair,
    Scope, ScopeAction, DisclosureSet,
    Mandate, MandateChain,
    PapSignatureError, PapScopeError,
)

# 1. Generate the principal's root keypair (store securely — this is your identity)
principal = PrincipalKeypair.generate()
print(principal.did())  # did:key:z6Mk...

# 2. Define what the agent is allowed to do
scope = Scope([ScopeAction("schema:SearchAction")])
ds = DisclosureSet.empty()

# 3. Issue and sign a root mandate
ttl = (datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(hours=1)).isoformat()
mandate = Mandate.issue_root(principal.did(), "did:key:zagent", scope, ds, ttl)
mandate.sign(principal)

# 4. Verify (raises PapSignatureError on failure)
try:
    mandate.verify_with_keypair(principal)
    print("mandate verified ✓")
except PapSignatureError as e:
    print(f"invalid signature: {e}")

# 5. Delegate to a sub-agent (scope must be ⊆ parent)
agent_key = SessionKeypair.generate()
child = mandate.delegate(agent_key.did(), scope, ds, ttl)
child.sign_with_session_key(agent_key)

chain = MandateChain(mandate)
chain.push(child)
chain.verify_chain([principal, agent_key])  # accepts mixed keypair types
print(f"chain depth: {len(chain)}")

Exception hierarchy

All PAP errors inherit from PapError:

Exception Raised when
PapSignatureError Signature missing, invalid, or tampered
PapScopeError Delegation exceeds parent scope or TTL
PapSessionError Invalid state transition or nonce replay
PapTransportError HTTP connection failure or bad server response

Installation

From PyPI (recommended)

pip install pap-protocol

Pre-built wheels are available for:

  • Linux x86_64 (glibc 2.28+)
  • Linux x86_64 (musl, for Alpine)
  • Linux aarch64 (glibc 2.28+)
  • macOS (universal2: x86_64 + Apple Silicon)
  • Windows x86_64

The package uses the Python Stable ABI (abi3), so a single wheel works across Python 3.8–3.13+.

From source

cd crates/pap-python
pip install maturin
maturin develop          # development install in current Python env
maturin build --release  # produce a distributable wheel

Or use the build script:

./crates/pap-python/scripts/build-wheels.sh
pip install crates/pap-python/dist/*.whl

Requires Rust 1.75+ and Python 3.8+.

Publishing

Releases are automated via GitHub Actions. To publish a new version:

  1. Update version in pyproject.toml
  2. Update CHANGELOG.md
  3. Commit, then tag and push:
    git tag python-v0.1.0
    git push origin python-v0.1.0
    

The workflow builds wheels for all platforms and publishes to PyPI via OIDC trusted publishing. See .github/workflows/release-python.yml for details.

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

pap_protocol-0.8.3.tar.gz (275.3 kB view details)

Uploaded Source

Built Distributions

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

pap_protocol-0.8.3-cp38-abi3-win_amd64.whl (3.4 MB view details)

Uploaded CPython 3.8+Windows x86-64

pap_protocol-0.8.3-cp38-abi3-musllinux_1_2_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ x86-64

pap_protocol-0.8.3-cp38-abi3-manylinux_2_28_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.28+ x86-64

pap_protocol-0.8.3-cp38-abi3-manylinux_2_28_aarch64.whl (3.9 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.28+ ARM64

pap_protocol-0.8.3-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (7.9 MB view details)

Uploaded CPython 3.8+macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

File details

Details for the file pap_protocol-0.8.3.tar.gz.

File metadata

  • Download URL: pap_protocol-0.8.3.tar.gz
  • Upload date:
  • Size: 275.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pap_protocol-0.8.3.tar.gz
Algorithm Hash digest
SHA256 171115786e9fd598fa6489139648a5d010d362cb616cd6ff5b3a30541dd79d36
MD5 da3c9407840568a18b0e4fcf51727005
BLAKE2b-256 bcd72914ac08a35ce4317771d112b85cb9d3c7a4156a28310571362045a1cc29

See more details on using hashes here.

Provenance

The following attestation bundles were made for pap_protocol-0.8.3.tar.gz:

Publisher: release-python.yml on Baur-Software/pap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pap_protocol-0.8.3-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: pap_protocol-0.8.3-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 3.4 MB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pap_protocol-0.8.3-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 04b31df75eac753a2c1ea6dd92a25ed48bc4f1e11e85b704d59c60bd306f7da5
MD5 26192ad7b94a7987559a0874638328f7
BLAKE2b-256 cdcf0e27aed2f31a62f06faad9e02b247de8b7fc80dd4d355d0597575dffc537

See more details on using hashes here.

Provenance

The following attestation bundles were made for pap_protocol-0.8.3-cp38-abi3-win_amd64.whl:

Publisher: release-python.yml on Baur-Software/pap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pap_protocol-0.8.3-cp38-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pap_protocol-0.8.3-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 daf123c895289a0839aa9d5cfb911642998e79f653084d183f892f65caa9f289
MD5 d0c7e28f99cb4f122d3e413774489473
BLAKE2b-256 29e00d2d51945154bedd4f6bd59dcce57db02b772ac49078d2314bac2369afbe

See more details on using hashes here.

Provenance

The following attestation bundles were made for pap_protocol-0.8.3-cp38-abi3-musllinux_1_2_x86_64.whl:

Publisher: release-python.yml on Baur-Software/pap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pap_protocol-0.8.3-cp38-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pap_protocol-0.8.3-cp38-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3ebd510a305bbeffc14201be402a6b066b508622711bab6b8322f15f6e93d3f8
MD5 9be127b3cab3757b246e7398eb62aec9
BLAKE2b-256 97c7db10ffe8af8593fc610dc70008d1aca1f797739d29a1a21c2719f8852097

See more details on using hashes here.

Provenance

The following attestation bundles were made for pap_protocol-0.8.3-cp38-abi3-manylinux_2_28_x86_64.whl:

Publisher: release-python.yml on Baur-Software/pap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pap_protocol-0.8.3-cp38-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pap_protocol-0.8.3-cp38-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 60cf79d0d40b664e0d44a4d8579015598bf40dd2cc0e38fc14d58f7f3c9673b2
MD5 c01ad93ac1f75d36ee64dd5f1881f889
BLAKE2b-256 304152d5a3583b1301aea4611600f62edd0f62cdc01000c2e18ad9a665f3d42b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pap_protocol-0.8.3-cp38-abi3-manylinux_2_28_aarch64.whl:

Publisher: release-python.yml on Baur-Software/pap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pap_protocol-0.8.3-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for pap_protocol-0.8.3-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 a79271b271005206d5aa46337da9e02612909b9f22683c83f31bb92dc771eb21
MD5 71ccaadb7e7b297bf4d867b83c4d0d55
BLAKE2b-256 4333a81ad49cdc9c4e379196f3c3dfe3e70183345b7223ffe292d9e9e7335d59

See more details on using hashes here.

Provenance

The following attestation bundles were made for pap_protocol-0.8.3-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:

Publisher: release-python.yml on Baur-Software/pap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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