Git Product home page Git Product logo

fastapi-daraja's Introduction

M-PESA Daraja APIs with FastAPI

FastAPI Middle Office Ware

This is a FastAPI library based on the Safaricom MPESA daraja API.

FastAPI is a modern, fast (high-performance) web framework for building APIs with Python 3.7+ based on standard Python type hints.

For the M-Pesa client, this library uses the python asynchronous client called aiohttp. aiohttp is a versatile asynchronous HTTP client/server framework for Python that supports both client and server-side applications.

MPESA Daraja API documentation can be found at https://developer.safaricom.co.ke

The technology stack used to create the backend of this application is as follows:

  • Framework
    • FastAPI and Starlette
  • ASGI Server
    • Uvicorn and Gunicorn
  • Containerization
    • Docker
  • Database
    • tbc
  • Authentication
    • Bcrypt
    • Passlib
    • JWT Tokens with Pyjwt
  • Testing
    • Pytest
  • Development
    • PyCharm

Configuration

Please create a .env file in the app folder with your configuration:

# M-Pesa Settings:
C2B_CONSUMER_KEY="xxx"
C2B_CONSUMER_SECRET="xxx"
LIPA_NA_MPESA_CONSUMER_KEY="xx"
LIPA_NA_MPESA_CONSUMER_SECRET="xxx"
LIPA_NA_MPESA_PASSKEY="xxx"
C2B_CONFIRMATION_URL=""
C2B_VALIDATION_URL=""
LIPA_NA_MPESA_CALLBACK_URL="xxxx"
LIPA_NA_MPESA_BUSINESS_SHORT_CODE="xxx"

Python/FastAPI Daraja App

Project structure:

├── docker-compose.yml
├── Dockerfile
├── requirements.txt
├── app
    ├── main.py
    ├── __init__.py

docker-compose.yml

version: '3.8'

services:
  api:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: fastapi-daraja
    command: uvicorn app.main:app --reload --workers 1 --host 0.0.0.0 --port 8000
    env_file:
      - .env
    ports:
      - "8000:8000"
    restart: "always"

Deploy with docker compose

docker-compose up -d --build

Expected result

Listing containers must show one container running and the port mapping as below:

$ docker ps
CONTAINER ID   IMAGE          COMMAND       CREATED              STATUS              PORTS                                               NAMES
7087a6e79610   fastapi-daraja   "/start.sh"   About a minute ago   Up About a minute   80/tcp, 0.0.0.0:8000->8000/tcp, :::8000->8000/tcp   fastapi-daraja

After the application starts, navigate to http://localhost:8000 in your web browser and you should see the swagger ui.

fastapi-daraja's People

Contributors

davidmuraya avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

codemarketke

fastapi-daraja's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.