Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openlibx402_core-0.1.0.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

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

openlibx402_core-0.1.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file openlibx402_core-0.1.0.tar.gz.

File metadata

  • Download URL: openlibx402_core-0.1.0.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for openlibx402_core-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bb0454e8324694221d23ae5bd8fd99f083503db80f5ce573f6971500bbf8ea7f
MD5 6958394b66e5447ebbe0c6dd58816993
BLAKE2b-256 68c9e27097ce89cc83e61171f336753a14446d2d751f3f2ceb3844a1483553d2

See more details on using hashes here.

File details

Details for the file openlibx402_core-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for openlibx402_core-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 af6849c47120700df5c923b9f98bd49b14a4afd9af8ea1c57eb140f0b294a942
MD5 74ba36f2364f10ac4b0848429385ca98
BLAKE2b-256 285ac7a935e686640aee26bc4326f1182fd26e9a1247f8616accdf66c213b311

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