Python SDK

Cliente Python com tipagem completa e suporte a async/await. Compativel com Python 3.9+.

Instalacao

pip install axon-sdk
# ou
poetry add axon-sdk

Configuracao

client.pypython
import os
from axon import Axon

client = Axon(
    api_key=os.environ["AXON_API_KEY"],
    environment="sandbox",  # ou "production"
)

Vault - Tokenizacao

vault.pypython
from axon import Axon

client = Axon(api_key="axon_sk_...")

# Tokenizar cartao
token = client.vault.tokens.create(
    card={
        "number": "4111111111111111",
        "exp_month": 12,
        "exp_year": 2025,
        "cvv": "123",
        "holder_name": "JOAO SILVA",
    },
    metadata={
        "customer_id": "cust_123",
    },
)

print(f"Token: {token.id}")
print(f"Brand: {token.card.brand}")
print(f"Last4: {token.card.last4}")

# Recuperar token
retrieved = client.vault.tokens.retrieve(token.id)

# Deletar token
client.vault.tokens.delete(token.id)

Async/Await

async_example.pypython
import asyncio
from axon import AsyncAxon

async def main():
    client = AsyncAxon(api_key="axon_sk_...")

    # Tokenizar cartao de forma assincrona
    token = await client.vault.tokens.create(
        card={
            "number": "4111111111111111",
            "exp_month": 12,
            "exp_year": 2025,
            "cvv": "123",
        },
    )

    print(f"Token: {token.id}")

asyncio.run(main())

Synapse - Transformacoes

synapse.pypython
# Transformar mensagem ISO 20022
result = client.synapse.transform(
    source_format="pacs.008",
    target_format="pix_payment",
    message=pacs008_xml,
    options={
        "validate": True,
        "enrich": True,
    },
)

print(f"Transformation ID: {result.transformation_id}")
print(f"Result: {result.data}")

# Listar transformacoes suportadas
transformations = client.synapse.list_transformations()

Tratamento de erros

errors.pypython
from axon import Axon
from axon.exceptions import (
    AxonError,
    RateLimitError,
    ValidationError,
    NotFoundError,
)

client = Axon(api_key="axon_sk_...")

try:
    token = client.vault.tokens.retrieve("tok_invalid")
except NotFoundError as e:
    print(f"Token not found: {e.message}")
except RateLimitError as e:
    print(f"Rate limit exceeded. Retry after: {e.retry_after}")
except ValidationError as e:
    print(f"Validation error: {e.details}")
except AxonError as e:
    print(f"Error code: {e.code}")
    print(f"Message: {e.message}")
    print(f"Request ID: {e.request_id}")

Type Hints

typed.pypython
from axon import Axon
from axon.types import Token, PixToken

def process_card(client: Axon, card_number: str) -> Token:
    token = client.vault.tokens.create(
        card={
            "number": card_number,
            "exp_month": 12,
            "exp_year": 2025,
            "cvv": "123",
        },
    )
    return token

Recursos