Skip to main content

MpesaKit

Open-source Python M-Pesa SDK built by the community, for the community. A reliable third-party library that simplifies M-Pesa integration with comprehensive validation and developer-friendly design.

Open Source99%+ Test Coverage300+ Test CasesCommunity Driven
quick_start.py
import os
from dotenv import load_dotenv
from mpesakit import MpesaClient
from mpesakit.mpesa_express import TransactionType

# load enviroment variables
load_dotenv()

client = MpesaClient(
consumer_key=os.getenv("MPESA_CONSUMER_KEY"),
consumer_secret=os.getenv("MPESA_CONSUMER_SECRET"),
environment="sandbox",
)

# Send STK Push โ€” Coffee Purchase
response = client.stk_push(
business_short_code=int(os.getenv("MPESA_SHORTCODE")),
passkey=os.getenv("MPESA_PASSKEY"),
transaction_type=TransactionType.CUSTOMER_PAYBILL_ONLINE,
amount=250,
party_a=os.getenv("MPESA_PHONE_NUMBER"),
party_b=os.getenv("MPESA_SHORTCODE"),
phone_number=os.getenv("MPESA_PHONE_NUMBER"),
callback_url="https://example.com/callback",
account_reference="NairobiCafe-Order123",
transaction_desc="Coffee โ€” Nairobi Cafe (Order #123)",
)
99%+
Test Coverage
300+
Test Cases
100%
Type Hints
24/7
API Monitoring

Why Choose MpesaKit?

Community-built features designed for real-world M-Pesa integration challenges

๐Ÿ”

Advanced Data Validation

Comprehensive request and response schema validation ensures data integrity before hitting M-Pesa APIs.

  • Pydantic-powered schema validation
  • Phone number format validation
  • Amount range verification
  • Callback URL security checks
๐Ÿ›ก๏ธ

Production Security

Enterprise-grade security features to protect your transactions and sensitive data.

  • IP whitelist for callback endpoints
  • SSL certificate validation
  • Request signing & verification
  • Token refresh automation
๐ŸŽฏ

Developer Experience

Designed for developers who value clean code, type safety, and comprehensive documentation.

  • 100% type hints coverage
  • IntelliSense-friendly APIs
  • Detailed error messages
  • Rich debugging information
โšก

High Customization

Extensively configurable to meet any business requirement with flexible integration options.

  • Custom callback handlers
  • Pluggable authentication
  • Middleware support
  • Flexible configuration
๐Ÿ“Š

Complete API Coverage

Full support for all M-Pesa Daraja APIs with real-time status monitoring.

  • STK Push (Lipa Na M-Pesa)
  • C2B, B2C, B2B transactions
  • Transaction status queries
  • Account balance checks
๐Ÿงช

Battle-Tested Quality

Extensive testing ensures reliability in production environments.

  • 300+ comprehensive test cases
  • 99%+ code coverage
  • Integration test suite
  • Performance benchmarks

Security & Reliability

MpesaKit implements industry best practices to ensure your M-Pesa integrations are secure and reliable in production environments.

๐Ÿ›ก๏ธ

IP Whitelisting

Restrict callback URLs to trusted IP addresses

๐Ÿ”

SSL Validation

Enforce HTTPS and validate certificates

๐Ÿ”‘

Token Management

Secure token storage and automatic refresh

๐Ÿ“

Request Signing

Cryptographic signing of requests for authenticity

Security Layers

Network Security
TLS encryption, IP filtering, HTTPS enforcement
Authentication
OAuth2, token validation, credential management
Data Validation
Schema validation, input sanitization, type checking

API Status Monitor

Real-time status of M-Pesa Daraja APIs and MpesaKit services

Authorization

OAuth token issuance and refresh endpoints operational

Dynamic QR

QR generation and validation working as expected

M-Pesa Express

STK Push / Lipa Na M-Pesa flow operational

Customer To Business (C2B)

C2B payment endpoints accepting requests

Business To Customer (B2C)

B2C payouts processing normally

Transaction Status

Status queries returning timely responses

Account Balance

Account balance checks operational

Reversals

Reversal endpoints functional

Tax Remittance

Tax remittance integration working

Business Pay Bill

PayBill payment flows operational

Business Buy Goods

BuyGoods payment flows operational

Bill Manager

On hold per Safaricom API support

B2B Express Checkout

On hold per Safaricom API support

B2C Account Top Up

Account top-up flows functioning normally

M-Pesa Ratiba

On hold per Safaricom API support

Comprehensive Documentation

Everything you need to get started and scale your M-Pesa integration

๐Ÿ“š

Quick Start Guide

Get up and running in minutes with our step-by-step guide and code examples.

Start Building
๐Ÿ”ง

API Reference

Complete API documentation with parameters, responses, and error codes.

View APIs

Ready to Build?

Join hundreds of developers who trust MpesaKit for their M-Pesa integrations. Start building secure, reliable payment solutions today.

Installation

$ pip install mpesakit