Skip to content

A dockerized Python/Flask REST example. Contains mypy, pytest, pylint and a few `best practices` :)

Notifications You must be signed in to change notification settings

ilhnctn/flask-rest-example

Repository files navigation

Flask Example Project

This project creates an API to implement and expose a few mathematical algorithms over REST API.

Development Stack

This app is developed on Python 3.8.3 and Flask 1.1.2. It also depends on Redis as well. You can either run the app on docker containers or run from local environments (like pyenv or virtualenv)

Installation Guide

Before cloning the project; cache/database engine (Redis) service must be ready. You can either use docker-compose or install locally to manage these dependencies

After this step, clone the project and navigate into the project root.

Installation On Local Env

➜ git clone git@github.com:ilhnctn/flask-example-app.git
➜ cd flask-example-app && python -m venv venv && source venv/bin/activate
➜ python -m pip install -r requirements/development.txt 

Local Settings & Database Credentials

You must copy the dist env file as below and fill your credentials.

➜ cp envs/dev.env.sample  envs/dev.env

Installation On Docker

➜ git clone git@github.com:ilhnctn/flask-example-app.git && cd flask-example-app
➜ docker-compose up --build 

You can also follow the Makefile to see more instructions about server management.

After either of the steps above, the api will be up and running on http://localhost:8080 (or whatever port supplied in docker-compose) This link contains an up-to-date Postman collection for all api services.

Tests

Test suits depend on pytest and coverage (not mandatory).

Important: Test dependencies are contained in development.txt requirements file, together with development and debug tools. In staging environments, this can be separated as well.

(venv) ➜  flask-example-app git:(develop) ✗ pytest
(venv) ➜ # or to run specific test
(venv) ➜  flask-example-app git:(develop) ✗ pytest apps/fibonacci/tests/test_service.py -k test_fails_when_unsupported_input_sent
(venv) ➜ # If you want to generate code coverage 
(venv) ➜  flask-example-app git:(develop) ✗ coverage run -m pytest

Notes and Missing Topics

  • CI/CD Pipeline And test automation
  • Caching: Add Redis layer on list endpoints
  • Add custom Exception handling and improve logging
  • Tests
    • Service Tests
    • Model Tests
    • View Tests

About

A dockerized Python/Flask REST example. Contains mypy, pytest, pylint and a few `best practices` :)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published