Skip to main content

PayHub Python SDK

Official Python client for the PayHub payments API — mobile money & crypto, one API across countries.

  • Zero runtime dependencies — pure standard library (urllib, hmac, json).
  • Typed payments, transfers and balance objects (frozen dataclasses, py.typed).
  • Built-in webhook signature verification.
  • Automatic retries on transient errors (429 / 503 / network).

Requirements

Python 3.9+.

Install

pip install barkapay-payhub

The distribution is barkapay-payhub; you import it as payhub.

Quick start

import payhub

client = payhub.PayHub(
    api_key="pk_live_xxx:sk_live_yyy",  # the "key_id:secret" you copy from the dashboard
    country="bf",                        # default country, overridable per call
)

payment = client.payments.create({
    "operator": "ORANGE",
    "phone_number": "50123456789",
    "amount": 10000,
    "otp": "123456",                     # only for synchronous-OTP operators (e.g. Orange)
    "order": {"id": "ORDER-2026-001"},
})

print(payment.public_id, payment.status)

Authentication: pass the raw key_id:secret (or key_id + secret separately). The SDK adds the Bearer prefix — never include the word Bearer yourself (an accidental one is forgiven).

Payments

client.payments.create({...})                          # -> payhub.Payment
client.payments.get("pay_… or order_id")               # by public_id or your order_id
client.payments.list({"status": "SUCCESSFUL", "per_page": 50})  # -> PaymentList (.items, .meta)
client.payments.confirm_otp(public_id, "123456")       # for AWAITING_OTP payments
client.payments.resend_otp(public_id)

The flow depends on the operator — always branch on the returned status: synchronous (SUCCESSFUL/FAILED), AWAITING_OTP (confirm step), or PROCESSING_OPERATOR (final outcome arrives by webhook).

from payhub import PaymentStatus

if payment.status is PaymentStatus.AWAITING_OTP:
    payment = client.payments.confirm_otp(payment.public_id, otp)

Transfers

client.transfers.create({
    "operator": "ORANGE",
    "phone_number": "50123456789",
    "amount": 50000,
    "order": {"id": "XFER-2026-001"},
})
client.transfers.get(transfer_id)
client.transfers.list({"from_date": "2026-06-01"})     # -> TransferList

Balance & operators

balance = client.balance.get()    # payhub.Balance: available / total / holds / currency
client.operators.info()           # authoritative operator list for the country
client.operators.availability()
client.me()

Webhooks

Verify the PayHub-Signature header against the raw request body:

from payhub import webhook
from payhub import SignatureVerificationError

try:
    event = webhook.parse(
        raw_body,                            # bytes or str — the RAW body
        request.headers["PayHub-Signature"],
        endpoint_secret,                     # whsec_…
    )
except SignatureVerificationError:
    return Response(status=400)

# No `event` field — derive it from event["type"] + event["status"].
# Deduplicate on event["public_id"] (retries deliver the same body).

webhook.verify(...) returns a bool if you prefer not to catch.

Errors

Every API error raises a typed exception extending payhub.ApiError (.code, .http_status, .request_id, .errors):

Exception When
AuthenticationError 401 — bad credentials
AuthorizationError 403/410/451 — not allowed
ValidationError 422 — bad request (.errors)
NotFoundError 404
ConflictError 409 — duplicate
RateLimitError 429
ServiceUnavailableError 503 — retryable
ServerError 5xx
NetworkError request never reached a response

Catch everything from the SDK with payhub.PayHubError.

Configuration

payhub.PayHub(
    api_key="key_id:secret",
    country="bf",
    base_url="https://hub.barkapay.com",
    max_retries=2,        # 429/503/network
    timeout=30.0,         # seconds
    transport=custom,     # any callable matching payhub.Transport (great for tests)
)

License

MIT.

Metadata

Release files for barkapay-payhub 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for barkapay-payhub 1.0.0
File Size Uploaded Provenance
barkapay_payhub-1.0.0.tar.gz 17.6 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for barkapay-payhub 1.0.0
File Interpreter ABI Platform
barkapay_payhub-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 34.4 kB

Release files / barkapay_payhub-1.0.0.tar.gz

Download URL barkapay_payhub-1.0.0.tar.gz
Size 17.6 kB
Tags Source
SHA-256 checksum
How to use checksums
cc78ab8dabd036e70ce8a3ac2f543c7d44840075a19639ff142997789184523e
BLAKE2b-256 checksum
How to use checksums
e164cc5004cf91a4a3e4424a5d4b3e120d2568f2e8a8b5b3efb732f727e2bc47
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 28, 2026.

Transparency log

Release files / barkapay_payhub-1.0.0-py3-none-any.whl

Download URL barkapay_payhub-1.0.0-py3-none-any.whl
Size 16.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6cf52b54ee78c529bbac2dc7541e95db7b50d9674082eea337f2a7b3230ad651
BLAKE2b-256 checksum
How to use checksums
c48b9f01b8756631028dc9e0e60c1ff287df354502b40795b842e8c6f8b92954
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 28, 2026.

Transparency log

Security for barkapay-payhub 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for barkapay_payhub-1.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 28, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page