Skip to main content

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

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.

Metadata

Release files for pap-protocol 0.8.3

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

Source distribution (sdist)

Source distribution for pap-protocol 0.8.3
File Size Uploaded
pap_protocol-0.8.3.tar.gz 275.3 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pap-protocol 0.8.3
File
pap_protocol-0.8.3-cp38-abi3-win_amd64.whl CPython 3.8 abi3 Windows x86-64 Details
pap_protocol-0.8.3-cp38-abi3-musllinux_1_2_x86_64.whl CPython 3.8 abi3 Linux musl 1.2+ x86-64 Details
pap_protocol-0.8.3-cp38-abi3-manylinux_2_28_x86_64.whl CPython 3.8 abi3 Linux glibc 2.28+ x86-64 Details
pap_protocol-0.8.3-cp38-abi3-manylinux_2_28_aarch64.whl CPython 3.8 abi3 Linux glibc 2.28+ ARM64 Details
pap_protocol-0.8.3-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl CPython 3.8 abi3 macOS 11.0+ ARM64, macOS 10.12+ universal2 (ARM64, x86-64), macOS 10.12+ x86-64 Details

Total release size: 23.6 MB

Release files / pap_protocol-0.8.3.tar.gz

Download URL pap_protocol-0.8.3.tar.gz
Size 275.3 kB
Tags Source
SHA-256 checksum
How to use checksums
171115786e9fd598fa6489139648a5d010d362cb616cd6ff5b3a30541dd79d36
BLAKE2b-256 checksum
How to use checksums
bcd72914ac08a35ce4317771d112b85cb9d3c7a4156a28310571362045a1cc29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 8, 2026.

Transparency log

Release files / pap_protocol-0.8.3-cp38-abi3-win_amd64.whl

Download URL pap_protocol-0.8.3-cp38-abi3-win_amd64.whl
Size 3.4 MB
Tags CPython 3.8 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
04b31df75eac753a2c1ea6dd92a25ed48bc4f1e11e85b704d59c60bd306f7da5
BLAKE2b-256 checksum
How to use checksums
cdcf0e27aed2f31a62f06faad9e02b247de8b7fc80dd4d355d0597575dffc537
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 8, 2026.

Transparency log

Release files / pap_protocol-0.8.3-cp38-abi3-musllinux_1_2_x86_64.whl

Download URL pap_protocol-0.8.3-cp38-abi3-musllinux_1_2_x86_64.whl
Size 4.2 MB
Tags CPython 3.8 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
daf123c895289a0839aa9d5cfb911642998e79f653084d183f892f65caa9f289
BLAKE2b-256 checksum
How to use checksums
29e00d2d51945154bedd4f6bd59dcce57db02b772ac49078d2314bac2369afbe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 8, 2026.

Transparency log

Release files / pap_protocol-0.8.3-cp38-abi3-manylinux_2_28_x86_64.whl

Download URL pap_protocol-0.8.3-cp38-abi3-manylinux_2_28_x86_64.whl
Size 4.0 MB
Tags CPython 3.8 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
3ebd510a305bbeffc14201be402a6b066b508622711bab6b8322f15f6e93d3f8
BLAKE2b-256 checksum
How to use checksums
97c7db10ffe8af8593fc610dc70008d1aca1f797739d29a1a21c2719f8852097
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 8, 2026.

Transparency log

Release files / pap_protocol-0.8.3-cp38-abi3-manylinux_2_28_aarch64.whl

Download URL pap_protocol-0.8.3-cp38-abi3-manylinux_2_28_aarch64.whl
Size 3.9 MB
Tags CPython 3.8 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
60cf79d0d40b664e0d44a4d8579015598bf40dd2cc0e38fc14d58f7f3c9673b2
BLAKE2b-256 checksum
How to use checksums
304152d5a3583b1301aea4611600f62edd0f62cdc01000c2e18ad9a665f3d42b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 8, 2026.

Transparency log

Release files / pap_protocol-0.8.3-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl

Download URL pap_protocol-0.8.3-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Size 7.9 MB
Tags CPython 3.8 abi3 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
a79271b271005206d5aa46337da9e02612909b9f22683c83f31bb92dc771eb21
BLAKE2b-256 checksum
How to use checksums
4333a81ad49cdc9c4e379196f3c3dfe3e70183345b7223ffe292d9e9e7335d59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 8, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.8.3 This release

6 release files

0.8.2

6 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