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.
We encourage you to contribute to Flask Boilerplate! Please check out the Contributing guidelines about how to proceed.
- Python 3.11.3 or higher
- Up and running Redis client
# clone the repo
$ git clone https://github.com/idris-rampurawala/flask-boilerplate.git
# move to the project folder
$ cd flask-boilerplate
If you want to install redis via docker
$ docker run -d --name="flask-boilerplate-redis" -p 6379:6379 redis
- Install
pipenv
a global python projectpip 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.11
- There are 3 configurations
development
,staging
andproduction
inconfig.py
. Default isdevelopment
- Create a
.env
file from.env.example
and set appropriate environment variables before running the project
- Run flask app
python run.py
- Logs would be generated under
log
folder
- 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 --loglevel='INFO'
# (append `--pool=solo` for windows)
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 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'
This program is free software under MIT license. Please see the LICENSE file in our repository for the full text.