All Projects → tko22 → Flask Boilerplate

tko22 / Flask Boilerplate

Licence: mit
Simple flask boilerplate with Postgres, Docker, and Heroku/Zeit now

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Flask Boilerplate

Flask Base
A simple Flask boilerplate app with SQLAlchemy, Redis, User Authentication, and more.
Stars: ✭ 2,680 (+967.73%)
Mutual labels:  sqlalchemy, database, flask, boilerplate
Architect
A set of tools which enhances ORMs written in Python with more features
Stars: ✭ 320 (+27.49%)
Mutual labels:  sqlalchemy, database, postgres
Fastapi React
🚀 Cookiecutter Template for FastAPI + React Projects. Using PostgreSQL, SQLAlchemy, and Docker
Stars: ✭ 501 (+99.6%)
Mutual labels:  sqlalchemy, postgres, boilerplate
Niklick
Rails Versioned API solution template for hipsters! (Ruby, Ruby on Rails, REST API, GraphQL, Docker, RSpec, Devise, Postgress DB)
Stars: ✭ 39 (-84.46%)
Mutual labels:  database, postgres, boilerplate
Postgres
🐘 Run PostgreSQL in Kubernetes
Stars: ✭ 205 (-18.33%)
Mutual labels:  database, postgres
Migrate
Database migrations. CLI and Golang library.
Stars: ✭ 2,315 (+822.31%)
Mutual labels:  database, postgres
Eve Sqlalchemy
SQLAlchemy data layer for Eve-powered RESTful APIs
Stars: ✭ 215 (-14.34%)
Mutual labels:  sqlalchemy, flask
Clear
Advanced ORM between postgreSQL and Crystal
Stars: ✭ 220 (-12.35%)
Mutual labels:  database, postgres
Graphql Engine Heroku
Blazing fast, instant realtime GraphQL APIs on Postgres with fine grained access control, also trigger webhooks on database events.
Stars: ✭ 188 (-25.1%)
Mutual labels:  heroku, postgres
Stator
Stator, your go-to template for the perfect stack. 😍🙏
Stars: ✭ 217 (-13.55%)
Mutual labels:  postgres, boilerplate
Fluentmigrator
Fluent migrations framework for .NET
Stars: ✭ 2,636 (+950.2%)
Mutual labels:  database, postgres
Rpostgres
A DBI-compliant interface to PostgreSQL
Stars: ✭ 245 (-2.39%)
Mutual labels:  database, postgres
Npgsql
Npgsql is the .NET data provider for PostgreSQL.
Stars: ✭ 2,415 (+862.15%)
Mutual labels:  database, postgres
Create Aio App
The boilerplate for aiohttp. Quick setup for your asynchronous web service.
Stars: ✭ 207 (-17.53%)
Mutual labels:  postgres, boilerplate
Condenser
Condenser is a database subsetting tool
Stars: ✭ 189 (-24.7%)
Mutual labels:  database, postgres
The Flask Mega Tutorial
📖《The Flask Mega-Tutorial》中文2018最新版📗
Stars: ✭ 221 (-11.95%)
Mutual labels:  sqlalchemy, flask
Autoline
建议你使用更新的AutoLink平台
Stars: ✭ 227 (-9.56%)
Mutual labels:  sqlalchemy, flask
Massive Js
A data mapper for Node.js and PostgreSQL.
Stars: ✭ 2,521 (+904.38%)
Mutual labels:  database, postgres
Scenic
Scenic is maintained by Derek Prior, Caleb Hearth, and you, our contributors.
Stars: ✭ 2,856 (+1037.85%)
Mutual labels:  database, postgres
Databases
Async database support for Python. 🗄
Stars: ✭ 2,602 (+936.65%)
Mutual labels:  sqlalchemy, postgres

Flask Boilerplate CircleCI Code style: black

Deploy Deploy to now

This is an minimal but opinionated boilerplate meant for building out simple REST APIs. It is primarily used at Hack4Impact UIUC. This app is written in Python 3.6 with Postgres 10 as the chosen data persistence. The default way to deploy it is with Heroku or Zeit now but you can deploy it with another service, like AWS, Google Cloud, or DigitalOcean with Gunicorn and Nginx, but instructions for that are not provided. Included are simple examples and instructions developing with or without Docker are provided. I've also written a blog post about using Docker based on this repository.

Documentation is located here. We use black for code formatting, and mypy for optional static typing.

Goal

The goal of this boilerplate is to allow developers to quickly write their API with code structured to best practices while giving them flexibility to easily add/change features. Here are the problems this is trying to solve:

  1. Flask is too flexible. With Flask, you can write your application in any structure you like, even in one file. There are also a lot of different tutorials and guides providing different instructions & application structures to set up a Flask app with a database, confusing many newcomers about best practices.

  2. Django and other Flask boilerplates are too heavy. Sometimes, I don't need a fully featured admin portal with Redis and an Email manager nor do I need templates. Many APIs and applications require the use of a database though. Thus, I've chosen Postgres because it is a battle-tested and reliable database used in many companies and we know that 99% of applications can easily be designed to use relational databases (especially the ones used at Hack4Impact).

Docs

Please Please PLEASE read the documentation if you don't understand something relevant to this boilerplate. Documentation is provided in the wiki page of this repository. I've also added comments with links to specific Flask Documentation to explain certain design choices and/or a specific Flask API (ex: test clients).

Usage

Here are some quickstart instructions, although I would look at the documentation for more details and other options of setting up your environment (e.g. full Docker setup, installed postgres instance, pipenv, etc).

First start a postgres docker container and persist the data with a volume flask-app-db:

make start_dev_db

Another option is to create a postgres instance on a cloud service like elephantsql and connect it to this app. Remember to change the postgres url and don't hard code it in!

Then, start your virtual environment

$ pip3 install virtualenv
$ virtualenv venv
$ source venv/bin/activate

Now, install the python dependencies and run the server:

(venv) $ pip install -r requirements.txt
(venv) $ pip install -r requirements-dev.txt
(venv) $ python manage.py recreate_db
(venv) $ python manage.py runserver

To exit the virtual environment:

(venv) $ deactivate
$

For ease of setup, I have hard-coded postgres URLs for development and docker configurations. If you are using a separate postgres instance as mentioned above, do not hardcode the postgres url including the credentials to your code. Instead, create a file called creds.ini in the same directory level as manage.py and write something like this:

[pg_creds]
pg_url = postgresql://testusr:[email protected]:5432/testdb

Note: you will need to call api.core.get_pg_url in the Config file.

For production, you should do something similar with the flask SECRET_KEY.

Easier setup

I've created a makefile to make this entire process easier but purposely provided verbose instructions there to show you what is necessary to start this application. To do so:

$ make setup

If you like to destroy your docker postgres database and start over, run:

$ make recreate_db

This is under the assumption that you have only set up one postgres container that's linked to the flask-app-db volume.

I would highly suggest reading the documentation for more details on setup.

Deployment

You may use Heroku or Zeit Now and the instructions are defined in the wiki page. I would recommend Heroku. The easiest way to do so is to click the Heroku Deploy button. Remember, once you fork/copy this repo, you will need to change app.json, especially the repository key. Everything else should be fine.

Repository Contents

  • api/views/ - Holds files that define your endpoints
  • api/models/ - Holds files that defines your database schema
  • api/__init__.py - What is initially ran when you start your application
  • api/utils.py - utility functions and classes - explained here
  • api/core.py - includes core functionality including error handlers and logger
  • api/wsgi.py - app reference for gunicorn
  • tests/ - Folder holding tests

Others

  • config.py - Provides Configuration for the application. There are two configurations: one for development and one for production using Heroku.
  • manage.py - Command line interface that allows you to perform common functions with a command
  • requirements.txt - A list of python package dependencies the application requires
  • runtime.txt & Procfile - configuration for Heroku
  • Dockerfile - instructions for Docker to build the Flask app
  • docker-compose.yml - config to setup this Flask app and a Database
  • migrations/ - Holds migration files – doesn't exist until you python manage.py db init if you decide to not use docker

MISC

If you're annoyed by the pycache files

find . | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf

Additional Documentation

Feel free to contact me for questions and contributions are welcome :)
[email protected]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].