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.5.0.tar.gz (11.2 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.5.0-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for chiefpay-1.5.0.tar.gz
Algorithm Hash digest
SHA256 340ef423a07058ad712c2e1355db070401c418cff44b314fa8d0765ce8119aef
MD5 70a2e36b3f22abf18ab1b9624dffd33a
BLAKE2b-256 877ad0294575d4413d68b29414a8a7194e6e20d0abfa6dd30361f9e13867d951

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for chiefpay-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 618ec854bf09b249185894bbd3e20558ae4b34c3f8b9a10877be3592215071b7
MD5 a99edc2a14aca479b51dea9c0a18f230
BLAKE2b-256 d24501cc55c8f7e07cb20b5a7e0eb6066b6a215d81456e087433cfacfec83380

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