Skip to main content

agirails v2.0 for Python: Full Feature Parity with TypeScript SDK

ยท 3 min read
AGIRAILS Core Team

The AGIRAILS Python SDK v2.0 is now live on PyPI with full feature parity to the TypeScript SDK, including mock mode, three API layers, and comprehensive error handling.

Installationโ€‹

pip install agirails

PyPI: agirails GitHub: agirails/sdk-python


What's New in v2.0โ€‹

Three API Layersโ€‹

The SDK offers three levels of abstraction to match your needs:

LayerUse CaseComplexity
BasicQuick integrations, demosMinimal
StandardProduction applicationsBalanced
RuntimeCustom implementationsFull control
from agirails import ACTPClient

client = await ACTPClient.create(
mode="testnet",
requester_address="0x...",
private_key="0x..."
)

# Basic: One-liner payment
result = await client.basic.pay({
"to": "0x...",
"amount": 10.00,
"deadline": "+1h"
})

# Standard: Full lifecycle control
tx_id = await client.standard.create_transaction({
"provider": "0x...",
"amount": 10.00,
"deadline": "+1h",
"dispute_window": 3600
})
await client.standard.link_escrow(tx_id)

Mock Modeโ€‹

Develop and test without blockchain access:

client = await ACTPClient.create(
mode="mock",
requester_address="0x1234..." # No private key needed!
)

# Full ACTP flow works identically
result = await client.basic.pay({
"to": "0x5678...",
"amount": 5.00
})

print(result.tx_id) # "0x..."
print(result.state) # "COMMITTED"
print(result.amount) # "5.00 USDC"

Mock mode features:

  • No gas fees or blockchain connection
  • Instant transactions
  • Persistent state (survives restarts)
  • Perfect for CI/CD pipelines
  • Test USDC minting

Comprehensive Error Handlingโ€‹

30+ typed exceptions with structured details:

from agirails import (
ACTPError,
InsufficientBalanceError,
InvalidStateTransitionError,
NetworkError,
TransactionNotFoundError
)

try:
await client.basic.pay({"to": "0x...", "amount": 1000})
except InsufficientBalanceError as e:
print(f"Need more USDC!")
print(f"Required: {e.details['required']}")
print(f"Available: {e.details['available']}")
except InvalidStateTransitionError as e:
print(f"Invalid transition: {e.details['from']} -> {e.details['to']}")
print(f"Valid transitions: {e.details['valid_transitions']}")
except NetworkError as e:
# Implement retry logic
pass
except ACTPError as e:
print(f"ACTP Error [{e.code}]: {e.message}")

Error categories:

  • Transaction: InsufficientBalanceError, TransactionNotFoundError, DeadlineExpiredError
  • State: InvalidStateTransitionError, DisputeWindowActiveError
  • Validation: InvalidAddressError, InvalidAmountError
  • Network: NetworkError, TransactionRevertedError
  • Storage: StorageError, UploadTimeoutError, ContentNotFoundError
  • Agent/Job: NoProviderFoundError, ProviderRejectedError

Fully Asyncโ€‹

Native Python async/await throughout:

import asyncio
from agirails import ACTPClient

async def main():
client = await ACTPClient.create(mode="mock", requester_address="0x...")

# Concurrent operations
results = await asyncio.gather(
client.basic.pay({"to": "0xA...", "amount": 10}),
client.basic.pay({"to": "0xB...", "amount": 20}),
client.basic.pay({"to": "0xC...", "amount": 30}),
)

for r in results:
print(f"Tx {r.tx_id}: {r.state}")

asyncio.run(main())

Dataclass Resultsโ€‹

All results are typed dataclasses with IDE autocomplete:

from agirails import BasicPayResult, CheckStatusResult

result: BasicPayResult = await client.basic.pay({...})

# IDE autocomplete works
result.tx_id # str
result.state # str
result.amount # str
result.deadline # str (ISO 8601)

Quick Startโ€‹

1. Installโ€‹

pip install agirails

2. Create Clientโ€‹

from agirails import ACTPClient

# Mock mode for development
client = await ACTPClient.create(
mode="mock",
requester_address="0xYourAddress..."
)

# Testnet for integration testing
client = await ACTPClient.create(
mode="testnet",
requester_address="0xYourAddress...",
private_key="0xYourPrivateKey..."
)

3. Make a Paymentโ€‹

result = await client.basic.pay({
"to": "0xProviderAddress...",
"amount": 25.00,
"deadline": "+24h"
})

print(f"Transaction: {result.tx_id}")
print(f"State: {result.state}")

4. Check Statusโ€‹

status = await client.basic.check_status(result.tx_id)

print(f"Can accept: {status.can_accept}")
print(f"Can complete: {status.can_complete}")
print(f"Can dispute: {status.can_dispute}")

Feature Parity with TypeScriptโ€‹

FeatureTypeScriptPython
Basic APIclient.basic.pay()client.basic.pay()
Standard APIclient.standard.*client.standard.*
Mock Modemode: 'mock'mode="mock"
Error Hierarchy30+ typed errors30+ typed errors
Async SupportPromisesasync/await
State Machine8 states8 states
Test USDC Mintingclient.mintTokens()client.mint_tokens()

Network Supportโ€‹

NetworkChain IDStatus
Base Sepolia84532Active (Testnet)
Base Mainnet8453Not Deployed

What's Nextโ€‹

  • Claude Code Plugin: AI-assisted AGIRAILS development
  • LangChain Integration: Native tools for AI agents
  • Documentation: Comprehensive Python guides

Resourcesโ€‹


Feedbackโ€‹

Found an issue? Open a GitHub issue or reach out on Discord.