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 USDC 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

The Modexia SDK handles complex blockchain transactions and HTTP retries under the hood, presenting your agents with a hyper-clean interface.

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

    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: Broadcasts USDC Transfer
    Chain-->>API: Transaction Confirmed
    API-->>SDK: Status: Completed
    SDK-->>Agent: Returns Full Receipt! 🎉

✨ 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} USDC")
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 USDC 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. PaymentReceipt
get_history(limit=5) Fetch the recent transaction history for Agent memory. TransactionHistoryResponse
smart_fetch(url, ...) Auto-negotiates 402 HTTP paywalls automatically. Response

🛑 Exception Handling

The SDK provides robust error mapping to help your agent gracefully recover from failures:

graph TD;
    Exception-->ModexiaError;
    ModexiaError-->ModexiaAuthError["ModexiaAuthError: Key/Auth Issues"];
    ModexiaError-->ModexiaPaymentError["ModexiaPaymentError: Insufficient Funds / API Denials"];
    ModexiaError-->ModexiaNetworkError["ModexiaNetworkError: Connection Drops / Timeouts"];

🤝 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.4.0.tar.gz (15.3 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.4.0-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: modexiaagentpay-0.4.0.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for modexiaagentpay-0.4.0.tar.gz
Algorithm Hash digest
SHA256 73b72318f467f766b8893058d8ad8401f0ba20ec4d41bfad73506ca3a06571ba
MD5 5ee7d04c6d31137d6f56fae243785d76
BLAKE2b-256 3523c5e381ecac965f8414a38ca8ce0da3bfe19c651632eb5a02032c3abb7e09

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for modexiaagentpay-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ab24578febc1308b396cd3423d814e5ec231c9f8eca64fb0fabba375e359ba51
MD5 9b6ebba438e896b9b57ef1b82a9dc1b5
BLAKE2b-256 071cea601968c70aaee64986b4d4fbfcc85df5d2a8c50b9d0c2aba0ec79677b6

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