Python

Python

The replaystack-python-sdk repository ships the official replaystack-sdk package on PyPI. It mirrors the Node @replaystack/sdk feature set: masking, sampling, breadcrumbs, offline queue, and framework middleware for FastAPI, Flask, and Django.

Install

Published as replaystack-sdk on PyPI. Import the client from replaystack_sdk.

pip
pip install replaystack-sdk
# pip install replaystack-sdk[fastapi]
# pip install replaystack-sdk[flask]
# pip install replaystack-sdk[django]
# pip install replaystack-sdk[all]

Minimal client

Environment variables

The client reads the same REPLAYSTACK_* variables as the TypeScript SDK when you omit arguments—see Authentication in this guide and the full option table in the repository README.
replaystack_sdk.ReplayStackClient
from replaystack_sdk import ReplayStackClient
import os

replaystack = ReplayStackClient(
    api_key=os.environ["REPLAYSTACK_API_KEY"],
    endpoint=os.environ.get("REPLAYSTACK_ENDPOINT"),  # optional; defaults to cloud API host
    service_name=os.environ.get("REPLAYSTACK_SERVICE_NAME", "my-service"),
    environment=os.environ.get("REPLAYSTACK_ENVIRONMENT", "development"),
    app_version=os.environ.get("REPLAYSTACK_APP_VERSION"),
    commit_hash=os.environ.get("REPLAYSTACK_COMMIT_HASH"),
)

Capture

Manual events use snake_case field names on the wire-compatible payload helpers (capture_event, capture_exception).

capture_event
replaystack.capture_event(
    event_type="custom",
    endpoint="health-check",
    status="success",
)
capture_exception
try:
    risky_operation()
except Exception as exc:
    replaystack.capture_exception(
        exc,
        event_type="custom",
        endpoint="process-payment",
        request_payload={"order_id": "ord_123"},
    )
    raise

Frameworks

Install the matching extra, then follow the README sections for FastAPI/Starlette, Flask, and Django middleware—same ingestion endpoint and headers as other SDKs.

Prefer Send events (HTTP API) only for one-off scripts without dependencies; for production services, use this SDK so retries, masking, and queueing stay consistent with Node and PHP.