Skip to main content

Python SDK for AI Wallet API - secure financial operations for AI agents

Project description

Agent Wallet SDK

Python SDK for the Agent Wallet API - secure financial operations for AI agents.

Installation

pip install agent-wallet

Quick Start

from agent_wallet import WalletClient

# Initialize the client
client = WalletClient(
    api_key="aw_your_api_key_here",
    base_url="http://localhost:8000"
)

# Check your balance
balance = client.balance()
print(f"Available: {balance.available} {balance.currency}")
print(f"Held: {balance.held} {balance.currency}")
print(f"Total: {balance.total} {balance.currency}")

Features

  • Type-safe: Full type hints and Pydantic models for all responses
  • Idempotent: Built-in support for idempotency keys to prevent duplicate transactions
  • Retry logic: Automatic retries with exponential backoff for network errors
  • Clean exceptions: Specific exception classes for different error types

Usage Examples

Transfer Funds

transfer = client.transfer(
    to_handle="@merchant",
    amount="25.00",
    currency="USD",
    idempotency_key="unique-transfer-key-123",
    reference_id="order_456",
    metadata={"note": "Payment for order"}
)
print(f"Transfer ID: {transfer.id}")

Create and Capture a Hold

# Create a hold (reservation)
hold = client.hold(
    amount="100.00",
    currency="USD",
    idempotency_key="hold-key-789",
    expires_in_seconds=3600  # 1 hour
)
print(f"Hold ID: {hold.id}")

# Capture the hold (partial or full)
capture = client.capture(
    hold_id=hold.id,
    to_handle="@merchant",
    amount="75.00",  # Capture only $75 of the $100 hold
    idempotency_key="capture-key-101"
)

# Release the remaining hold
release = client.release(
    hold_id=hold.id,
    idempotency_key="release-key-102"
)

Payment Intents (Merchant Flow)

# Merchant creates a payment intent
intent = client.create_payment_intent(
    amount="50.00",
    currency="USD",
    expires_in_seconds=900,  # 15 minutes
    metadata={"order_id": "order_789"}
)
print(f"Payment Intent ID: {intent.id}")

# Customer pays the intent
result = client.pay_payment_intent(
    intent_id=intent.id,
    idempotency_key="pay-intent-key-103"
)

Request a Refund

refund = client.refund(
    capture_id="cap_abc123",
    amount="25.00",  # Partial refund
    idempotency_key="refund-key-104"
)
print(f"Refund ID: {refund.id}")

Exception Handling

from agent_wallet import WalletClient
from agent_wallet.exceptions import (
    InsufficientFunds,
    ForbiddenScope,
    LimitExceeded,
    RecipientNotFound,
    CurrencyMismatch,
    ConflictIdempotency,
    WalletAPIError,
)

client = WalletClient(api_key="...", base_url="...")

try:
    transfer = client.transfer(
        to_handle="@merchant",
        amount="1000000.00",
        currency="USD",
        idempotency_key="key-123"
    )
except InsufficientFunds as e:
    print(f"Not enough funds: {e.message}")
except LimitExceeded as e:
    print(f"Transaction limit exceeded: {e.message}")
except RecipientNotFound as e:
    print(f"Recipient not found: {e.message}")
except ForbiddenScope as e:
    print(f"Permission denied: {e.message}")
except CurrencyMismatch as e:
    print(f"Currency mismatch: {e.message}")
except ConflictIdempotency as e:
    print(f"Idempotency conflict: {e.message}")
except WalletAPIError as e:
    print(f"API error: {e.status_code} - {e.message}")

Configuration

Custom Timeout

client = WalletClient(
    api_key="...",
    base_url="...",
    timeout=30.0  # 30 seconds
)

Disable Retries

client = WalletClient(
    api_key="...",
    base_url="...",
    max_retries=0
)

API Reference

WalletClient Methods

Method Description
balance() Get current wallet balance
transactions(cursor, limit) List transactions with pagination
transfer(...) Transfer funds to another wallet
hold(...) Create a hold/reservation
capture(...) Capture a hold
release(...) Release a hold
create_payment_intent(...) Create a payment intent
pay_payment_intent(...) Pay a payment intent
refund(...) Request a refund

License

MIT License

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

ai_wallet-0.1.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

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

ai_wallet-0.1.0-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file ai_wallet-0.1.0.tar.gz.

File metadata

  • Download URL: ai_wallet-0.1.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ai_wallet-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7c2e68926c716b1a5a73af3dae36106812316da4223999c883995371d3ac4e3e
MD5 ac0041143e6a60d1c1d71682276753c8
BLAKE2b-256 a5af093eb9d2b8f1c709d32e809a6b454c5c139a846183822358b385c2004aea

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai_wallet-0.1.0.tar.gz:

Publisher: publish-sdk.yml on VedavrathP/ai-wallet

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ai_wallet-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ai_wallet-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ai_wallet-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f4365b341c3c807c96c9178b2ab48ccce938f17e93c0116f623842ffd7e3e054
MD5 8a0c8e14e2fbfd488458813538b9bd60
BLAKE2b-256 72d9e09578426b72d7ab6160a301bcc090bff83db32f9f4182e33e7ad037ca1d

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai_wallet-0.1.0-py3-none-any.whl:

Publisher: publish-sdk.yml on VedavrathP/ai-wallet

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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