pydaraja
Description
This Python wrapper allows developers to seamlessly interact with the MPESA's Daraja API and manage payment requests within their Python applications.
It streamlines and abstracts the complexity of integrating with the MPESA's Daraja API, providing developers with a convenient and efficient means of handling payment transactions
Daraja API services offered by pydaraja are:
- Lipa na M-PESA online API also known as M-PESA express (STK Push/NI push)
- STK push query API -> Used to check the status of Lipa na Mpesa online payment
More services will come soon.
Installation
pip install -U pydaraja
Usage
- Lipa na Mpesa Online API (STK push) and STK push query API.
from pydaraja import MpesaPaymentGateway
# Create MpesaPaymentGateway instance
mpesa = MpesaPaymentGateway(
api_host="https://sandbox.safaricom.co.ke",
consumer_key="consumer_key",
consumer_secret="consumer_secret",
business_shortcode="business_shortcode",
passkey="passkey"
callback_url="your_callback_url"
account_reference="account_reference" # name of your business
)
# Trigger STK push prompt
response = mpesa.trigger_stk_push(phone_number="+254700000000", amount=1)
print(response.json())
# Output
{
'MerchantRequestID': '2654-4b64-97ff-b827b542881d164797',
'CheckoutRequestID': 'ws_CO_18072024175449513769356298',
'ResponseCode': '0',
'ResponseDescription': 'Success. Request accepted for processing',
'CustomerMessage': 'Success. Request accepted for processing'
}
# use checkout_request_id from the above stk push as parameter for the function below
response = mpesa.query_stk_push(checkout_request_id=your_checkout_request_id)
print(response.json())
# Output
{
'ResponseCode': '0',
'ResponseDescription': 'The service request has been accepted successsfully',
'MerchantRequestID': '2654-4b64-97ff-b827b542881d164797',
'CheckoutRequestID': 'ws_CO_18072024175449513769356298',
'ResultCode': '0',
'ResultDesc': 'The service request is processed successfully.'
}
Daraja API Environments
Sandbox(Test environment) - https://sandbox.safaricom.co.ke
Production(Live environment for real transactions) - https://api.safaricom.co.ke
Contributing
To contribute to this project, we kindly request you to review the CONTRIBUTING.md file for detailed guidelines.
License
This python package is available as open source under the terms of the MIT License
Metadata
Release files for pydaraja 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 | |
|---|---|---|---|---|
| pydaraja-1.0.0.tar.gz | 13.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pydaraja-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.5 kB
Release files / pydaraja-1.0.0.tar.gz
| Download URL | pydaraja-1.0.0.tar.gz |
|---|---|
| Size | 13.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
60e3b8da9f5e68446d4ae3922298e49d54ae534110ac18c29bc1e32d671b5c44
|
|
BLAKE2b-256 checksum How to use checksums |
52253b999218c0cdcf31250162fb7b2f7959b6756420d6a54aaf5e9e78213b4a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Release files / pydaraja-1.0.0-py3-none-any.whl
| Download URL | pydaraja-1.0.0-py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aca584d5574b81a2d37393148ae1b9133b64fa5d38a319c946f65ccaec090696
|
|
BLAKE2b-256 checksum How to use checksums |
8d6d641d42acccc846f370f56eca5703bdd68c6bc7869665517488af32825d04
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Security for pydaraja 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.