Skip to main content

Prava Python SDK

Typed server-side Python SDK for Prava Payments.

Documentation · Source

The SDK creates payment sessions, manages enrolled cards, retrieves one-time payment credentials, and reports checkout outcomes. Card collection still happens on Prava's hosted surface or through the browser @prava-sdk/core package—your Python server must never collect a cardholder's raw card number.

Installation

pip install prava-sdk

Python 3.10 or newer is required.

The complete SDK guide is available in docs/, with runnable programs in examples/.

Quick start

from decimal import Decimal

from prava_sdk import PravaClient

client = PravaClient("sk_test_xxx")

session = client.sessions.create(
    user_id="user_123",
    user_email="buyer@example.com",
    total_amount=Decimal("49.99"),
    currency="USD",
    purchase_context=[
        {
            "merchant_details": {
                "name": "Example Store",
                "url": "https://merchant.example",
                "country_code_iso2": "US",
            },
            "product_details": [
                {
                    "description": "Example product",
                    "unit_price": "49.99",
                    "product_id": "sku_123",
                    "quantity": 1,
                }
            ],
        }
    ],
    integration_type="full_checkout",
    callback_url="https://app.example/payments/complete",
)

# Send the cardholder to session.iframe_url. After card entry and passkey approval:
result = client.sessions.wait_for_payment_result(session.session_id)
line_item = result.transactions[0].line_items[0]

card_number = line_item.token.get_secret_value() if line_item.token else None
dynamic_cvv = line_item.dynamic_cvv.get_secret_value() if line_item.dynamic_cvv else None

# Use the one-time credentials at the merchant checkout, then always report the outcome.
client.sessions.report_status(
    session.session_id,
    txn_ref_id=line_item.txn_ref_id,
    txn_status="APPROVED",
)

client.close()

The secret key can instead be supplied through PRAVA_SECRET_KEY. sk_test_* keys automatically use https://sandbox.api.prava.space; sk_live_* keys use https://api.prava.space.

Use the client as a context manager to guarantee cleanup:

from prava_sdk import PravaClient

with PravaClient("sk_test_xxx") as client:
    cards = client.cards.list(customer_id="user_123")

Async client

AsyncPravaClient exposes the same grouped resources and method arguments:

from prava_sdk import AsyncPravaClient

async with AsyncPravaClient("sk_test_xxx") as client:
    result = await client.sessions.wait_for_payment_result(
        "ses_123",
        timeout=300,
        poll_interval=2,
    )

API

Sessions

  • client.sessions.create(...)
  • client.sessions.revoke(session_id)
  • client.sessions.get_payment_result(session_id)
  • client.sessions.wait_for_payment_result(session_id, timeout=300, poll_interval=2)
  • client.sessions.report_status(session_id, ...)

The polling helper returns as soon as the result status becomes awaiting_result, completed, or failed. It raises PravaPollingTimeoutError if the session remains pending past the timeout.

Cards

  • client.cards.list(customer_id=..., status="active", include_card_art=False)
  • client.cards.delete(customer_id=..., card_id=..., reason="OTHER")

Only non-sensitive card metadata is returned by card-management endpoints.

Errors

All failures derive from PravaError. API exceptions expose code, message, status_code, details, and response_id (from the X-Response-ID response header):

from prava_sdk import PravaError

try:
    client.sessions.revoke("ses_missing")
except PravaError as exc:
    print(exc.code, exc.response_id)

The SDK provides dedicated authentication, validation, not-found, invalid-state, rate-limit, transport, request-timeout, and polling-timeout exception types. Requests are not retried automatically because the API does not currently document idempotency keys.

Security

  • Never use sk_test_* or sk_live_* keys in browsers, mobile apps, logs, or version control.
  • Never collect or send a cardholder's underlying card number through this SDK.
  • Payment-result token and dynamic_cvv values are Pydantic SecretStr fields and are redacted from normal model representations. Retrieve them only immediately before checkout.
  • Always call report_status with APPROVED or DECLINED after attempting checkout.

See the API reference, error catalog, and sandbox guide for the complete server contract.

Package architecture

The SDK is organized as a standalone Python library:

prava_sdk/
├── client.py          # Small public sync and async client facades
├── resources/         # Session and card endpoint groups
│   └── _base.py       # Shared resource contracts and validation boundary
├── models/            # Pydantic requests, responses, and enums
├── _config.py         # Secret-key and environment resolution
├── _transport.py      # Shared HTTP, JSON, and response handling
└── errors.py          # Public exception hierarchy

The JavaScript SDK is not a runtime or build dependency. It only handles browser-side card collection and is excluded from Python source and wheel distributions.

Development

uv sync --extra dev
uv run ruff check .
uv run mypy
uv run pytest
uv run mkdocs build --strict
uv run python -m build

Release files for prava-sdk 0.1.0

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

Source distribution (sdist)

Source distribution for prava-sdk 0.1.0
File Size Uploaded
prava_sdk-0.1.0.tar.gz 94.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for prava-sdk 0.1.0
File Interpreter ABI Platform
prava_sdk-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 114.7 kB

Release files / prava_sdk-0.1.0.tar.gz

Download URL prava_sdk-0.1.0.tar.gz
Size 94.9 kB
Tags Source
SHA-256 checksum
How to use checksums
eb85abdbdb19197b78e154b2a72e3c6b4110ac12cc14ff93e93605e04e7dc36a
BLAKE2b-256 checksum
How to use checksums
50928f77c4ecd85e0d2add2f17ac6a48a332b75a5b1435b67e96a9c47eb0af1a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 15, 2026.

Transparency log

Release files / prava_sdk-0.1.0-py3-none-any.whl

Download URL prava_sdk-0.1.0-py3-none-any.whl
Size 19.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1956742f9db9ff3ffdfe51cc30430d1dcbdd5a2a063ea26137a297b8f929bf47
BLAKE2b-256 checksum
How to use checksums
902a4a26beebb7e69ac73cc06c03d70a58074ea9c18971b12d45129ff025d607
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 15, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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