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.
Install:
pip install revaly-sdk— published on PyPI. Requires Python ≥ 3.9. GitHub release artifacts remain the provenance anchor and fallback channel.
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 — failing over reproduces the same rejection 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.
pip install revaly-sdk
Prefer to install from a verified artifact? Every release attaches
revaly-sdk-python.tar.gzand a wheel, each with a.sha256and aprovenance.json; verify the checksum, thenpip install ./revaly-sdk-python.tar.gz— 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 — failing over reproduces the same rejection 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_deadlineexpiry after send classifiesRapOutcomeUnknown(reconcile), never TransientFailure.connect_timeoutexpiry proves the request never left the client and classifiesRapTransientFailure— 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
loggingmodule (logger namerevaly_sdk; silent until your application configures handlers, or passlogger=). Default output is values-free — operation, status, class, correlation id.DEBUGlevel 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.
Design guarantees
- Each charge is sent exactly once. Retry policy stays yours, with the classification that makes it safe to exercise.
- Every call stands alone — no cross-request state, no circuit breaker, so behaviour under load is the behaviour you tested.
- The reconcile re-poll you bound is the only loop the SDK owns.
- Classification rests on evidence only: HTTP status and
ErrorResponse.code. Message text, latency and wait length are reported to you and excluded from the verdict. - Recovery beyond this boundary belongs to RAP-core — resubmission and
bypassPlatformare platform-internal, so a payment's outcome stays unambiguous.
Concretely, on the transport: urllib3's default connect retries and redirect-following are
switched off per request, so a 307 on POST /payments arrives as a response and
classifies RapOutcomeUnknown rather than being silently re-sent.
Normative form: docs/failover-contract.md §5 and
Appendix A.
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.
Where to go next
- Failover cookbook — recipes for each outcome, choosing a reconcile policy, testing offline, debugging with correlation ids.
- Failover contract — the normative specification, with sequence diagrams and the verbatim prohibitions in Appendix A.
- AGENTS.md — the whole contract on one page, for AI coding agents.
- Support · Contributing · Security
Metadata
Release files for revaly-sdk 0.5.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| revaly_sdk-0.5.2.tar.gz | 130.2 kB | With provenance | Details for revaly_sdk-0.5.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| revaly_sdk-0.5.2-py3-none-any.whl | Python 3 | none | any | Details for revaly_sdk-0.5.2-py3-none-any.whl |
Total release size: 384.8 kB
Release files / revaly_sdk-0.5.2.tar.gz
| Download URL | revaly_sdk-0.5.2.tar.gz |
|---|---|
| Size | 130.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2f30e2c85039bca1e6d1c5afaa8d2c1be0e10fc49cc1fb089e569b3ad7e7d65a
|
|
BLAKE2b-256 checksum How to use checksums |
ca3200ea036a7146262cb82f7d527c635e1738019b526679b7584fdf4e38498d
|
| 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 12, 2026.
Transparency logRelease files / revaly_sdk-0.5.2-py3-none-any.whl
| Download URL | revaly_sdk-0.5.2-py3-none-any.whl |
|---|---|
| Size | 254.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8173f338f53b40d6d2e7deb749864fd746b7a4a7d05a3b2bbcde43e55e83c3e7
|
|
BLAKE2b-256 checksum How to use checksums |
a078c74aa042bdfecda54f4422c7a95cf351d8092bed86bcc2d954a22047b427
|
| 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 12, 2026.
Transparency logSecurity for revaly-sdk 0.5.2
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.
Attestation for revaly_sdk-0.5.2.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 12, 2026.
Transparency logA 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.