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.1.0.tar.gz (57.5 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.1.0-py3-none-any.whl (56.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rapyd_py-1.1.0.tar.gz
  • Upload date:
  • Size: 57.5 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.1.0.tar.gz
Algorithm Hash digest
SHA256 fc6d3c1eba5a4682874ffc79da71395211614b4b56782d8fbcaad86901380b89
MD5 f0e2f8d4caff0a7b8fae02ad17d1a12d
BLAKE2b-256 44d019e7c93cad24e227208ce21206ad4b227a00aa774c472ea8e3c204f68196

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rapyd_py-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 56.9 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 27975a8513fed0100246585240a13fd76db5cc07915c1d1b84967c1745fe8bae
MD5 b7c819e1b44642dc092736aad46949ee
BLAKE2b-256 36d021b4ad9ff98b222cf7d9660443533f4ba6d1a59c8a4c08c7f3fb1f50d58a

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