Metadata-Version: 2.4
Name: mixrpay
Version: 0.7.0
Summary: MixrPay Agent SDK - Enable AI agents to make x402 payments with session keys
Author-email: MixrPay <support@mixrpay.com>
License: MIT
Project-URL: Homepage, https://www.mixrpay.com
Project-URL: Documentation, https://docs.mixrpay.com/sdk/python
Project-URL: Repository, https://github.com/mixrpay/mixrpay-python
Project-URL: Changelog, https://github.com/mixrpay/mixrpay-python/blob/main/CHANGELOG.md
Keywords: payments,ai-agents,x402,cryptocurrency,usdc,blockchain,web3,langchain,crewai
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Office/Business :: Financial
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: httpx>=0.24.0
Requires-Dist: eth-account>=0.9.0
Requires-Dist: pydantic>=2.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0; extra == "dev"
Requires-Dist: black>=23.0; extra == "dev"
Requires-Dist: mypy>=1.0; extra == "dev"
Requires-Dist: ruff>=0.1.0; extra == "dev"
Provides-Extra: langchain
Requires-Dist: langchain>=0.1.0; extra == "langchain"
Requires-Dist: langchain-core>=0.1.0; extra == "langchain"
Provides-Extra: crewai
Requires-Dist: crewai>=0.1.0; extra == "crewai"
Provides-Extra: all
Requires-Dist: mixrpay[crewai,dev,langchain]; extra == "all"

# MixrPay Agent SDK for Python

Enable AI agents to make autonomous payments.

## Installation

```bash
pip install mixrpay
```

## Setup

```bash
export MIXRPAY_SESSION_KEY=sk_live_...
```

Session keys are created by wallet owners at [mixrpay.com/wallet/sessions](https://www.mixrpay.com/wallet/sessions).

## Basic Usage

```python
from mixrpay import AgentWallet

wallet = AgentWallet(session_key="sk_live_...")

# Call a paid API
response = await wallet.call_merchant_api(
    url="https://api.merchant.com/generate",
    merchant_public_key="pk_live_...",
    price_usd=0.05,
    json={"prompt": "Hello world"}
)

data = response.json()
```

## Pre-Flight Checks

```python
# Check if wallet can afford an amount before calling
check = await wallet.can_afford(0.50)
if check.can_afford:
    response = await wallet.call_merchant_api(...)
else:
    print(f"Insufficient funds. Have: ${check.current_balance}")

# Run diagnostics for debugging
diag = await wallet.run_diagnostics()
print(f"Balance: ${diag.balance_usd}")
print(f"Latency: {diag.latency_ms}ms")
print(f"Recommendations: {diag.recommendations}")
```

## Error Handling

```python
from mixrpay import (
    AgentWallet,
    MixrPayError,
    InsufficientBalanceError,
    SessionLimitExceededError,
    PaymentFailedError,
)

try:
    response = await wallet.call_merchant_api(...)
except InsufficientBalanceError as e:
    print(f"Low balance. Top up: {e.top_up_url}")
except SessionLimitExceededError:
    print("Session limit exceeded")
except MixrPayError as e:
    # Check if error is retryable
    if e.is_retryable():
        delay = e.retry_after_ms / 1000 if e.retry_after_ms else 1
        await asyncio.sleep(delay)
        return await retry()
    raise
```

## Spending Controls

```python
wallet = AgentWallet(
    session_key="sk_live_...",
    max_payment_usd=1.0,  # Client-side safety limit
    on_payment=lambda p: print(f"Paid ${p.amount_usd}"),
)

# Check balance
balance = await wallet.get_balance()
stats = wallet.get_spending_stats()
```

## Context Manager

```python
async with AsyncAgentWallet(session_key="sk_live_...") as wallet:
    response = await wallet.call_merchant_api(...)
```

## LangChain Integration

```python
from langchain.tools import BaseTool
from mixrpay import AgentWallet

class PaidSearchTool(BaseTool):
    name = "paid_search"
    description = "Premium search ($0.05/query)"
    
    def __init__(self, session_key: str):
        super().__init__()
        self.wallet = AgentWallet(session_key=session_key)
    
    async def _arun(self, query: str) -> str:
        response = await self.wallet.call_merchant_api(
            url="https://api.search.com/query",
            merchant_public_key="pk_live_...",
            price_usd=0.05,
            json={"query": query}
        )
        return response.json()["results"]
```

## What's New in v0.6.0

- `can_afford(amount_usd)` - Pre-flight balance check
- `is_retryable()` on all errors - Determine if operation should be retried
- `retry_after_ms` on errors - Suggested retry delay
- Enhanced `run_diagnostics()` - Session limits, latency, recommendations
- `request_id` and `correlation_id` in payment events

## Documentation

Full documentation at [mixrpay.com/docs](https://www.mixrpay.com/docs)

## License

MIT
