Skip to content

smadasty/flask-boilerplate

 
 

Repository files navigation

Flask Boilerplate

The MIT License

Flask Boilerplate to quickly get started with production grade flask application with some additional packages and configuration prebuilt.

You can find an in-depth article on this implementation here.

Contributing

We encourage you to contribute to Flask Boilerplate! Please check out the Contributing guidelines about how to proceed.

Getting Started

Prerequisites

  • Python 3.9.2 or higher
  • Up and running Redis client

Project setup

# clone the repo
$ git clone https://github.com/idris-rampurawala/flask-boilerplate.git
# move to the project folder
$ cd flask-boilerplate

Creating virtual environment

  • Install pipenv a global python project pip install pipenv
  • Create a virtual environment for this project
# creating pipenv environment for python 3
$ pipenv --three
# activating the pipenv environment
$ pipenv shell
# install all dependencies (include -d for installing dev dependencies)
$ pipenv install -d

# if you have multiple python 3 versions installed then
$ pipenv install -d --python 3.9

Configuration

  • There are 3 configurations development, staging and production in config.py. Default is development
  • Create a .env file from .env.example and set appropriate environment variables before running the project

Running app

  • Run flask app python run.py
  • Logs would be generated under log folder

Running celery workers

  • Run redis locally before running celery worker
  • Celery worker can be started with following command
# run following command in a separate terminal
$ celery -A celery_worker.celery worker -l=info  
# (append `--pool=solo` for windows)

Preconfigured Packages

Includes preconfigured packages to kick start flask app by just setting appropriate configuration.

Package Usage
celery Running background tasks
redis A Python Redis client for caching
flask-cors Configuring CORS
python-dotenv Reads the key-value pair from .env file and adds them to environment variable.
marshmallow A package for creating Schema, serialization, deserialization
webargs A Python library for parsing and validating HTTP request objects

autopep8 & flake8 as dev packages for linting and formatting

Test

Test if this app has been installed correctly and it is working via following curl commands (or use in Postman)

  • Check if the app is running via status API
$ curl --location --request GET 'http://localhost:5000/status'
  • Check if core app API and celery task is working via
$ curl --location --request GET 'http://localhost:5000/api/v1/core/test'
  • Check if authorization is working via (change API Key as per you .env)
$ curl --location --request GET 'http://localhost:5000/api/v1/core/restricted' --header 'x-api-key: 436236939443955C11494D448451F'

License

This program is free software under MIT license. Please see the LICENSE file in our repository for the full text.

About

A Flask Boilerplate to quickly get started with production-grade flask application. It has some additional packages pre-configured for ease of development.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 97.3%
  • Shell 2.7%