A Python library for integrating with ClickPesa payment gateway API
Project description
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.
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 clickpesa-1.0.0.tar.gz.
File metadata
- Download URL: clickpesa-1.0.0.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3f939f97639d8dbd5b404afb844dd746a301f63251b7c29c2b8fe28de657c8d
|
|
| MD5 |
2aa3752ddd763a5f743f43670edb3c06
|
|
| BLAKE2b-256 |
7d455719929485037d6798916d1ed327a3f848d003028394d80210032957ec2e
|
File details
Details for the file clickpesa-1.0.0-py3-none-any.whl.
File metadata
- Download URL: clickpesa-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2949a507f8bdc8a6480a02ed157a0f0eca5b8b79890b5ad188d01de2b6e99ec
|
|
| MD5 |
e9a0ebafed8618fc037170ed3d4b7be3
|
|
| BLAKE2b-256 |
8d91e0d375b3199c9808df1948f50ca8f35958cc81e4e367b18d63079a7d97ac
|