Python SDK

Professional Python SDK for ifenpay Agent. One pip install away from autonomous AI payments.

⚡ 1-Minute Setup

Install & Start in Seconds

Production-ready Python SDK with CLI tool included!

Requirement: Docker Desktop

Install from docker.com

1

Install SDK

pip install ifenpay-agent-sdk

One command installs SDK + CLI tool

2

Setup Agent

python -m ifenpay_agent_sdk.cli setup

Installs & starts agent automatically

✅ Done! Start Coding:

from ifenpay_agent_sdk import Agent, AgentError

agent = Agent("http://localhost:7860")

# Check balance with auto-receive
balance = agent.check_balance(auto_receive_pending_blocks=True)
print(f"Balance: {balance.balance} NANO")

# Send payment
agent.pay("nano_address", "0.001")
⚙️

Agent Configuration (.env)

The agent uses a .env file for configuration. Located at:

~/.ifenpay/agent/.env

This file is created automatically from .env.example during setup.

Key Settings:
AGENT_MODE - Set to AUTONOMOUS or STRICT
AI_WALLET_PASSWORD - Auto-generated secure password for wallet encryption
NANO_WORK_MODE - CPU or GPU for proof-of-work

💡 Tip: Edit the .env file with your preferred text editor before starting the agent:

nano ~/.ifenpay/agent/.env

Professional Python SDK

Type-safe, well-documented, production-ready

🎯

Type-Safe

Full dataclass support with type hints. IDE autocomplete works perfectly.

result: PaymentResult
result.amount  # str
result.recipient  # str

Easy Error Handling

Custom AgentError exception with error codes and messages.

try:
    agent.pay("..")
except AgentError as e:
    print(e.error_code)
🛠️

CLI Tool Included

Manage agent with simple commands. No manual Docker setup.

python -m ifenpay_agent_sdk.cli setup
python -m ifenpay_agent_sdk.cli status
python -m ifenpay_agent_sdk.cli logs
ai_payment_flow.py
from ifenpay_agent_sdk import Agent, AgentError

# Initialize agent (strict mode for AI-to-AI payments)
agent = Agent(agent_url="http://localhost:7860")

try:
    # 1. Check balance (auto-receives pending blocks)
    balance = agent.check_balance(auto_receive_pending_blocks=True)
    print(f"Balance: {balance.balance} NANO")
    print(f"Pending: {balance.pending} NANO")
    print(f"Address: {balance.address}")
    
    # 2. Create payment request (for receiving payments)
    payment_req = agent.request_payment(amount="0.001")
    print(f"\nTransaction ID: {payment_req.transaction_id}")
    print(f"Pay to: {payment_req.receive_address}")
    print(f"Pay EXACTLY: {payment_req.amount} NANO (includes offset)")
    
    # 3. Send payment
    result = agent.pay(
        address="nano_1ebhjnii43rx9fs41njqam86q9uwgcfbap18beoyrpheekw7wniu9e3g6rb3",
        amount="0.001"
    )
    print(f"\n✅ Payment sent!")
    print(f"Hash: {result.hash}")
    
    # 4. Check payment status
    status = agent.check_payment_status(payment_req.transaction_id)
    print(f"\nStatus: {status.get('response')}")
    print(f"Message: {status.get('message')}")
    
    # 5. Get credits info
    credits = agent.get_credits_info()
    print(f"\nCredits: {credits.credits}")
    print(f"10 credits = {credits.price_10} NANO")
    
    # 6. Top up credits
    topup = agent.topup_credits(amount=10)
    print(f"\nToppped up: {topup.topped_up_credits} credits")
    print(f"New balance: {topup.new_credits_balance} credits")
    
    # 7. Donate (sends payment automatically)
    donation = agent.donate(amount="0.001")
    print(f"\n❤️  Donated {donation.amount} NANO")
    
except AgentError as e:
    print(f"❌ Error [{e.error_code}]: {e.message}")

Complete SDK Examples

Check Balance

Check your Nano balance and automatically receive pending blocks

check_balance.py
from ifenpay_agent_sdk import Agent, AgentError

agent = Agent("http://localhost:7860")

try:
    # Check balance (auto-receives pending blocks)
    balance = agent.check_balance(auto_receive_pending_blocks=True)
    print(f"✅ Balance: {balance.balance} NANO")
    print(f"   Pending: {balance.pending} NANO")
    print(f"   Address: {balance.address}")
    
    # Check balance without auto-receive
    balance = agent.check_balance(auto_receive_pending_blocks=False)
    print(f"\n💰 Balance: {balance.balance} NANO")
    print(f"   Pending: {balance.pending} NANO")

except AgentError as e:
    print(f"❌ Error [{e.error_code}]: {e.message}")