Python SDK for Xenarch — payment middleware for AI agents and publishers
Project description
xenarch
Python SDK for Xenarch, the payment network for AI agents. Pay for any x402-gated content or API with USDC micropayments on Base.
Install
# For AI agents (wallet + on-chain payments)
pip install xenarch[agent]
# For LangChain agents
pip install xenarch[agent,langchain]
# For CrewAI agents
pip install xenarch[agent,crewai]
# For publishers (FastAPI middleware)
pip install xenarch[fastapi]
Agent: pay for gated content
from xenarch.agent_client import check_gate, verify_payment
from xenarch.wallet import load_wallet_or_create
from xenarch.payment import execute_payment
# Auto-creates wallet on first run (saved to ~/.xenarch/wallet.json)
wallet = load_wallet_or_create()
# 1. Check if a URL is gated
gate = check_gate("https://example.com/premium-article")
if gate:
# 2. Pay via USDC on Base (max $1 per payment)
result = execute_payment(
wallet=wallet,
splitter_address=gate.splitter,
collector_address=gate.collector,
price_usd=gate.price_usd,
)
# 3. Verify payment, get access token
access = verify_payment(gate.verify_url, result.tx_hash)
print(f"Access token: {access['access_token']}")
LangChain integration
from xenarch.tools.langchain import CheckGateTool, PayTool, GetHistoryTool
tools = [CheckGateTool(), PayTool(), GetHistoryTool()]
# Use with any LangChain agent
from langchain.agents import initialize_agent
agent = initialize_agent(tools=tools, llm=llm, agent="zero-shot-react-description")
agent.run("Check if example.com has a paywall and pay for access if needed")
CrewAI integration
from xenarch.tools.crewai import check_gate, pay, get_history
from crewai import Agent
researcher = Agent(
role="Web Researcher",
tools=[check_gate, pay, get_history],
goal="Access premium content by paying micropayments when needed",
)
Publisher: gate your content
from fastapi import FastAPI
from xenarch import XenarchMiddleware
app = FastAPI()
app.add_middleware(
XenarchMiddleware,
site_token="your-site-token",
protected_paths=["/premium/*"],
)
Or use the decorator:
from xenarch import require_payment
@app.get("/premium/article")
@require_payment(price_usd="0.05")
async def premium_article():
return {"content": "This is premium content"}
Wallet management
On first use, load_wallet_or_create() generates a wallet automatically and saves it to ~/.xenarch/wallet.json. No signup, no API key.
To fund your wallet, send USDC and a small amount of ETH (for gas) to your wallet address on Base.
You can also configure via environment variables:
export XENARCH_PRIVATE_KEY=0x... # Wallet private key
export XENARCH_RPC_URL=... # Base RPC (default: https://mainnet.base.org)
export XENARCH_API_BASE=... # API base (default: https://api.xenarch.dev)
export XENARCH_NETWORK=base # base or base-sepolia
How it works
Xenarch is a non-custodial payment network. When an AI agent hits an x402-gated URL:
- The server returns HTTP 402 with payment instructions (price, wallet, contract)
- The agent pays USDC through a smart contract on Base (max $1 per payment)
- The agent verifies the payment and receives a time-limited access token
- The agent re-requests the content with the access token
No signup. No API keys. No custodial balances. Every payment is an on-chain USDC transfer the agent can verify.
Links
- Xenarch
- GitHub
- Examples (working integration examples)
- MCP Server (for Claude Desktop, Cursor, etc.)
- Smart Contract (verified, immutable, 0% fee)
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 xenarch-0.1.1.tar.gz.
File metadata
- Download URL: xenarch-0.1.1.tar.gz
- Upload date:
- Size: 11.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c89fa24034e3e81a94897f59cd2289aad32b67b60ef032ae7996a9cc667bd197
|
|
| MD5 |
6ba1cd710b1cfe860f1016e0823b7c40
|
|
| BLAKE2b-256 |
37a68f2806a60d329f99f33422b0c503dfd8cfc5e782fe9d71392115531dc760
|
File details
Details for the file xenarch-0.1.1-py3-none-any.whl.
File metadata
- Download URL: xenarch-0.1.1-py3-none-any.whl
- Upload date:
- Size: 16.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90d65e9261bd29364320852ce84ec70e6ad88ec9dd9792e5843457405704aaed
|
|
| MD5 |
c676f47f12eab2f56d9941e28f948a60
|
|
| BLAKE2b-256 |
8c49fb80673fc29ad1c4ea60ec172cca3f1d45082cf1b5ce6386a8f9eab84b2e
|