Official Python client for the PayHub payments API — mobile money & crypto, one API across countries. Import as `payhub`.
Project description
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(orkey_id+secretseparately). The SDK adds theBearerprefix — never include the wordBeareryourself (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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file barkapay_payhub-1.0.0.tar.gz.
File metadata
- Download URL: barkapay_payhub-1.0.0.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc78ab8dabd036e70ce8a3ac2f543c7d44840075a19639ff142997789184523e
|
|
| MD5 |
42353b7747d4813da59b34b36d7e5dc1
|
|
| BLAKE2b-256 |
e164cc5004cf91a4a3e4424a5d4b3e120d2568f2e8a8b5b3efb732f727e2bc47
|
Provenance
The following attestation bundles were made for barkapay_payhub-1.0.0.tar.gz:
Publisher:
release.yml on BarkaPay/payhub-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
barkapay_payhub-1.0.0.tar.gz -
Subject digest:
cc78ab8dabd036e70ce8a3ac2f543c7d44840075a19639ff142997789184523e - Sigstore transparency entry: 1989066856
- Sigstore integration time:
-
Permalink:
BarkaPay/payhub-python@71048d2f55e580fa550ac05006bcee34e4c0fdc2 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/BarkaPay
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@71048d2f55e580fa550ac05006bcee34e4c0fdc2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file barkapay_payhub-1.0.0-py3-none-any.whl.
File metadata
- Download URL: barkapay_payhub-1.0.0-py3-none-any.whl
- Upload date:
- Size: 16.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6cf52b54ee78c529bbac2dc7541e95db7b50d9674082eea337f2a7b3230ad651
|
|
| MD5 |
b1d25f61b3619828b1b70b1de549aa1e
|
|
| BLAKE2b-256 |
c48b9f01b8756631028dc9e0e60c1ff287df354502b40795b842e8c6f8b92954
|
Provenance
The following attestation bundles were made for barkapay_payhub-1.0.0-py3-none-any.whl:
Publisher:
release.yml on BarkaPay/payhub-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
barkapay_payhub-1.0.0-py3-none-any.whl -
Subject digest:
6cf52b54ee78c529bbac2dc7541e95db7b50d9674082eea337f2a7b3230ad651 - Sigstore transparency entry: 1989066964
- Sigstore integration time:
-
Permalink:
BarkaPay/payhub-python@71048d2f55e580fa550ac05006bcee34e4c0fdc2 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/BarkaPay
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@71048d2f55e580fa550ac05006bcee34e4c0fdc2 -
Trigger Event:
push
-
Statement type: