ClickPesa Python SDK
A comprehensive Python library for integrating with the ClickPesa payment gateway API. This library provides easy-to-use methods for processing mobile money payments in Tanzania.
Features
- Complete API Coverage: All ClickPesa USSD API endpoints supported
- Type Safety: Full type hints and data models
- Error Handling: Comprehensive exception handling with specific error types
- Token Management: Automatic JWT token generation and refresh
- Easy Integration: Simple, intuitive interface
Project Status:
- Authorization
- Payments:
- USSD
- Card
- Queries
- Payouts:
- Mobile
- Bank
- Queries
- Billpay
- Checkout Link
- Payout Link
- Account:
- Retrieve Account Balance
- Retrieve Account Statement
- Exchange Rates
Installation
pip install clickpesa
Quick Start
from clickpesa import ClickPesaClient, Currency
# Initialize the client
client = ClickPesaClient(
client_id="your_client_id",
api_key="your_api_key"
)
# Preview available payment methods
preview = client.preview_ussd_push(
amount="1000",
currency=Currency.TZS,
order_reference="ORDER123",
phone_number="255712345678"
)
# Initiate payment
transaction = client.initiate_ussd_push(
amount="1000",
currency=Currency.TZS,
order_reference="ORDER123",
phone_number="255712345678"
)
# Check payment status
status = client.query_payment_status("ORDER123")
print(f"Payment status: {status['status']}")
API Methods
Authentication
- Automatic JWT token generation and management
- Token refresh when expired
Payment Operations
preview_ussd_push()- Preview payment and get available methodsinitiate_ussd_push()- Initiate USSD push paymentquery_payment_status()- Check single payment statusquery_all_payments()- Query multiple payments with filters
Convenience Methods
get_payment_methods()- Get available payment methodscheck_payment_completed()- Simple boolean check for payment completion
Error Handling
The library provides specific exception types for different error scenarios:
from clickpesa import (
ClickPesaAuthError, # Authentication errors
ClickPesaValidationError, # Request validation errors
ClickPesaNotFoundError, # Resource not found errors
ClickPesaAPIError # General API errors
)
try:
client.initiate_ussd_push(...)
except ClickPesaValidationError as e:
print(f"Invalid request: {e.message}")
except ClickPesaAuthError as e:
print(f"Authentication failed: {e.message}")
Examples
See the examples/ directory for complete usage examples:
simple.py- Basic usage examplecomplete_flow.py- Full payment processing workflow with monitoring
Requirements
- Python 3.8+
- requests >= 2.25.0
- typing-extensions >= 4.0.0
License
MIT License - see LICENSE file for details.
Metadata
Release files for clickpesa 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| clickpesa-1.0.0.tar.gz | 9.9 kB | Without provenance | Details for clickpesa-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| clickpesa-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for clickpesa-1.0.0-py3-none-any.whl |
Total release size: 17.6 kB
Release files / clickpesa-1.0.0.tar.gz
| Download URL | clickpesa-1.0.0.tar.gz |
|---|---|
| Size | 9.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c3f939f97639d8dbd5b404afb844dd746a301f63251b7c29c2b8fe28de657c8d
|
|
BLAKE2b-256 checksum How to use checksums |
7d455719929485037d6798916d1ed327a3f848d003028394d80210032957ec2e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.2
|
Release files / clickpesa-1.0.0-py3-none-any.whl
| Download URL | clickpesa-1.0.0-py3-none-any.whl |
|---|---|
| Size | 7.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a2949a507f8bdc8a6480a02ed157a0f0eca5b8b79890b5ad188d01de2b6e99ec
|
|
BLAKE2b-256 checksum How to use checksums |
8d91e0d375b3199c9808df1948f50ca8f35958cc81e4e367b18d63079a7d97ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.2
|
Security for clickpesa 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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.