PQSafe AgentPay Python SDK — post-quantum safe payments for AI agents
Project description
pqsafe-agent-pay
Python SDK for PQSafe AgentPay — post-quantum signed payment authorization for AI agents.
Part of the PQSafe AgentPay ecosystem. Uses ML-DSA-65 (NIST FIPS 204) for signing. Integrates with LangChain, CrewAI, AutoGen, and any custom Python agent.
What it does
pqsafe-agent-pay lets a human wallet owner issue a cryptographically-bound SpendEnvelope to an AI agent. The envelope defines exactly what the agent can spend, to whom, and for how long — enforced by an ML-DSA-65 (NIST FIPS 204) post-quantum signature that the agent cannot exceed or forge.
The agent calls pay(signed_envelope, recipient, amount, memo) and the SDK verifies the signature, validates the policy constraints (amount ceiling, recipient allowlist, time window), and dispatches the payment over the configured rail. No centralized server. No long-lived credentials in your agent code. The envelope is the authorization.
Install
pip install pqsafe-agent-pay
For local development:
git clone https://github.com/PQSafe/pqsafe
cd pqsafe/python-sdk
pip install -e ".[dev]"
Quickstart
from pqsafe import create_envelope, generate_keypair, pay, sign_envelope
# 1. Generate an ML-DSA-65 key pair (wallet owner, done once)
keypair = generate_keypair()
# 2. Create a SpendEnvelope — authorizes an AI agent to pay up to $10 USD
envelope = create_envelope(
issuer="pq1" + "a" * 40, # wallet owner's PQSafe address
agent="supplier-bot-v1",
max_amount=10.00,
currency="USD",
allowed_recipients=["supplier-uuid-here"],
ttl_seconds=3600,
)
# 3. Sign the envelope (post-quantum ML-DSA-65)
signed = sign_envelope(envelope, keypair)
# 4. Agent pays — all constraints enforced before dispatch
result = pay(
signed,
recipient="supplier-uuid-here",
amount=5.00,
memo="Invoice #42",
dry_run=True, # remove for live payments; set PQSAFE_API_KEY env var
)
print(result.tx_id) # "dry-run-no-http" (dry_run) or live txId
print(result.status) # "dry_run" or "success"
Set PQSAFE_API_KEY in your environment and remove dry_run=True for live calls.
What you get
- FIPS 204 ML-DSA-65 signing — 128-bit post-quantum security; powered by
pqcrypto>=0.4.0 - Policy enforcement — amount ceiling, recipient allowlist, and validity window enforced before any payment is dispatched
- Replay protection — 128-bit random nonce per envelope; envelopes cannot be reused
- Multi-rail routing — Airwallex (live sandbox), Wise, Stripe, USDC on Base, x402 via the PQSafe API
- Framework plugins —
langchain-pqsafeandcrewai-pqsafewrap this SDK for one-line tool registration - AP2 adapter — interop with Google AP2 mandates (
pqsafe.adapters) - ACP adapter — interop with Stripe ACP Shared Payment Tokens (
pqsafe.adapters) - Spend policy modes —
SingleUsePolicy,PerTxCapPolicy,CumulativeCapPolicyviapqsafe.sprint2 - Classical fallback — if
pqcryptocannot be installed, Ed25519 is used (clearly marked; not post-quantum secure; not for production)
API reference
generate_keypair() -> KeyPair
Generate an ML-DSA-65 key pair. Returns a KeyPair with .public_key and .secret_key as raw bytes. Use .public_key_hex() and .secret_key_hex() for hex-encoded strings.
create_envelope(...) -> SpendEnvelope
| Parameter | Type | Description |
|---|---|---|
issuer |
str |
PQSafe address (pq1 + 40 hex chars) |
agent |
str |
Agent identifier (1–128 chars) |
max_amount |
float |
Maximum spend allowed |
currency |
str |
ISO 4217 currency code (e.g. "USD") |
allowed_recipients |
list[str] |
Allowlist of recipient addresses |
starts_in_seconds |
int |
Delay before activation (default 0) |
ttl_seconds |
int |
Validity window in seconds (default 3600) |
rail |
str | None |
Optional rail constraint |
sign_envelope(envelope, keypair) -> SignedEnvelope
Sign a SpendEnvelope with the issuer's ML-DSA-65 key pair.
verify_envelope(signed, public_key=None) -> SpendEnvelope
Verify a SignedEnvelope. Raises ValueError on invalid signature or expired envelope.
pay(signed_envelope, ...) -> PaymentResult
Verify the envelope and POST to /v1/pay. Accepts a PaymentRequest, plain dict, or keyword args (recipient, amount, memo, api_key, base_url, dry_run).
Framework plugins
For LangChain or CrewAI agents, install the framework-specific plugin instead — it wraps this SDK as a drop-in tool:
pip install langchain-pqsafe # LangChain tool: PQSafePaymentTool
pip install crewai-pqsafe # CrewAI tool: PQSafePaymentTool
Both plugins use this SDK under the hood — same envelope format, same signature verification, same rails.
Part of PQSafe AgentPay
@pqsafe/agent-pay— core TypeScript SDK@pqsafe/mastra— Mastra workflow integrationlangchain-pqsafe— LangChain toolcrewai-pqsafe— CrewAI tool
Links
- Main repo: github.com/PQSafe/pqsafe
- Docs: docs.pqsafe.xyz
- Live demo: demo.pqsafe.xyz
- Website: pqsafe.xyz
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pqsafe_agent_pay-0.1.1.tar.gz.
File metadata
- Download URL: pqsafe_agent_pay-0.1.1.tar.gz
- Upload date:
- Size: 49.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32c00cbf903be9a3a5e996a6898892406298654f5130045fe419fb613a1e25f7
|
|
| MD5 |
8482ecb403c5f1b89d9e98a00b87e3b5
|
|
| BLAKE2b-256 |
99a58f23a13071a078dcd802b5730ef8d9b001c743468963c92933c19842e095
|
File details
Details for the file pqsafe_agent_pay-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pqsafe_agent_pay-0.1.1-py3-none-any.whl
- Upload date:
- Size: 41.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2689df8ce47a4cdb8851d19f19a6bf7053529c768536cf8da3a005455c79d6e
|
|
| MD5 |
97a3d63c0150f73783e9f0ea9b9becb7
|
|
| BLAKE2b-256 |
fc464c381a08d188331fb8ee41d7f4a561ed79ead92c18ef2f8a9158162d02cc
|