Skip to content

a-wakeel/flask-bp

Repository files navigation

codecov Build Status flask-bp

header

flask-bp

flask-bp is a comprehensive flask boilerplate for prototyping. It includes most common aspects of the projects such as Database migrations, resourceful routing, unit-testing and many more.

Features

1. Swagger API docs

Swagger docs are supported for API. flask-apispec has been used to automatically generate swagger docs for APIs. Swagger Docs

Swagger docs can be accessed at:

localhost:5000/apidocs
localhost:5000/apidocs-json

2. Automated Testing

Automated unit testing base is configured using pytest with automatic coverage report. Pytest

Tests can be engaged using:

make test

3. Automated Code Linter

Automated code linting is supported using Pylint Pylint

Linter can be engaged using:

make lint

Setup

A virtual environment should be used, e.g

virtualenv flaskbp-env

Activate the virtual environment and install the requirements:

source flaskbp-env/bin/activate
pip install -r requirements.txt

Run the flask-bp:

make start-dev
OR
flask run -h 0.0.0.0

Setup Using Docker

Make sure you have installed docker and docker-compose.

  • Create a flaskbp user with UID 9001 and change the ownership of the repo:
    sudo useradd -u 9001 -m -d /home/flaskbp -s /bin/bash flaskbp
    sudo chown -R 9001:9001 flask-bp
  • Build Postgres Image using:
    make -f docker/postgres/Makefile
  • Build the dev server image using:
    make -f docker/dev/Makefile
  • After the build process completes, launch dev environment using:
    docker-compose -f docker/dev/devenv-with-local-db.yml run --rm --service-ports dev-shell

Accessing flask-bp resources

To access the api server, you can access it on:

http://localhost:5000/api/v1/

There is one route defined which accepts a user information and return it back, it can be accessed:

http://localhost:5000/api/v1/user

It supports GET & POST method, GET for getting the user information from the database and POST to insert new user information to the database.

To access the auto generated swagger documentations:

http://localhost:5000/apidocs/

To export swagger docs in json format:

http://localhost:5000/apidocs-json/

Database Migrations

To initialize database migrations

make install-db

To upgrade database schema

make upgrade-db

Others

To clean project

   make clean

To clean .pyc files

make clean-pyc

To run the tests

make test

Open Source Resources Used

  1. Python
  2. Flask
  3. Flask-Restful
  4. Flask-cors
  5. Marshmallow Python
  6. Flask SQLAlchemy
  7. PyYAML
  8. Flask Script
  9. Flask Migrate
  10. apispec
  11. flask-apispec
  12. testing.postgresql

About

Flask boilerplate

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published