Skip to main content

Modexia AgentPay — Python SDK for agent wallets & payments (USDC)

Project description

Modexia Logo

🚀 Modexia Python SDK

The ultimate Python client for AI Agents to seamlessly interact with Modexia's AgentPay API.

PyPI version Python versions License: MIT Code style: black


Welcome to the Modexia Python SDK (modexiaagentpay). Built from the ground up to give your AI agents and Python applications frictionless access to Modexia's wallet and payment infrastructure. Enable your AI to hold, manage, and transfer value with just a few lines of code!


🌟 Getting Started: Your API Key

Before writing your first integration, you will need a Modexia developer account and an API key.

  1. Visit modexia.software
  2. Create or log into your developer account.
  3. Navigate to your dashboard and generate your API Key.

For deep dives, architecture, and advanced agentic payment flows, dive into our Full Documentation.


🏗 System Architecture & Flow

Currently, the SDK uses an API Key-based Custodial Model for maximum developer velocity.

sequenceDiagram
    participant Agent as 🤖 AI Agent (Your App)
    participant SDK as 📦 Modexia Python SDK
    participant API as 🌐 Modexia AgentPay API
    participant Chain as ⛓️ Settlement Layer

    Agent->>SDK: transfer(recipient, amount, wait=True)
    SDK->>API: POST /v1/payments (with API Key)
    API-->>SDK: Transaction Pending (TxHash)
    
    rect rgb(40, 44, 52)
    Note over SDK, API: SDK Automatically Polls API
    loop Polling Status
        SDK->>API: GET /v1/payments/{id}/status
        API-->>SDK: Status: Pending...
    end
    end
    
    API->>Chain: Finalizes Settlement On-Chain
    Chain-->>API: Transaction Confirmed
    API-->>SDK: Status: Completed
    SDK-->>Agent: Returns Full Receipt! 🎉

Note on Future Evolution: We are actively developing a transition to Fully Trustless State Channels (EIP-712). In future versions, agents will manage their own private keys and sign off-chain cryptographic receipts natively, removing Modexia as a trusted middleman. See our Architecture Docs for details.


✨ Top-Level Features

  • Built for AI Agents: Designed specifically for programmatic access to agent wallets and payments without complex cryptography. Includes Agent Memory via transaction history.
  • Intent-Based Idempotency: Automatically deduplicates identical payment requests from your agents using intent hashing.
  • Async & "Swarm" Support: High-concurrency operations powered by blazing fast implementations in both synchronous and asyncio models.
  • Fully Typed: Returns robust Python dataclasses for exceptional developer experience and editor autocompletion.
  • Reliable Networking: Built-in retry and exponential backoff mechanisms to gracefully handle transient network errors.

📦 Installation

Install the production-ready package directly from PyPI:

pip install modexiaagentpay

For local development and contribution:

git clone https://github.com/Modaniel/SDKs.git
cd SDKs
pip install -e packages/SDKs/pythonSdk

🚀 Quick Start Guide

Initialize the client with your Modexia API key and empower your application to make real-world transactions instantly.

from modexia import ModexiaClient

# 1. Initialize the client using the API key you generated at modexia.software
# (It also respects the MODEXIA_BASE_URL environment variable!)
client = ModexiaClient(api_key="mx_test_your_api_key_here")

# 2. Check your agent's wallet balance & history
try:
    balance = client.retrieve_balance() # Or client.get_balance()
    history = client.get_history(limit=5)
    print(f"💰 Current wallet balance: {balance} credits")
except Exception as e:
    print(f"Failed to fetch balance: {e}")

# 3. Execute a secure transfer!
# Setting wait=True ensures the SDK polls until the blockchain confirms the transaction.
receipt = client.transfer(
    recipient="0xabc123456789def0123456789abc0123456789def", 
    amount=5.0, 
    wait=True
)

# Strongly-typed dataclasses mean your editor knows `receipt.txId` exists!
if receipt.success:
    print(f"✅ Transfer successful! TX ID: {receipt.txId}")

Async Usage (Swarm Mode)

For high-concurrency loops or AutoGPT-style agent networks:

import asyncio
from modexia import AsyncModexiaClient

async def main():
    client = AsyncModexiaClient(api_key="mx_test_your_api_key_here")
    receipt = await client.transfer("0xabc...", 5.0)
    print(f"Status: {receipt.status}")
    await client.aclose()

asyncio.run(main())

🛠 API Reference

ModexiaClient & AsyncModexiaClient

The core classes for all network operations.

ModexiaClient(
    api_key: str, 
    timeout: int = 15, 
    base_url: Optional[str] = None, 
    validate: bool = True
)

Core Methods

Method Description Returns
retrieve_balance() / get_balance() Fetches the current available balance of your agent's wallet. str
transfer(recipient, amount, idempotency_key=None, wait=True) Send funds to a destination. Uses intent-hashing to prevent duplicate charges. Raises TimeoutError if wait=True exceeds 30s. PaymentReceipt
get_history(limit=5) Fetch the recent transaction history for Agent memory. TransactionHistoryResponse
open_channel(...), consume_channel(...), settle_channel(...) Utilize High-Frequency Vaults to process thousands of zero-fee micropayments per second off-chain. Varied
smart_fetch(url, ...) Auto-negotiates 402 HTTP paywalls automatically. Explicitly raises network/auth errors but catches payment errors. Response

🛑 Exception Handling

The SDK provides robust error mapping to help your agent gracefully recover from failures. You can import these directly from the modexia package:

from modexia import ModexiaClient, ModexiaAuthError, ModexiaPaymentError, ModexiaNetworkError
graph TD;
    Exception-->TimeoutError["TimeoutError: wait=True Polling exceeded 30s"];
    Exception-->ModexiaError;
    ModexiaError-->ModexiaAuthError["ModexiaAuthError: Key/Auth Issues"];
    ModexiaError-->ModexiaPaymentError["ModexiaPaymentError: Insufficient Funds / API Responses with success=False"];
    ModexiaError-->ModexiaNetworkError["ModexiaNetworkError: Connection Drops / Invalid JSON payloads"];

🤝 Contributing to Open Source

We actively welcome community contributions to make this SDK even better.

  1. Fork & Branch: Open a Pull Request targeting the develop branch.
  2. Backward Compatibility: Please keep API contracts stable. ModexiaClient, transfer(), and retrieve_balance() are canonical.
  3. Testing: Make sure tests pass locally before submitting.
# Run tests from the repository root
pytest -q packages/SDKs/pythonSdk

📄 License & Support

modexiaagentpay is totally open-source and governed by the MIT License.

Need help scaling your agent swarm? Hit rate limits? Reach out to our engineering team or explore the docs at modexia.software.

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

modexiaagentpay-0.6.0.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

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

modexiaagentpay-0.6.0-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file modexiaagentpay-0.6.0.tar.gz.

File metadata

  • Download URL: modexiaagentpay-0.6.0.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for modexiaagentpay-0.6.0.tar.gz
Algorithm Hash digest
SHA256 099270d8d88dd7cb812963f2fc7220d30b1bfdf03b2652b70f64b21900a32afc
MD5 dbf4563f46a3de3c4356878e7bc614ee
BLAKE2b-256 0825d1b65ed06c75f56f2bfda68b537a0dc206c8a9eb767c436e781bf8809ec6

See more details on using hashes here.

File details

Details for the file modexiaagentpay-0.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for modexiaagentpay-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 65aeaa92a0a1f22bd066c7d936b70f8d3c1956455c69fcec6518f06304d97a54
MD5 8c6dcea40b5423efbf760a0bb7db5d69
BLAKE2b-256 a431f0514d94632b2088ebbd13b6e05016e0b6be15e52048a0acb8052719314f

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