Skip to main content

Core implementation of the 402fly payment protocol for autonomous AI agent payments

Project description

402fly-core

Core Python implementation of the X402 payment protocol for autonomous AI agent payments.

Overview

The 402fly-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 402fly-core

Core Components

Payment Models

from 402fly_core import PaymentRequest, PaymentAuthorization

# PaymentRequest: Represents a payment requirement
# PaymentAuthorization: Represents completed payment details

Payment Processor

from 402fly_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 402fly_core import (
    Fly402Error,
    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:

  • 402fly-client: HTTP client with automatic payment handling
  • 402fly-fastapi: FastAPI middleware for payment-required endpoints
  • 402fly-langchain: LangChain agent integration
  • 402fly-langgraph: LangGraph workflow integration

For most use cases, you'll want to use one of these higher-level packages rather than using 402fly-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

fly402core-0.1.1.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

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

fly402core-0.1.1-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file fly402core-0.1.1.tar.gz.

File metadata

  • Download URL: fly402core-0.1.1.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for fly402core-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ca85fa1953ad5b371798c50458e294ebec8670e147b3b15a81e38b59d263ec47
MD5 da62fd3a8baf174bdfeb21c18a461b30
BLAKE2b-256 1447687322a06b853146fb68e700351b4e15ae40ec9a005a00a2aae9523f8069

See more details on using hashes here.

File details

Details for the file fly402core-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: fly402core-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for fly402core-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d65a74ef2f592b26dda40d6077e68aba8321624dd5cb421999939ba4cd81ceb2
MD5 c4d0e8e24c8e499a031d31ffda26f146
BLAKE2b-256 f15959b31b2162b9f1719de354c7e29906b49202dd8344f2b30d44bb127251c9

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