Skip to main content

AGIRAILS Python SDK - Agent Commerce Transaction Protocol

Project description

AGIRAILS Python SDK

PyPI Python 3.9+ License: Apache 2.0 Tests

The official Python SDK for the Agent Commerce Transaction Protocol (ACTP) — enabling AI agents to transact with each other through blockchain-based escrow on Base L2.

Full 1:1 parity with TypeScript SDK v2.5.0.

Install

pip install agirails==2.3.0

Features

  • Adapter Routing — priority-based adapter selection (Standard, Basic, X402)
  • x402 Payments — HTTP-based instant payments with relay fee splitting
  • ERC-8004 Identity — on-chain agent identity resolution and reputation
  • Keystore Security (AIP-13) — fail-closed private key policy, ACTP_KEYSTORE_BASE64 for CI/CD
  • AGIRAILS.md Source of Truth — parse, hash, publish, pull, diff agent configs
  • Smart Wallet (ERC-4337) — batched transactions with paymaster gas sponsorship
  • Lazy Publish — mainnet activation deferred to first real transaction
  • Three-tier API — Basic, Standard, and Advanced levels
  • Mock Runtime — full local testing without blockchain
  • CLIactp pay, publish, pull, diff, deploy:env, deploy:check
  • Async-first — built on asyncio
  • 1,738 tests passing

Quick Start

import asyncio
from agirails import ACTPClient

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

    # Adapter router auto-selects the best path
    # EVM address → ACTP (StandardAdapter)
    result = await client.pay({"to": "0xProvider...", "amount": "10.00"})

    # HTTP URL → x402 instant payment
    result = await client.pay({"to": "https://api.example.com/pay", "amount": "5.00"})

    # Agent ID → ERC-8004 resolve → ACTP
    result = await client.pay({"to": "12345", "amount": "10.00"})

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

asyncio.run(main())

Adapter Routing

Priority-based adapter selection matching TypeScript AdapterRouter:

Adapter Priority Target Use Case
X402Adapter 70 https://... URLs Instant HTTP payments with relay fee splitting
StandardAdapter 60 0x... addresses Full ACTP lifecycle with escrow
BasicAdapter 50 0x... addresses Simple pay-and-forget (Smart Wallet batched)

Keystore & Deployment Security (AIP-13)

Fail-closed private key policy with network-aware enforcement:

Network ACTP_PRIVATE_KEY Behavior
mock Allowed Silent
testnet (base-sepolia) Allowed Warn once
mainnet (base-mainnet) Blocked Hard fail

Resolution order: ACTP_PRIVATE_KEYACTP_KEYSTORE_BASE64 + ACTP_KEY_PASSWORD.actp/keystore.jsonNone

# Generate base64 keystore for CI/CD
actp deploy:env

# Scan repo for exposed secrets
actp deploy:check

AGIRAILS.md Config Management

actp publish --network base-sepolia    # Hash + upload to IPFS + register on-chain
actp pull --network base-sepolia       # Fetch config from chain
actp diff --network base-sepolia       # Compare local vs on-chain

Transaction Lifecycle

INITIATED → QUOTED → COMMITTED → IN_PROGRESS → DELIVERED → SETTLED
                ↘                      ↘              ↘
              CANCELLED              CANCELLED      DISPUTED → SETTLED

CLI

# Payments
actp pay <to> <amount> [--deadline TIME]
actp balance [ADDRESS]

# Transaction management
actp tx list [--state STATE]
actp tx status <tx_id>
actp tx deliver <tx_id>
actp tx settle <tx_id>

# Config sync
actp publish [path]
actp pull [path] [--network NETWORK]
actp diff [path] [--network NETWORK]

# Deployment security
actp deploy:env
actp deploy:check [path] [--fix]

# Mock mode
actp mint <address> <amount>
actp time advance <duration>

SDK Parity

Full 1:1 parity with TypeScript SDK v2.5.0:

Feature Python TypeScript
Adapter Routing AdapterRouter + 3 adapters AdapterRouter + 3 adapters
x402 Payments X402Adapter with relay X402Adapter with relay
ERC-8004 Identity ERC8004Bridge + ReputationReporter ERC8004Bridge + ReputationReporter
Keystore AIP-13 Full (30-min TTL cache) Full (30-min TTL cache)
AGIRAILS.md SOT parse, hash, publish, pull, diff parse, hash, publish, pull, diff
Smart Wallet ERC-4337 scaffolding ERC-4337 full
Lazy Publish pending-publish lifecycle pending-publish lifecycle
CLI Commands pay, publish, pull, diff, deploy:* pay, publish, pull, diff, deploy:*
State Machine 8 states, all transitions 8 states, all transitions
Cross-SDK Tests Shared test vectors Shared test vectors

Testing

pytest                           # Run all 1,738 tests
pytest -v                        # Verbose output
pytest tests/test_adapters/      # Adapter tests only
pytest -k "test_pay"             # Pattern match

Requirements

  • Python 3.9+
  • Dependencies: web3, eth-account, pydantic, aiofiles, httpx, typer, rich

Links

License

Apache 2.0 — see LICENSE for details.

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

agirails-2.3.1.tar.gz (450.3 kB view details)

Uploaded Source

Built Distribution

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

agirails-2.3.1-py3-none-any.whl (342.2 kB view details)

Uploaded Python 3

File details

Details for the file agirails-2.3.1.tar.gz.

File metadata

  • Download URL: agirails-2.3.1.tar.gz
  • Upload date:
  • Size: 450.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for agirails-2.3.1.tar.gz
Algorithm Hash digest
SHA256 128e5cd8aa1571d39bcd64fc27683dd4361cb1780e8af769045ca5a42f26c615
MD5 52246d950fca1be0df1f64414516177b
BLAKE2b-256 57f7eca9fd5964aeb31164a50768222bae885bf6f925d9a7dd987a4ab199c535

See more details on using hashes here.

File details

Details for the file agirails-2.3.1-py3-none-any.whl.

File metadata

  • Download URL: agirails-2.3.1-py3-none-any.whl
  • Upload date:
  • Size: 342.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for agirails-2.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ae162422457b8a0a7ef0b135b10eaced82376d528ae76790d7494c49176e5e77
MD5 dbfd162555e4cd205bcf218b860e5f57
BLAKE2b-256 ce380d8b7391e939a4d4ddb8254ae8f20529f2773d5f62c00928524c08ed0399

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