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: chains (open chains, via cowriepay.chains.list()), 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.2.0.tar.gz (11.6 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.2.0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for cowriepay-0.2.0.tar.gz
Algorithm Hash digest
SHA256 32c32a41f0d90aaaa8c79b429b91e9366894b5bad0522d6d22af253da0fb9ade
MD5 36aebe1a69f42dd06b0d6b763bea5b00
BLAKE2b-256 17e166d2df5987e9116a54ac8946067d0189cfbfda2f58dad92e5eba44970048

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cowriepay-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 14.5 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ec5826629871e00c4135ae7b55054e61feca40afbefcf06669cadda0fdfc145a
MD5 35a0313f7d5cdc4e910e9de9697aa17c
BLAKE2b-256 d33ef586d3005d71f9b5137634062cdd3ab4676379c3749666237b8d37242f1a

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