Skip to main content

Django-Mpesa is a generic python library that interfaces the safaricom MPESA APIs to enable easy payments to your python application.

Detailed documentation is in the “docs” directory.

View the module from the official pypi site

Quick start

  1. Install the package with pip like this:

    pip install django-mpesa
  2. Add “mpesa” to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = [
        ...
        'mpesa',
    ]
  3. Add Mpesa Config variables to your project’s settings.py file

    MPESA_CONFIG = {

    … ‘CONSUMER_KEY’: ‘<Your consumer key from daraja>’, ‘CONSUMER_SECRET’: ‘<Your consumer secret from daraja>’, ‘HOST_NAME’: ‘<Your hostname e.g https://myhostname>’, ‘PASS_KEY’: ‘<Your pass key from daraja>’, ‘SAFARICOM_API’: ‘https://sandbox.safaricom.co.ke’, ‘SHORT_CODE’: ‘174379’

    }

    Check below for full setting variables description

  4. Include the polls URLconf in your project urls.py like this:

    from django.urls import path, include
    from mpesa.urls import mpesa_urls
    
    path('mpesa/', include(mpesa_urls)),
  5. Run python manage.py migrate to create the mpesa models.

  6. Start the development server and visit http://127.0.0.1:8000/admin/

  7. Visit http://127.0.0.1:8000/mpesa/ to checkout the library features.

API ENDPONTS

This module exposes some API endpoints that enable you work with MPESA API

  1. mpesa/submit/

    This endpoint allows you to submit a post request to initiate an STK push

  2. mpesa/confirm/

    This endpoint is used as the callback endpoint on which MPESA will return a transaction response/status

  3. mpesa/check-transaction/

    This endpoint allows you to manually check for the status of an mpesa transaction

Check out the test module for more elaborate examples

Release files for django-mpesa 2.0.14

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-mpesa 2.0.14
File Size Uploaded
django-mpesa-2.0.14.tar.gz 9.0 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for django-mpesa 2.0.14
File Interpreter ABI Platform
django_mpesa-2.0.14-py3.8.egg Legacy Egg format - - Details
django_mpesa-2.0.14-py3-none-any.whl Python 3 none any Details

Total release size:33.7 kB

Release files / django-mpesa-2.0.14.tar.gz

Download URL django-mpesa-2.0.14.tar.gz
Size 9.0 kB
Tags Source
SHA-256 checksum
How to use checksums
aa9f98b113bd744cfdfeabdeef0028f883e14ee287f684d8cb0f3e00ef6fe105
BLAKE2b-256 checksum
How to use checksums
b05121acc07dceb7b74c5444e8a1c28c214970efe68e046d11c2af53025dc165
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/29.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.62.0 importlib-metadata/4.6.3 keyring/23.0.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.8.2

Release files / django_mpesa-2.0.14-py3.8.egg

Download URL django_mpesa-2.0.14-py3.8.egg
Size 11.6 kB
Tags Egg
SHA-256 checksum
How to use checksums
79907f075ffd09453c9a6659791181b8a5b035497b8a77ca81839749524499d6
BLAKE2b-256 checksum
How to use checksums
dd85a07e2af16c9f73f6893c0d961f317893ae87af8f4a9d810239ffd8d20ffb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/29.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.62.0 importlib-metadata/4.6.3 keyring/23.0.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.8.2

Release files / django_mpesa-2.0.14-py3-none-any.whl

Download URL django_mpesa-2.0.14-py3-none-any.whl
Size 13.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d1674f0ab9c37b37843f30543b2c22b6dd037fd510856c6f974c59c86aad7ba0
BLAKE2b-256 checksum
How to use checksums
d68ef3973d61dec9eca020c68bdb1e19d49a4fcb426c173c096cc171838446a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/29.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.62.0 importlib-metadata/4.6.3 keyring/23.0.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.8.2

Release history Release notifications | RSS feed

This release

2.0.14 This release

3 release files

2.0.13

3 release files

2.0.12

3 release files

2.0.10

3 release files

2.0.9

3 release files

2.0.8

2 release files

2.0.7

3 release files

2.0.6

3 release files

2.0.5

3 release files

2.0.3

3 release files

2.0.2

3 release files

2.0.1

3 release files

1.3.4

2 release files

1.3.3

2 release files

1.3.2

2 release files

1.3

2 release files

1.2

2 release files

1.1

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page