Skip to main content

ChiefPay Python SDK

Project description

ChiefPay SDK

This is the official Python SDK for interacting with the ChiefPay payment system.

Installation

pip install chiefpay

Usage

Synchronous Client

from chiefpay import Client

client = Client(api_key="your_api_key")
rates = client.get_rates()
print("Exchange rates:", rates)

Asynchronous Client

import asyncio
from chiefpay import AsyncClient

async def main():
    client = AsyncClient(api_key="your_api_key")
    rates = await client.get_rates()
    print("Exchange rates:", rates)

asyncio.run(main())

WebSocket Client

from chiefpay import SocketClient

def on_notification(data):
    print("New notification:", data)

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("New notification:", data)

async def main():
    async with AsyncSocketClient(api_key="your_api_key") as client:
        client.set_on_notification(on_notification)
        print("Asynchronous WebSocket client started. Waiting for events...")
        await asyncio.sleep(60)

asyncio.run(main())

Error Handling

from chiefpay import Client
from chiefpay.exceptions import APIError, TransportError, InvalidJSONError, ManyRequestsError, ChiefPayErrorCode

def handle_errors():
    client = Client(api_key="wrong_api_key")

    try:
        rates = client.get_rates()
        print("Exchange rates:", rates)
    except APIError as e:
        if e.code == ChiefPayErrorCode.PERMISSION_DENIED:
            print(f"Permission denied. Check your API key in: {e.fields}")
        else:
            print(f"API Error: {e.message} (HTTP Status: {e.status_code})")
    except ManyRequestsError:
        print("Too many requests. Please try again later.")
    except TransportError as e:
        print(f"Transport error occurred: {e}")
    except InvalidJSONError as e:
        print(f"Invalid JSON response: {e}")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

if __name__ == "__main__":
    handle_errors()

Examples

For comprehensive examples, including advanced use cases, check out the examples directory

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-1.6.0.tar.gz (11.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-1.6.0-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: chiefpay-1.6.0.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for chiefpay-1.6.0.tar.gz
Algorithm Hash digest
SHA256 61c9f16017a806a66983a9865d83c5973c96a9bcd04cd5e7b24922494ab24506
MD5 36624c2f33ab95a4bd7b09b9b3652a1e
BLAKE2b-256 1264ad50f4ce444772e566e70a13390660064e1f8b4a1862d30838b1a1da361f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: chiefpay-1.6.0-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for chiefpay-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c5449c28586c46b18a068db555449f01849e81cbde4822b1d9becb7359baac1
MD5 942cfa8fdbc1cd83d031d10e2034b2f4
BLAKE2b-256 e05737dbd07bb44fec22de43f616bffec5a54221cfe1f6fe04792714d2211fe7

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