ChiefPay Python SDK
Project description
ChiefPay SDK
Official Python SDK for interacting with the ChiefPay payment system.
Requirements
- Python 3.9+
Installation
pip install chiefpay
Quick Start
Synchronous Client
from chiefpay import Client
client = Client(api_key="your_api_key")
# Get exchange rates
rates = client.get_rates()
# Get available payment methods
payment_methods = client.get_payment_methods()
# Create an invoice
invoice = client.create_invoice(
order_id="unique-order-id",
amount="15.4", # String format, USD
fee_included=False,
accuracy="0.01"
)
print(f"Payment URL: {invoice.url}")
Asynchronous Client
import asyncio
from chiefpay import AsyncClient
async def main():
async with AsyncClient(api_key="your_api_key") as client:
rates = await client.get_rates()
invoice = await client.create_invoice(
order_id="unique-order-id",
amount="100.50"
)
print(f"Invoice ID: {invoice.id}")
asyncio.run(main())
WebSocket Client
from chiefpay import SocketClient
def on_notification(data):
if data.type == "invoice":
print(f"Invoice updated: {data.invoice.status}")
elif data.type == "transaction":
print(f"Transaction: {data.transaction.txid}")
with SocketClient(api_key="your_api_key") as client:
client.set_on_notification(on_notification)
input("Press Enter to exit...")
Asynchronous WebSocket Client
import asyncio
from chiefpay import AsyncSocketClient
async def on_notification(data):
print(f"Notification type: {data.type}")
async def on_rates(rates):
print(f"Rates updated: {len(rates)} rates")
async def main():
async with AsyncSocketClient(api_key="your_api_key") as client:
client.set_on_notification(on_notification)
client.set_on_rates(on_rates)
await asyncio.sleep(60)
asyncio.run(main())
Error Handling
from chiefpay import Client
from chiefpay.exceptions import (
APIError,
TransportError,
InvalidJSONError,
ManyRequestsError,
ChiefPayErrorCode,
)
client = Client(api_key="your_api_key")
try:
invoice = client.create_invoice(order_id="", amount="10")
except APIError as e:
print(f"API Error: {e.code} - {e.errors}")
if e.code == ChiefPayErrorCode.INVALID_ARGUMENT:
print("Invalid parameters")
except ManyRequestsError:
print("Rate limit exceeded")
except TransportError as e:
print(f"Network error: {e.status_code}")
except InvalidJSONError:
print("Invalid JSON response")
Examples
For comprehensive examples, including advanced use cases, check out the examples directory:
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
chiefpay-2.0.0.tar.gz
(14.2 kB
view details)
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
chiefpay-2.0.0-py3-none-any.whl
(19.0 kB
view details)
File details
Details for the file chiefpay-2.0.0.tar.gz.
File metadata
- Download URL: chiefpay-2.0.0.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd07696dd1ee4913ece480957cf0766601a5a11eff7fea08872f7363aa9aad34
|
|
| MD5 |
bdf746e3d3c23a9a410af098f1c998e4
|
|
| BLAKE2b-256 |
5607af0b78364f9c1db5df5f79add5c9ccb0b7fd867a3091d0619d31ca9b46c2
|
File details
Details for the file chiefpay-2.0.0-py3-none-any.whl.
File metadata
- Download URL: chiefpay-2.0.0-py3-none-any.whl
- Upload date:
- Size: 19.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efc4374564ec769d3f0b1120c9280979369225af263ea40ee696e7bb3b4c6609
|
|
| MD5 |
5e695df2c94bd87942f80d0abd6b3f31
|
|
| BLAKE2b-256 |
43d6b651f8e231601403d2a51a2a1c2286c67a9c3f7bef87c3f62a22d98e8f7e
|