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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for chiefpay-1.3.0.tar.gz
Algorithm Hash digest
SHA256 9e83961c72eb9536773de234a85b838f5c408aafd7f46488ccd4f76b34b9cf03
MD5 dcd2de83982f2189e8236025a4cca150
BLAKE2b-256 e01faaeae4857762af1ab59c07f4e97f7cf6b94fc797fe1681792c5d8164d678

See more details on using hashes here.

File details

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

File metadata

  • Download URL: chiefpay-1.3.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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 471c3653ca76f7174e10bb2fb1f6a13a1c59120a64b216b53edc592028282353
MD5 870fc4f5cf9a551b3cb64cc8d156e5ec
BLAKE2b-256 f15d0f052b54368de5642855baf8ef50fbed9b6bb655af92714df49b1b9f345e

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