Python SDK for the SwiftPay REST API (sync + async).
Project description
swiftpay-api-client
Python SDK for the SwiftPay REST API. Sync and async, type-checked end-to-end with Pydantic v2.
- Two transports.
SwiftPayfor sync code,AsyncSwiftPayfor asyncio (FastAPI, async workers). - Auth-aware modules. Methods that need a secret key raise
SwiftPayConfigErrorat call time when the key is missing — no silent 401s. - Typed errors. Each HTTP status maps to a discriminated subclass.
- Two runtime deps.
httpxandpydantic.
Install
pip install swiftpay-api-client
Requires Python 3.10+.
Quick start
from swiftpay import SwiftPay
client = SwiftPay(secret_key="sk_live_...")
result = client.invoices.create(
amount="100.00",
token="USDC",
network="ethereum",
recipients={"evm": "0xYourWallet..."},
external_ref="order_8675309",
)
print("New" if result.created else "Existing", result.invoice.id)
Async
import asyncio
from swiftpay import AsyncSwiftPay
async def main() -> None:
async with AsyncSwiftPay(secret_key="sk_live_...") as client:
chains = await client.utils.list_chains()
for c in chains:
print(c.id, c.chain_id)
asyncio.run(main())
Configuration
SwiftPay(
secret_key="sk_live_...", # optional — required only for secret-scoped modules
base_url="https://api.swiftpay.finance", # optional, defaults to production
timeout=30.0, # optional, seconds
http_client=..., # optional, inject your own httpx.Client
)
Modules
| Module | Auth | Methods |
|---|---|---|
client.utils |
none | list_chains, list_tokens |
client.invoices |
secret key | create, list, get, list_transactions, rescan |
client.x402.facilitator |
none | supported, verify, settle, payment_status |
client.x402.endpoints |
secret key | register, list, deactivate, requirements, requirements_by_id |
x402.facilitator.settle() returns a SettlementResponse for both 200 (settled) and 422 (settlement failed). Inspect result.success / result.error. Other 4xx / 5xx still raise.
Error handling
from swiftpay import SwiftPay
from swiftpay.errors import (
SwiftPayError,
SwiftPayValidationError,
SwiftPayAuthError,
SwiftPayNotFoundError,
SwiftPayConfigError,
SwiftPayServerError,
)
client = SwiftPay(secret_key="sk_live_...")
try:
client.invoices.create(amount="", token="USDC", network="ethereum")
except SwiftPayValidationError as e:
print("Bad input:", e.details)
except SwiftPayAuthError:
print("Bad API key")
except SwiftPayError as e:
print("SwiftPay error", e.status, e, e.trace_id)
Versioning
This SDK is pinned to one major version of the SwiftPay REST API. Each swiftpay-api-client major maps 1:1 to a SwiftPay API major.
| SDK | API path prefix |
|---|---|
0.x / 1.x |
/v1/... |
When SwiftPay ships /v2, we'll release swiftpay-api-client@2.0.0 with regenerated types. Within a major, we follow SemVer.
Development
uv venv
source .venv/bin/activate
uv pip install -e ".[dev]"
ruff check .
ruff format --check .
mypy src
pytest --cov
python -m build
License
Licensed under the Apache License, Version 2.0. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file swiftpay_api_client-0.1.1b0.tar.gz.
File metadata
- Download URL: swiftpay_api_client-0.1.1b0.tar.gz
- Upload date:
- Size: 22.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a3cd7e5b0d7f40c84ce3d485b1b1a95538145684d981a6c2293fdc8ba2e7545f
|
|
| MD5 |
35fb553f1c215ac57b89776770bac528
|
|
| BLAKE2b-256 |
3dc55fdd153cabc56de38ad4bab409bc116802da5d81155630fe8d77212eef30
|
File details
Details for the file swiftpay_api_client-0.1.1b0-py3-none-any.whl.
File metadata
- Download URL: swiftpay_api_client-0.1.1b0-py3-none-any.whl
- Upload date:
- Size: 24.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
749f3f0893a2a2778c6aed9ef6766c8b8c7da6954a847531e6afa4fcb75b3c4c
|
|
| MD5 |
bcb0ee8e6bd3003b8cecd5a30b15817e
|
|
| BLAKE2b-256 |
a2eeb2f2b37dd1e6c17e66fc2698eee999eb8c4409fecf2a88d11559789798a8
|