Skip to main content

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 methods
  • initiate_ussd_push() - Initiate USSD push payment
  • query_payment_status() - Check single payment status
  • query_all_payments() - Query multiple payments with filters

Convenience Methods

  • get_payment_methods() - Get available payment methods
  • check_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 example
  • complete_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clickpesa-1.0.0.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

clickpesa-1.0.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

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

Hashes for clickpesa-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c3f939f97639d8dbd5b404afb844dd746a301f63251b7c29c2b8fe28de657c8d
MD5 2aa3752ddd763a5f743f43670edb3c06
BLAKE2b-256 7d455719929485037d6798916d1ed327a3f848d003028394d80210032957ec2e

See more details on using hashes here.

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

Hashes for clickpesa-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a2949a507f8bdc8a6480a02ed157a0f0eca5b8b79890b5ad188d01de2b6e99ec
MD5 e9a0ebafed8618fc037170ed3d4b7be3
BLAKE2b-256 8d91e0d375b3199c9808df1948f50ca8f35958cc81e4e367b18d63079a7d97ac

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