Skip to main content

Python SDK

Official Python client for Axol API.

Installation

pip install axol-api-client

Quick Start

from axol import AxolClient

client = AxolClient(api_key="your_key")

# Get gas prices
gas = client.gas_prices("ethereum")
print(gas)

Client Configuration

client = AxolClient(
api_key="your_key",
base_url="https://api.axol.io", # Optional
timeout=30, # Request timeout in seconds
retry_count=3, # Auto-retry on failure
cache_ttl=60 # Cache responses for 60 seconds
)

Core Methods

Blockchain Data

# Get latest block
block = client.get_block("ethereum", "latest")

# Get specific block
block = client.get_block("ethereum", 18500000)

# Get transaction
tx = client.get_transaction("ethereum", "0x...")

# Get balance
balance = client.get_balance("ethereum", "0x...")

# Get token balances
tokens = client.get_token_balances("0x...", "ethereum")

Gas Prices

# Single chain
gas = client.gas_prices("ethereum")

# Multiple chains
gas = client.gas_prices(["ethereum", "polygon", "arbitrum"])

# With prediction
gas = client.predict_gas_prices("ethereum", minutes_ahead=10)

Multi-chain Operations

# Check balances across chains
balances = client.get_multi_chain_balances(
address="0x...",
chains=["ethereum", "polygon", "arbitrum"]
)

# Search transactions across chains
txs = client.search_transactions(
address="0x...",
chains=["ethereum", "bsc", "polygon"],
limit=100
)

Async Support

import asyncio
from axol import AsyncAxolClient

async def main():
client = AsyncAxolClient(api_key="your_key")

# Concurrent requests
results = await asyncio.gather(
client.get_block("ethereum", "latest"),
client.get_block("polygon", "latest"),
client.get_block("arbitrum", "latest")
)

for block in results:
print(block)

asyncio.run(main())

WebSocket Integration

# Real-time streaming
async def stream():
await client.ws.connect()

# Subscribe to channels
await client.ws.subscribe("gas_prices", on_gas)
await client.ws.subscribe("blocks:ethereum", on_block)

await client.ws.run_forever()

def on_gas(data):
print(f"Gas update: {data}")

def on_block(data):
print(f"New block: {data}")

Error Handling

from axol.exceptions import (
AxolAPIError,
RateLimitError,
CUPoolExhaustedError,
AuthenticationError
)

try:
result = client.get_block("ethereum", "latest")
except RateLimitError as e:
# Exceeded CUPs (throughput limit)
print(f"Rate limited (CUPs exceeded). Reset at: {e.reset_time}")
print(f"CUPs limit: {e.cups_limit}, Current: {e.current_cups}")
# Implement exponential backoff
except CUPoolExhaustedError as e:
# Exceeded monthly CU pool
print(f"Monthly CU pool exhausted. Reset: {e.reset_date}")
print(f"CU limit: {e.cu_limit}, Used: {e.cu_used}")
# Options: wait for reset, enable overage billing, or upgrade tier
except AuthenticationError:
print("Invalid API key")
except AxolAPIError as e:
print(f"API error: {e.message}")

# Check CU usage proactively
response = client.get_block("ethereum", "latest")
cu_remaining = response.headers.get('X-RateLimit-CU-Remaining')
print(f"CUs remaining this month: {cu_remaining}")

Caching

# Enable caching
client = AxolClient(
api_key="your_key",
cache_enabled=True,
cache_ttl=300 # 5 minutes
)

# Clear cache
client.clear_cache()

# Bypass cache for specific request
block = client.get_block("ethereum", "latest", cache=False)

Pagination

# Paginate through results
page = 1
while True:
txs = client.get_transactions(
address="0x...",
page=page,
limit=100
)

if not txs:
break

for tx in txs:
process(tx)

page += 1

Batch Requests

# Batch multiple calls
requests = [
("get_block", ["ethereum", "latest"]),
("get_block", ["polygon", "latest"]),
("gas_prices", ["ethereum"]),
]

results = client.batch(requests)

Custom Requests

# Make custom API calls
response = client.request(
method="GET",
endpoint="/custom/endpoint",
params={"key": "value"}
)

Utilities

# Format addresses
formatted = client.utils.format_address("0xabc...")

# Convert units
eth = client.utils.wei_to_eth(1000000000000000000)
gwei = client.utils.wei_to_gwei(1000000000)

# Validate addresses
is_valid = client.utils.is_valid_address("0x...")

Next Steps