Core implementation of X402 payment protocol for autonomous AI agent payments
Project description
openlibx402-core
Core Python implementation of the X402 payment protocol for autonomous AI agent payments.
Overview
The openlibx402-core package provides the fundamental building blocks for implementing the X402 payment protocol. This package handles payment processing on the Solana blockchain, including transaction creation, verification, and error handling.
Features
- Payment request and authorization models
- Solana blockchain payment processing
- Comprehensive error handling for payment workflows
- Protocol primitives and data structures
- Transaction verification and validation
Installation
pip install openlibx402-core
Core Components
Payment Models
from openlibx402_core import PaymentRequest, PaymentAuthorization
# PaymentRequest: Represents a payment requirement
# PaymentAuthorization: Represents completed payment details
Payment Processor
from openlibx402_core import SolanaPaymentProcessor
from solders.keypair import Keypair
# Initialize payment processor
keypair = Keypair() # Your wallet keypair
processor = SolanaPaymentProcessor(
wallet_keypair=keypair,
rpc_url="https://api.devnet.solana.com"
)
# Process payments (typically used by higher-level packages)
Error Handling
from openlibx402_core import (
X402Error,
PaymentRequiredError,
PaymentExpiredError,
InsufficientFundsError,
PaymentVerificationError,
TransactionBroadcastError,
InvalidPaymentRequestError,
)
try:
# Payment operations
pass
except PaymentRequiredError as e:
print(f"Payment required: {e}")
except InsufficientFundsError as e:
print(f"Insufficient funds: {e}")
Usage
This package is typically used as a dependency by higher-level packages like:
- openlibx402-client: HTTP client with automatic payment handling
- openlibx402-fastapi: FastAPI middleware for payment-required endpoints
- openlibx402-langchain: LangChain agent integration
- openlibx402-langgraph: LangGraph workflow integration
For most use cases, you'll want to use one of these higher-level packages rather than using openlibx402-core directly.
Documentation
For complete API reference and guides, see:
Testing
pytest tests/
License
MIT License - See LICENSE file for details.
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 openlibx402_core-0.1.1.tar.gz.
File metadata
- Download URL: openlibx402_core-0.1.1.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72aea316f181aa1ca7ecb59350faee7342bddda3e5a3bd84f319631cf1d22622
|
|
| MD5 |
5936a6522baf0a3b534bd5563aa13496
|
|
| BLAKE2b-256 |
311dc665d9e0f03803b440014bfe12e3e4284f3218b94e8cc0e9343a304d0c60
|
File details
Details for the file openlibx402_core-0.1.1-py3-none-any.whl.
File metadata
- Download URL: openlibx402_core-0.1.1-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
205b5161841d63e762bd2937efba542d942c2dfff6624d02d4cd45fdc279b739
|
|
| MD5 |
e64f472702d3d6ea0ddddc1faffa1f95
|
|
| BLAKE2b-256 |
b6c6f7f55022a751cc60efe174b4282373ab5ee081a75701b2dcf35f4ba854da
|