Skip to main content

Revaly RAP SDK for Python

Server-side Python SDK for the RAP V2 API: payments, payment methods, transactions and notify — with a merchant-facing failover contract built in. Every failed payment call raises exactly one of three typed classes that tell you what you may safely do next.

Package status: the PyPI name revaly-sdk is [Proposed] until registry provisioning (OQ-3), and registry publish is embargoed — install from the per-language GitHub release artifact until then. Requires Python ≥ 3.9.

Why the error classes matter (read this first)

A failed charge(...) does not mean the payment didn't happen. If you blind-fail-over to your own gateway on an ambiguous failure, the cardholder can be charged twice. The SDK classifies every failure so you never have to guess:

Class Meaning What you do
RapPermanentRejection Received and rejected (400/401/403/404/422) Fix or decline. Never fail over — the same request fails anywhere.
RapTransientFailure Definitively not processed (provably never sent, or 503 + code: not_processed) Route to your own gateway immediately.
RapOutcomeUnknown May have been processed (timeout after send, reset, 5xx) Reconcile before acting — see below.

Quickstart (sandbox key → first charge, ≤ 15 minutes)

Your API key's scope selects the environment: sandbox and live share the same URL — there is no separate sandbox host. Use the sandbox-scoped key issued by Enablement.

# Download revaly-sdk-python.tar.gz from the release, verify its .sha256, then:
pip install ./revaly-sdk-python.tar.gz
# (the release also attaches a wheel — either file installs the same package)
import os

from revaly_sdk import (
    CreditCard,
    Found,
    NotFoundYet,
    PaymentMethod,
    PaymentRequest,
    RapClient,
    RapOutcomeUnknown,
    RapPermanentRejection,
    RapTransactionOutcome,
    RapTransientFailure,
    ReconcilePolicy,
)

client = RapClient(os.environ["RAP_API_KEY"])

request = PaymentRequest(
    amount=1999,
    currency="USD",
    merchant_transaction_id="order-1042",  # required on every payment — it is your reconcile handle
    order_id="order-1042",  # orderId + email below: the sandbox simulator requires both for an approval
    # paymentMethodType is omitted — inferred from the one populated method object
    payment_method=PaymentMethod(
        full_name="Ada Lovelace",  # creditCard requires a cardholder name
        email="ada@example.com",
        credit_card=CreditCard(
            number="4111111111111111",  # sandbox test PAN
            card_verification_code="999",
            expiry_month="12",
            expiry_year="2030",
        )
    ),
)

try:
    transaction = client.charge(request)
    print("approved", transaction.transaction_id)
except RapPermanentRejection as failure:
    # Fix or decline. Never fail over — the same request fails anywhere.
    print("rejected", failure.status, failure.api_error, failure.correlation_id)
except RapTransientFailure:
    # Definitively not processed — route to your own gateway immediately.
    route_to_own_gateway()
except RapOutcomeUnknown:
    # May have been processed — reconcile BEFORE acting (double-charge hazard).
    verdict = client.reconcile(
        "order-1042",
        ReconcilePolicy(max_attempts=5, overall_budget=30.0, initial_delay=0.5),
    )
    if isinstance(verdict, Found):
        # The record IS visible. Found(APPROVED) means the money moved —
        # failing over now would double-charge.
        print("resolved", verdict.outcome, verdict.correlation_id)
    elif isinstance(verdict, NotFoundYet):
        # Not visible YET — absence is not provable in V1. Hold and escalate
        # per your risk policy; do not treat this as "safe to fail over".
        print("hold", verdict.attempts, verdict.last_correlation_id)
    else:
        # Verdicts are open for extension (SafeToFailover arrives with
        # platform P-2 as a minor release). Always keep this branch.
        escalate_to_operator(verdict)

Timeouts

overall_deadline defaults to 75 seconds (DEFAULT_OVERALL_DEADLINE) — ratified from production latency telemetry (ADR-SDK-027): it clears every observed gateway tail cluster (the worst non-hung tail seen in 14 fleet days was 64 s), clips ≲0.007% of charges, and still classifies well before the platform's own ≈100 s ceiling. Tighten it per your checkout budget (RAP routes gateways server-side, so the default must cover the slowest common class), or pass an explicit overall_deadline=None to disable the SDK deadline. connect_timeout defaults to 10 seconds (DEFAULT_CONNECT_TIMEOUT) — ratified from the OQ-11 edge verification (ADR-SDK-029): roughly 25× the observed cold client→edge TLS envelope, and 65 s below the overall deadline. Pass an explicit connect_timeout=None to disable the SDK connect bound. All timeouts are seconds:

client = RapClient(api_key, connect_timeout=3.0, overall_deadline=10.0)
# or per call:
client.charge(request, overall_deadline=5.0)

Note the per-call asymmetry: passing overall_deadline=None (or omitting it) on a call means "use the client's configured value", never "disable" — disabling the deadline is a client-construction decision only (RapClient(..., overall_deadline=None)), deliberately without a per-call equivalent (the safe direction). The same asymmetry applies to connect_timeout.

  • overall_deadline expiry after send classifies RapOutcomeUnknown (reconcile), never TransientFailure.
  • connect_timeout expiry proves the request never left the client and classifies RapTransientFailure — urllib3 reports the connect phase distinctly even when only an overall deadline is set.

Python has no ambient cancellation token: bound calls with these timeout arguments and bound reconciliation with the ReconcilePolicy budget — that is this SDK's cancellation idiom.

API versioning

Requests pin X-Api-Version: 2.1 by default. "2.0" is selectable (api_version="2.0") but narrows the contract: ErrorResponse.code is not part of the 2.0 documented surface, so a 503 + not_processed classifies RapOutcomeUnknown (reconcile) instead of RapTransientFailure (immediate failover). Pin 2.1 unless you have a frozen 2.0 integration.

Testing your failover handler — no network

The mock transport scripts every row of the failure taxonomy and both reconcile verdicts, and asserts your requests carry the SDK User-Agent. It replaces only the wire: header injection and classification run exactly as in production.

from revaly_sdk import RapClient
from revaly_sdk.testing import RapMockTransport

mock = RapMockTransport()
mock.charge().returns_not_processed_503()  # → RapTransientFailure
mock.reconcile().not_found_yet(2).then_found_approved()

client = RapClient("sk-synthetic", transport=mock)
# exercise YOUR suppression/escalation logic against scripted consecutive outcomes:
mock.charge().returns_bare_503().throws_connection_refused().returns_approved()

Scenario methods mirror the contract: returns_permanent_rejection(status), returns_not_processed_503(), throws_connection_refused(), throws_dns_failure(), throws_ssl_handshake_failure(), throws_connect_timeout(), throws_timeout_after_send(), throws_connection_reset(), returns_bare_503(), returns_server_error(), pending(), and raw escapes returns(...) / throws_io(...). Transport failures are simulated with real urllib3 exception instances, so classification in your tests exercises the production code path. Synthetic data only — no real PAN/CVV/PII ever appears in the mock.

Logging & debugging

  • Logging uses the stdlib logging module (logger name revaly_sdk; silent until your application configures handlers, or pass logger=). Default output is values-free — operation, status, class, correlation id. DEBUG level carries allowlist-scrubbed payloads only; PAN/CVV/PII and the API key can never appear (the API key is also absent from every error message).
  • wire_trace_hook: a request/response observer for Enablement escalations — payloads arrive already scrubbed by the runtime's central allowlist scrubber.
  • Every response and every typed error carries the X-Correlation-ID; quote it in support tickets to join RAP-core telemetry directly.

What this SDK never does

No hidden retries, no resubmission, no circuit breaker, no cross-request state, no bypassPlatform. The explicit, caller-bounded reconcile re-poll is the only loop the SDK owns. Classification never derives from message text, latency, or wait heuristics. (Concretely: urllib3's default connect retries and redirect-following are disabled on every request — a 307 on POST /payments comes back as a response and classifies RapOutcomeUnknown instead of being silently re-sent.)

Beyond payments

The full generated V2 surface ships in the same package and flows through the same transport, headers and classification:

methods = client.payment_methods.list_payment_methods()
raw = client.transactions.get_transaction_by_id_without_preload_content("txn-1")

One logging caution on this surface: raw core operations raise the generator's ApiException, not the three typed classes — and str(ApiException) embeds the full HTTP response body. Response bodies can contain PII (names, emails, masked card data): never log raw core exceptions or response bodies; log the correlation id and the typed runtime errors (values-free by design) instead.

Metadata

Release files for revaly-sdk 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for revaly-sdk 0.5.1
File Size Uploaded Provenance Actions
revaly_sdk-0.5.1.tar.gz 129.3 kB With provenance Details for revaly_sdk-0.5.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for revaly-sdk 0.5.1
File Interpreter ABI Platform Actions
revaly_sdk-0.5.1-py3-none-any.whl Python 3 none any Details for revaly_sdk-0.5.1-py3-none-any.whl

Total release size: 383.4 kB

Release files / revaly_sdk-0.5.1.tar.gz

Download URL revaly_sdk-0.5.1.tar.gz
Size 129.3 kB
Tags Source
SHA-256 checksum
How to use checksums
41c18d13cb189db852fabc0f8de61bc7993df7b70ae5f906ece5fe56060328b9
BLAKE2b-256 checksum
How to use checksums
625c9de3ba1cef7e648c3d4e3ee397eb22608d27d37e9e113099a3b2e02307e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.

Transparency log

Release files / revaly_sdk-0.5.1-py3-none-any.whl

Download URL revaly_sdk-0.5.1-py3-none-any.whl
Size 254.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e8236fe2b8abc82cc8d0e5d6a5c5fed44d8517a43f8272c80ea6431854a6b208
BLAKE2b-256 checksum
How to use checksums
076d75e8ee65a8e6621249f1482cca604fe4266f4addbc72e544ff92a34e1317
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.

Transparency log

Security for revaly-sdk 0.5.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for revaly_sdk-0.5.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page