Skip to main content

PayNode Protocol Python SDK for AI Agents

Project description

PayNode Python SDK

Official Documentation PyPI Version

The official Python SDK for the PayNode Protocol (v2.2.1). PayNode allows autonomous AI Agents to seamlessly pay for APIs and computational resources using USDC on Base L2, utilizing the standardized HTTP 402 protocol with support for both on-chain receipts and off-chain signatures (EIP-3009).

📖 Read the Docs

For complete installation guides, advanced usage, API references, and architecture details, please visit our official documentation: 👉 docs.paynode.dev

⚡ Quick Start

Installation

pip install paynode-sdk-python web3

Agent Client (Payer)

from paynode_sdk import PayNodeAgentClient

agent = PayNodeAgentClient(
    private_key="YOUR_AGENT_PRIVATE_KEY",
    rpc_urls=["https://mainnet.base.org", "https://rpc.ankr.com/base"]
)

# Automatically handles the 402 challenge, executes the Base L2 transaction, and gets the data.
response = agent.request_gate("https://api.merchant.com/premium-data", method="POST", json={"agent": "PythonAgent"})

print(response.json())

Key Features (v2.2.1)

  • EIP-3009 Support: Sign payments off-chain using TransferWithAuthorization, allowing for gasless or relayer-mediated settlement.
  • X402 V2 Protocol: JSON-based handshake for more structured and machine-readable payment instructions.
  • Dual Flow: Automatic fallback to V1 (on-chain receipts) for legacy merchant support.
  • FastAPI Middleware: Easy-to-use middleware for merchants to protect their API routes.

🗺️ Roadmap

  • TRON Support: USDT (TRC-20) payment integration.
  • Solana Support: SPL USDC/USDT payment integration.
  • Cross-chain: Universal settlement via bridges.

🚀 Run the Demo

The SDK includes a complete Merchant/Agent demo in the examples/ directory.

1. Setup Environment

Copy the example environment file and fill in your keys:

cp .env.example .env
# Edit .env with your private key and RPC URLs

2. Get Test Tokens (Required for Base Sepolia)

If you're testing on Sepolia, run the helper script to mint 1,000 mock USDC:

python examples/mint_test_tokens.py

3. Run the Merchant Server (FastAPI)

python examples/fastapi_server.py

4. Run the Agent Client

In another terminal:

python examples/agent_client.py

The demo will perform a full loop: 402 Handshake -> On-chain Payment -> 200 Verification.


📦 Publishing to PyPI

To publish a new version of the SDK:

  1. Install build tools:
    pip install build twine
    
  2. Build the package:
    python -m build
    
  3. Upload to PyPI:
    python -m twine upload dist/*
    

Built for the Autonomous AI Economy by PayNodeLabs.

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

paynode_sdk_python-2.5.0.tar.gz (31.9 kB view details)

Uploaded Source

Built Distribution

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

paynode_sdk_python-2.5.0-py3-none-any.whl (27.8 kB view details)

Uploaded Python 3

File details

Details for the file paynode_sdk_python-2.5.0.tar.gz.

File metadata

  • Download URL: paynode_sdk_python-2.5.0.tar.gz
  • Upload date:
  • Size: 31.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for paynode_sdk_python-2.5.0.tar.gz
Algorithm Hash digest
SHA256 71350fda0887f198912f08aa9f08927a100cde96a9151322420c094d060f372b
MD5 5484add64c8ee3f4db8a21e9881c86c3
BLAKE2b-256 44b923ed782e0400c14ecf6938c5a64208fcf4b63f378b8425e0395bf04da3dc

See more details on using hashes here.

File details

Details for the file paynode_sdk_python-2.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for paynode_sdk_python-2.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ad09fe82c1490c572a970074bbc3ea70acab71111f8107a8791c67eee1e601fa
MD5 feee425bd49a4adfd8dffa0d61b1ea43
BLAKE2b-256 d53769e7c41c49b058e04d39884cbcce47c7ee5b5fde2bcc3cf5ff2ee97dc702

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