Skip to main content

Async Python SDK for the Rapyd Fintech-as-a-Service API

Project description

PyPI version Python versions License: MIT CI

rapyd-py

The unofficial async Python SDK for Rapyd — the one Rapyd should have built.

Fully async, Pydantic v2 models, webhook verification, auto-pagination, and complete coverage of all 6 Rapyd domains. Built to be the foundation for rapyd-mcp.

Why This Exists

The official rapyd-sdk on PyPI is a bare-bones beta — no async support, no Pydantic models, no webhook signature verification, and incomplete endpoint coverage. This library fixes all of that.

Install

pip install rapyd-py

Quick Start

import asyncio
from rapyd import RapydClient

async def main():
    async with RapydClient() as rapyd:
        # Create a payment
        payment = await rapyd.payments().create(
            amount=100.00,
            currency="USD",
            payment_method={
                "type": "us_visa_card",
                "fields": {
                    "number": "4111111111111111",
                    "expiration_month": "12",
                    "expiration_year": "29",
                    "cvv": "345",
                    "name": "John Doe",
                }
            },
            capture=True,
        )
        print(f"Payment created: {payment.id} — status: {payment.status}")

asyncio.run(main())

Configuration

Environment Variables (recommended)

export RAPYD_ACCESS_KEY=your_access_key
export RAPYD_SECRET_KEY=your_secret_key
export RAPYD_ENVIRONMENT=sandbox   # or "production"

Or use a .env file — the SDK reads it automatically.

Explicit Arguments

client = RapydClient(
    access_key="your_access_key",
    secret_key="your_secret_key",
    environment="sandbox",
    timeout=30,
)

Domains

Collect (Payments)

# Payments
payment = await rapyd.payments().create(amount=50, currency="USD", ...)
payment = await rapyd.payments().get("payment_xxx")
payments = await rapyd.payments().list(limit=20)

# Refunds
refund = await rapyd.refunds().create(payment="payment_xxx", amount=10)

# Customers
customer = await rapyd.customers().create(name="Jane Doe", email="jane@example.com")

# Checkout
checkout = await rapyd.checkout().create(amount=100, country="US", currency="USD")

# Subscriptions & Plans
plan = await rapyd.plans().create(amount=29.99, currency="USD", interval="month", product="product_xxx")
sub = await rapyd.subscriptions().create(customer="cus_xxx", billing="pay_automatically", ...)

Disburse (Payouts)

payout = await rapyd.payouts().create(
    beneficiary="beneficiary_xxx",
    sender="sender_xxx",
    payout_amount=10000,
    payout_currency="PHP",
    payout_method_type="ph_metrobank_bank",
    ewallet="ewallet_xxx",
)
confirmed = await rapyd.payouts().confirm("payout_xxx")

Wallet

wallet = await rapyd.wallets().create(first_name="John", last_name="Doe", ...)
transfer = await rapyd.wallet_transfers().create(
    source_ewallet="ewallet_src",
    destination_ewallet="ewallet_dst",
    amount=500,
    currency="USD",
)

Issuing (Cards)

card = await rapyd.cards().create(ewallet_contact="cont_xxx", card_program="cardprog_xxx")
await rapyd.cards().activate(card=card.id)
await rapyd.cards().set_pin(card=card.id, pin="1234")

Verify (KYC)

identity = await rapyd.identities().create(country="US", document_type="passport", ...)
hosted = await rapyd.verification().create_hosted_page(country="US", ...)

Protect (Fraud)

settings = await rapyd.fraud().get_settings()
await rapyd.fraud().update_settings(enabled=True)

Webhook Verification

from fastapi import FastAPI, Request, Header
from rapyd import parse_webhook_event

app = FastAPI()

@app.post("/webhook")
async def webhook(
    request: Request,
    salt: str = Header(...),
    timestamp: str = Header(...),
    signature: str = Header(...),
):
    body = await request.body()
    event = parse_webhook_event(
        body,
        salt=salt,
        timestamp=timestamp,
        signature=signature,
        access_key="your_access_key",
        secret_key="your_secret_key",
        webhook_url="https://yourdomain.com/webhook",
    )
    print(f"Received {event.type}: {event.data}")
    return {"status": "ok"}

Async Pagination

from rapyd import paginate

async for payment in paginate(rapyd.payments().list, limit=50):
    print(payment.id)

Error Handling

from rapyd import RapydClient, RapydApiError, RapydAuthError

async with RapydClient() as rapyd:
    try:
        payment = await rapyd.payments().get("payment_nonexistent")
    except RapydAuthError as e:
        print(f"Auth failed: {e.error_code}")
    except RapydApiError as e:
        print(f"API error: {e.error_code}{e.message}")
        print(f"Operation ID: {e.operation_id}")

MCP Server

This SDK is the foundation for rapyd-mcp — a Model Context Protocol server for Rapyd. Coming soon.

Contributing

  1. Clone the repo
  2. pip install -e ".[dev]"
  3. pytest to run tests
  4. ruff check . for linting

Links

License

MIT

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

rapyd_py-1.0.0.tar.gz (46.0 kB view details)

Uploaded Source

Built Distribution

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

rapyd_py-1.0.0-py3-none-any.whl (45.8 kB view details)

Uploaded Python 3

File details

Details for the file rapyd_py-1.0.0.tar.gz.

File metadata

  • Download URL: rapyd_py-1.0.0.tar.gz
  • Upload date:
  • Size: 46.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rapyd_py-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fa8ff4e4d488cb20893363ce15a8d322b1890cc6af5697a4d8a5f3989a91a11c
MD5 73df0ca055b11066af4db834f92ee391
BLAKE2b-256 16654759f7aa59fe40d8a30cced9a8a0bc1c58b5d9dfeb945c376426458f4a14

See more details on using hashes here.

File details

Details for the file rapyd_py-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: rapyd_py-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 45.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rapyd_py-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3e23e756c506081f67524a7b4bffdc9ab3d60d50b5850369f73d75f1075d6106
MD5 361c84f73e460db2b41c87534e57db2f
BLAKE2b-256 4f19af322eba28e81368430419f7afe2cad2742c235b4faa86303a9777d7ca76

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