Skip to main content

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.

Metadata

Release files for fly402core 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fly402core 0.1.1
File Size Uploaded
fly402core-0.1.1.tar.gz 9.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fly402core 0.1.1
File Interpreter ABI Platform
fly402core-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 21.3 kB

Release files / fly402core-0.1.1.tar.gz

Download URL fly402core-0.1.1.tar.gz
Size 9.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ca85fa1953ad5b371798c50458e294ebec8670e147b3b15a81e38b59d263ec47
BLAKE2b-256 checksum
How to use checksums
1447687322a06b853146fb68e700351b4e15ae40ec9a005a00a2aae9523f8069
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / fly402core-0.1.1-py3-none-any.whl

Download URL fly402core-0.1.1-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d65a74ef2f592b26dda40d6077e68aba8321624dd5cb421999939ba4cd81ceb2
BLAKE2b-256 checksum
How to use checksums
f15959b31b2162b9f1719de354c7e29906b49202dd8344f2b30d44bb127251c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page