Skip to content

Latest commit

 

History

History
97 lines (75 loc) · 3.59 KB

README.md

File metadata and controls

97 lines (75 loc) · 3.59 KB

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.11.3 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

If you want to install redis via docker

$ docker run -d --name="flask-boilerplate-redis" -p 6379:6379 redis

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.11

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 --loglevel='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.