Skip to main content

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:

  • sync.py - Synchronous REST API usage
  • async.py - Asynchronous REST API usage
  • socket.py - WebSocket real-time notifications

Project details


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.1.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chiefpay-2.0.1-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

Details for the file chiefpay-2.0.1.tar.gz.

File metadata

  • Download URL: chiefpay-2.0.1.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for chiefpay-2.0.1.tar.gz
Algorithm Hash digest
SHA256 7e7629b8287c9cd36adeada87be1d828622c6d6425a907e309936ba1a06eb8ac
MD5 dea3202a3dfafb37c5ba02d56e9ff1bd
BLAKE2b-256 f73237457cb172b68679a96472e27ce56d739a6cedd7a404eee5a7100418930b

See more details on using hashes here.

File details

Details for the file chiefpay-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: chiefpay-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 18.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for chiefpay-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b9d7788b7298492e0aadc7a6e8ccf6cbf765d87675673749688f225cf3815694
MD5 9def3d7eafc3ae60f8461cc56d802eaa
BLAKE2b-256 3e5d796dbd364e550575f1d86d4be518d4d7cb6395259a7f439c7e1f4332b98f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page