Skip to content

py-package/flask-boilerplate

Repository files navigation

Flask Boilerplate

A production-grade flask application that you can start your projects without hesitation and without worrying about managing the project structure.

Features

  • Factory Pattern
  • SQLAlchemy ORM
  • Flask-Migrate for database migrations
  • Flask-Seeder for database seed
  • Celery for background jobs
  • Managed Routing using Blueprints
  • Data and Route Caching using Flask-Cache
  • File Storage using Depot
  • Authentication using Flask-Login
  • Email using Flask-Mail

Application Setup

First of all copy .env.example and create new .env file. Set required configurations for mails and databases in .env.

# create virtual environment
python -m venv venv

# activate virtual environment
source venv/bin/activate

# install project dependencies
pip install -r requirements.txt

# migrate database
flask db upgrade

# rollback database migrations
flask db downgrade

# run database seeder, this will setup default admin credentials for our backend
python seed run

Running Application

You can run application using multiple methods:

# using wsgi
python wsgi.py

# gunicorn server
gunicorn -w 4 wsgi:app -t 90 0.0.0.0:5000 --reload

# using sh
./run

ORM

This application uses orator orm. You can find details here. Some basic commands:

# Creating migration
flask db migrate -m "migration_message_here"

# Run migration
flask db upgrade

# Rollback migration
flask db downgrade

Celery

For task queues and heavy background services, Celery is used. Redis has been used as broker.

# Start celery worker

celery -A celery_worker.celery worker --pool=solo --loglevel=info

Contributions

Contributions are welcome! If you have any questions or suggestions, please feel free to open an issue or create a pull request.