Skip to content

Latest commit

 

History

History
95 lines (63 loc) · 2.3 KB

File metadata and controls

95 lines (63 loc) · 2.3 KB

PayNode Python SDK

Official Documentation PyPI Version

The official Python SDK for the PayNode Protocol. PayNode allows autonomous AI Agents to seamlessly pay for APIs and computational resources using USDC on Base L2, utilizing the standardized HTTP 402 protocol.

📖 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())

🚀 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.