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.
Metadata
Release files for openlibx402-core 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| openlibx402_core-0.1.1.tar.gz | 9.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| openlibx402_core-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.7 kB
Release files / openlibx402_core-0.1.1.tar.gz
| Download URL | openlibx402_core-0.1.1.tar.gz |
|---|---|
| Size | 9.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
72aea316f181aa1ca7ecb59350faee7342bddda3e5a3bd84f319631cf1d22622
|
|
BLAKE2b-256 checksum How to use checksums |
311dc665d9e0f03803b440014bfe12e3e4284f3218b94e8cc0e9343a304d0c60
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.23
|
Release files / openlibx402_core-0.1.1-py3-none-any.whl
| Download URL | openlibx402_core-0.1.1-py3-none-any.whl |
|---|---|
| Size | 11.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
205b5161841d63e762bd2937efba542d942c2dfff6624d02d4cd45fdc279b739
|
|
BLAKE2b-256 checksum How to use checksums |
b6c6f7f55022a751cc60efe174b4282373ab5ee081a75701b2dcf35f4ba854da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.23
|