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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c2e68926c716b1a5a73af3dae36106812316da4223999c883995371d3ac4e3e
|
|
| MD5 |
ac0041143e6a60d1c1d71682276753c8
|
|
| BLAKE2b-256 |
a5af093eb9d2b8f1c709d32e809a6b454c5c139a846183822358b385c2004aea
|
Provenance
The following attestation bundles were made for ai_wallet-0.1.0.tar.gz:
Publisher:
publish-sdk.yml on VedavrathP/ai-wallet
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ai_wallet-0.1.0.tar.gz -
Subject digest:
7c2e68926c716b1a5a73af3dae36106812316da4223999c883995371d3ac4e3e - Sigstore transparency entry: 906535372
- Sigstore integration time:
-
Permalink:
VedavrathP/ai-wallet@f6efaf435e7d2b8ababa4b38e6d41e75c36de585 -
Branch / Tag:
refs/tags/sdk-v0.1.0 - Owner: https://github.com/VedavrathP
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdk.yml@f6efaf435e7d2b8ababa4b38e6d41e75c36de585 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4365b341c3c807c96c9178b2ab48ccce938f17e93c0116f623842ffd7e3e054
|
|
| MD5 |
8a0c8e14e2fbfd488458813538b9bd60
|
|
| BLAKE2b-256 |
72d9e09578426b72d7ab6160a301bcc090bff83db32f9f4182e33e7ad037ca1d
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ai_wallet-0.1.0-py3-none-any.whl -
Subject digest:
f4365b341c3c807c96c9178b2ab48ccce938f17e93c0116f623842ffd7e3e054 - Sigstore transparency entry: 906535374
- Sigstore integration time:
-
Permalink:
VedavrathP/ai-wallet@f6efaf435e7d2b8ababa4b38e6d41e75c36de585 -
Branch / Tag:
refs/tags/sdk-v0.1.0 - Owner: https://github.com/VedavrathP
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdk.yml@f6efaf435e7d2b8ababa4b38e6d41e75c36de585 -
Trigger Event:
push
-
Statement type: