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.4.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.4.0-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: chiefpay-1.4.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.4.0.tar.gz
Algorithm Hash digest
SHA256 cb7182288f3b6757bc58808e0607cc255dae436f96ac144d810089351491da56
MD5 3866e10ff7f5990afedb4f74184c1aa2
BLAKE2b-256 7d186dee3e61b438bdba9b77928e40c5340f6237f2ff0bbd15b48fa55c263ab9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: chiefpay-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 16.7 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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c7baff60097f6eadb436a5762f82d06d89e795711f3033fb3199d3a7d672dc04
MD5 7bb3ceaea7704104562cbc16e88e74a1
BLAKE2b-256 eebf04e358d2a8826625aefa3f236668f16b01d305c3ab7692e15646f7d9a35c

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