Skip to main content

Official CowriePay Python SDK: signed Developer API client + webhook verification.

Project description

cowriepay (Python)

Official CowriePay Python SDK: a signed client for the CowriePay Developer API (/v2) plus webhook signature verification. Server-side only (your cpk_* secret must never reach a browser or mobile app). Zero runtime dependencies (standard library only). Python ≥ 3.9.

Install

pip install cowriepay

Quickstart

import os
from cowriepay import CowriePay

cowriepay = CowriePay(api_key=os.environ["CPK_KEY"], api_secret=os.environ["CPK_SECRET"])
# One base URL for everything: https://api.cowriepay.io
# The key you use selects the network, no host switch:
#   cpk_test_… → Sandbox (testnets: TRON Nile, BSC testnet, ETH Sepolia; fund from faucets)
#   cpk_live_… → Live (mainnets, real funds)
# Same code for both; swap the key to go live. Override the host with base_url=... (e.g. a dev host).

wallet = cowriepay.wallets.create(
    {"chain": "TRON", "asset": "USDT_TRON"},
    idempotency_key="a-uuid",  # makes the POST safe to auto-retry
)

balances = cowriepay.transactions.balances()
deposits = cowriepay.transactions.list_deposits(status="CONFIRMED", limit=20)

Namespaces: wallets, customers, transactions (deposits / withdrawals / balances), withdrawals, fees, webhooks, api_keys, health. For anything not wrapped, cowriepay.request(method, path, body=...) is a signed escape hatch.

CowriePay ships WaaS-first: this SDK is generated from the WaaS-only API view, so it does not include the checkout surface (payment intents / refunds). Those appear automatically when checkout launches.

Errors

from cowriepay import AuthenticationError, NotFoundError, CowriePayError

try:
    cowriepay.wallets.get("does-not-exist")
except NotFoundError:
    ...  # 404 / FEATURE_NOT_AVAILABLE
except AuthenticationError:
    ...  # 401 INVALID_SIGNATURE / TIMESTAMP_EXPIRED / ...
except CowriePayError as err:
    print(err.code, err.status, err.request_id)

Verifying webhooks

Verify against the raw request body. During a secret rotation, pass both the current and previous secrets so no delivery is rejected while you roll the secret.

from cowriepay import verify_webhook

ok = verify_webhook(
    payload=raw_body_bytes,                       # the RAW body (bytes or str)
    signature_header=headers["X-CowriePay-Signature"],
    timestamp=headers["X-CowriePay-Timestamp"],
    secrets=[os.environ["WEBHOOK_SECRET"]],       # add the previous secret during rotation
    tolerance_seconds=300,                        # optional replay guard
)

Development

python -m venv .venv && . .venv/bin/activate
pip install -e ".[dev]"
python -m pytest        # golden vectors + prove-it-fails + client behaviour
python -m mypy          # strict type-check of the hand-written core

License

MIT, Copyright (c) 2026 COWRIEX SAS. See LICENSE.

CowriePay and COWRIEX are trademarks of COWRIEX SAS. This license covers the source code only and grants no right to the COWRIEX or CowriePay names or logos.

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

cowriepay-0.1.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.

cowriepay-0.1.0-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file cowriepay-0.1.0.tar.gz.

File metadata

  • Download URL: cowriepay-0.1.0.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for cowriepay-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d7545b16fff3de2ddef4a05467fec6bbc3b41cc2242de21d88a9cc2f1c223a69
MD5 aeda4cf21bb21e82387ec5868f07b91c
BLAKE2b-256 8674c8cfed915745a1d6c43991d7d8c71c7a3ca9f8133bb020631a71bac49870

See more details on using hashes here.

File details

Details for the file cowriepay-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cowriepay-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for cowriepay-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d9b4996cf4190b67ee3a97cd9634ffba2c2a945b5eaf52b021253ce3d27e9b27
MD5 894594a3ead1a826ba9ed773134a31e4
BLAKE2b-256 c5cf24a25522f2eed5f73e8a664589136be44d3938ad61abf3ade25fe54154fe

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