Python SDK

Official Caibo SDK for Python 3.8+.

pipcaibopay

Installation

pip
pip install caibopay
poetry
poetry add caibopay

Quick Start

main.py
import caibopay
import os

# Initialize the client
client = caibopay.Client(api_key=os.environ["CAIBOPAY_API_KEY"])

# Create a transfer
transfer = client.transfers.create(
    amount=100000,
    source_currency="CAD",
    destination_currency="COP",
    destination={
        "type": "bank_account",
        "country": "CO",
        "account_holder": "Maria Garcia",
        "account_number": "12345678901234"
    }
)

print(f"Transfer created: {transfer.id}")

Async Support

The SDK supports async/await with asyncio:

async_example.py
import asyncio
import caibopay

async def main():
    client = caibopay.AsyncClient(api_key="sk_test_...")

    # Async transfer creation
    transfer = await client.transfers.create(
        amount=100000,
        source_currency="CAD",
        destination_currency="COP",
        destination={
            "type": "bank_account",
            "country": "CO",
            "account_holder": "Maria Garcia",
            "account_number": "12345678901234"
        }
    )

    print(f"Transfer: {transfer.id}")

    # Async iteration
    async for t in client.transfers.list():
        print(t.id)

asyncio.run(main())

Error Handling

errors.py
import caibopay
from caibopay.exceptions import (
    CaiboPayError,
    InvalidRequestError,
    AuthenticationError,
    RateLimitError
)

client = caibopay.Client(api_key="sk_test_...")

try:
    transfer = client.transfers.create(...)
except InvalidRequestError as e:
    print(f"Invalid request: {e.message}")
    print(f"Parameter: {e.param}")
except AuthenticationError:
    print("Check your API key")
except RateLimitError as e:
    print(f"Rate limited. Retry after: {e.retry_after}")
except CaiboPayError as e:
    print(f"API error: {e}")

Type Hints

Full type hints for IDE autocompletion:

typed.py
from caibopay import Client
from caibopay.types import Transfer, TransferCreateParams

client = Client(api_key="sk_test_...")

params: TransferCreateParams = {
    "amount": 100000,
    "source_currency": "CAD",
    "destination_currency": "COP",
    "destination": {
        "type": "bank_account",
        "country": "CO",
        "account_holder": "Maria Garcia",
        "account_number": "12345678901234"
    }
}

transfer: Transfer = client.transfers.create(**params)

# IDE will show available attributes
transfer.id
transfer.status
transfer.created_at

Webhooks (Flask)

webhooks.py
from flask import Flask, request
import caibopay

app = Flask(__name__)
client = caibopay.Client(api_key="sk_test_...")

@app.route("/webhooks", methods=["POST"])
def handle_webhook():
    payload = request.data
    signature = request.headers.get("Caibo-Signature")

    try:
        event = client.webhooks.construct_event(
            payload=payload,
            signature=signature,
            secret=os.environ["WEBHOOK_SECRET"]
        )

        if event.type == "transfer.completed":
            transfer = event.data.object
            print(f"Transfer {transfer.id} completed")

        return {"received": True}

    except caibopay.SignatureVerificationError:
        return {"error": "Invalid signature"}, 400