The sohopay package is the official Python client for the SohoPay API. It mirrors the TypeScript SDK — same resources, same behavior, snake_case methods — with automatic retries and per-request idempotency built in.

Installation

The SDK supports Python 3.9+. Source and issues live at github.com/sohopay/sohopay-python; releases are published to PyPI.

Initialize the client

Pass your API key and, optionally, the target environment. The environment selects the base URL for you — use a sk_test_ key with sandbox and a sk_live_ key with mainnet.
Never hard-code API keys or commit them to git. Load them from environment variables or a secrets manager. See Authentication & Security.

Quick example

The canonical flow: create an agent with a credit line, create an order, submit the payment, and verify the settlement webhook when it arrives.
To confirm settlement, verify the payment.settled webhook instead of polling. The SDK validates the HMAC-SHA256 signature and timestamp for you:

Method reference

All methods are snake_case and parameters mirror the API Reference field names exactly.

Error handling

Every non-2xx response raises a SohoPayError exception carrying the API’s error code, the HTTP status, and the request_id to quote in support tickets. See Errors for the full code list.

Advanced

  • Automatic retries — network failures, 429, and 5xx responses are retried with exponential backoff (respecting Retry-After). Configure with max_retries in the constructor; set max_retries=0 to disable.
  • Idempotency — the SDK generates a unique Idempotency-Key per POST request and reuses it across retries, so a retried payment can never settle twice. Pass idempotency_key= on any call to control it yourself.
  • Typed models — responses are typed dataclass-style models with attribute access (agent.agent_id, payment.settlement_tx); call .to_dict() when you need plain dictionaries.
A Go SDK and a sohopay CLI are on the roadmap but not yet shipped. Until then, generate clients from the OpenAPI spec — see OpenAPI Tools.

Next steps

TypeScript SDK

The same client surface for Node.js and TypeScript.

Code Examples

Runnable, CI-tested examples for every core flow.

Error Handling Guide

Retry strategies and recovery patterns for every error code.