Skip to content

Python based backend server using FASTAPI framework

Notifications You must be signed in to change notification settings

CurrantScantist/Backend

Repository files navigation

Backend Service

build version

Introduction

The Backend service is being used to establish communication with database.

Python Framework

FASTAPI framework is a modern, fast, robust, easy scalable web framework for building APIs with Python 3.6+. The key features:

  • Fast: One of the fastest Python open source framework link
  • Easy Scalable and Maintainable
  • Easy Learning: Designed to be easy to use and learn. Less time reading docs.
  • Robust: Get production-ready code. With automatic interactive documentation. and many more..

Please follow official documentation for further information.

Module Structure

image

Current services module structure

image

Getting Up and Running

First time setup

1.Ensure that you have a virtual environment setup for **python3.6+**, and it is activated.
If not, please setup a new virtual environment for python3.6+

2. Ensure that .env file exists in Backend root directory.
If not, please checkout configuration section.

3. Ensure that you are in root directory of ```Backend```  

4. pip install -r requirements.txt  
5. python main.py  

Normal Execution

Activate your python3.6+ virtual environment.
python main.py

API Doc

  1. Normal Excecution
  2. visit http://127.0.0.1:3333/docs

Normal Test Execution

  • Ensure that you have a virtual environment setup for python3.6+, and it is activated.
  • Ensure that you are in root directory of Backend
 pytest test/[file name that ends with test.py]

Generating coverage report

coverage run -m pytest -v test && coverage report -m

APIs

This project has several APIs:

  • The API Serves the communication with database and any device.
  • The GET request has been used predominately in the API endpoints.

Endpoints

image

Unit / Automated Tests

  • Github Action is being used to automated Tests.
  • Unit tests for APIs have been standardised for the GET request.
  • Test File Structure
|..  
    ├── test                  
          |── [xyz] _ test.py                
|..   
  • Adding new test file
    • By convention and setup, the new test should go into test file

Error Handling

Configuration

Database connection

MONGODB is being used as a database platform for NoSQL database.
Contact exisitng Developers/maintainers to get either admin access or developer access for MONGODB.

  1. Create .env file in the root directory
  2. Add following variables with your access details
PASSWORD={.............}
NAME={.........}

Server Configuration

DOCKER

DOCKER file configuration to run on server

# syntax=docker/dockerfile:1

FROM python:3.7

WORKDIR /app

COPY requirements.txt requirements.txt

RUN pip3 install -r requirements.txt

EXPOSE 3333

COPY . .

CMD ["uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "3333"]

Note: Configuration might not be updated. Therefore, please confirm with DOCKER file from the repository only.

Staging

The main branch continuous deploy on the heorku as staging environment.
staging environment
Please contact current developers for further configuration of heroku environment,

Production

Currently, production server has been deployed on the Scantist local machine.

Feedback

All bugs, feature requests, pull requests, feedback, etc., are welcome. Create an issue.

Next Step

  • API limiter
  • Minimise additional dependencies
  • Area of improvement regarding API's performance

About

Python based backend server using FASTAPI framework

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •