Cookiecutter Flask OpenAPI is a template for jumpstarting production-ready Flask projects quickly.

Overview

Cookiecutter Flask OpenAPI boilerplate

GitHub issues GitHub stars GitHub license code style: black

πŸ’» A full-featured Flask + API + OAS3 + JWT + SwaggerUI + ORM + Migrations + Great and Scalable structure project template

πŸ‘‰ It's using latest Flask 1.2

Flask 2 is coming soon 😎

It uses PostgreSQL everywhere, so Docker is necessary (SQLite with no Docker dependency is on the roadmap) 😎

Why using this boilerplate ❓

  • Focus on the business and creating value
  • Faster project setup
  • Standard project structure organization (easy to scale)
  • Better QA

What's Included (Features) πŸŽ‰

  • API Design first using OpenAPI & Connexion
  • API documentation using swagger UI
  • Login using JWT
  • Every layer is separated in context/domain
  • Service layer for better tests and reuse
  • Using Flask Factory to integrate with extensions
  • Migrations using Alembic
  • ORM using SQLAlchemy
  • Optimized development and production settings
  • Comes with user model ready to go, signup & signin
  • Procfile for deploying to Heroku
  • Customizable PostgreSQL version
  • Tests using pytest
  • Unit tests for the API layer
  • Unit tests for the service layer

Development

  • Code linter
  • Code formatter (Black+iSort)
  • Using .env file
  • Docker support using docker-compose for development
  • Docker using multistage (Production Ready Dockerfile)
  • Postgres in development (using docker-compose)
  • CI using Github Actions

Structure

This project is organized in:

  • Layers πŸ§… , which might not change in the project life cycle
  • Modules πŸ“¦ , for domain contexts, which might scale in terms of new features
  • Configuration βš™οΈ separated based on the extensions
  • The πŸŽ‚ Business modules
Hackernews-Clone
.
β”œβ”€β”€ hackernews
β”‚   β”œβ”€β”€ app.py                    πŸ‘‰ Entrypoint (create_app)
β”‚   β”œβ”€β”€ exceptions.py
β”‚   β”œβ”€β”€ πŸ§… ext                    πŸ‘‰ Settings
β”‚   β”‚   β”œβ”€β”€ βš™οΈ configuration.py
β”‚   β”‚   β”œβ”€β”€ βš™οΈ api.py
β”‚   β”‚   └── βš™οΈ database.py
β”‚   β”‚   ...
β”‚   β”œβ”€β”€ πŸ§… api                    πŸ‘‰ API Routes
β”‚   β”‚   β”œβ”€β”€ πŸ“¦ auth.py
β”‚   β”‚   β”œβ”€β”€ πŸ“¦ news.py
β”‚   β”‚   └── πŸ“¦ openapi.yaml       πŸ‘‰ API Contract
β”‚   β”‚   ...
β”‚   β”œβ”€β”€ πŸ§… services               πŸ‘‰ Business rules
β”‚   β”‚   β”œβ”€β”€ πŸ“¦ auth.py πŸŽ‚
β”‚   β”‚   β”œβ”€β”€ πŸ“¦ news.py πŸŽ‚
β”‚   β”‚   └── πŸ“¦ token.py πŸŽ‚
β”‚   β”‚   ...
β”‚   └── πŸ§… models                 πŸ‘‰ ORM
β”‚       β”œβ”€β”€ πŸ“¦ news.py
β”‚       └── πŸ“¦ users.py
β”‚       ...
β”œβ”€β”€ βš™οΈ migrations                 πŸ‘‰ Database versions
β”‚   β”œβ”€β”€ alembic.ini
β”‚   β”œβ”€β”€ env.py
β”‚   β”œβ”€β”€ script.py.mako
β”‚   └── versions
β”œβ”€β”€ tests
β”‚   β”œβ”€β”€ conftest.py
β”‚   β”œβ”€β”€ api                      πŸ‘‰ Endpoint tests, input, output and validation 
β”‚   β”œβ”€β”€ database                 πŸ‘‰ Database connection tests
β”‚   └── services                 πŸ‘‰ Business rules tests
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ pytest.ini
β”œβ”€β”€ uwsgi.ini                    πŸ‘‰ Application server settings  
└── wsgi.py                      πŸ‘‰ WSGI Deploy file (Gunicorn/uWSGI)

Requirements

  • Python 3.8 or 3.9 (Help us test in other versions)

  • Docker to run Postgres locally

Contribute πŸš€

Any help is more than welcome...

  • πŸ‘‰ It could be an Issue
  • πŸ’» It could be using it and give a feedback
  • 🌟 It could be a github star
  • πŸ€” It could be a Question
  • πŸ€” If you dislike this project, feel free to tell us what is wrong with it

Get Started (Usage)

Let's pretend you want to create a Flask project called "hackernewsclone". Rather than start from scratch by a app.py and add each library, Flask extesion and various other configurations that always get forgotten until the worst possible moment, get this cookiecutter template do all the work.

First, get Cookiecutter. Trust me, it's awesome::

=1.7.0"">
    $ pip install "cookiecutter>=1.7.0"

Now run it against this repo::

    $ cookiecutter https://github.com/huogerac/cookiecutter-flask-openapi/

You'll be prompted for some values. Provide them...

project_name [Hackernews Clone]: 
project_slug [hackernews_clone]: hackernewsclone
main_model [News]: 
main_model_lower [news]: 
description [The Ultimate Flask Template]: 
author_name [Roger Camargo]: 
email [[email protected]]: 
version [0.1.0]: 
Select python_version:
1 - 3.8.10
2 - 3.9.5
Choose from 1, 2 [1]: 
Select postgresql_version:
1 - 13.3-alpine
2 - 13.5
3 - 14.1
Choose from 1, 2, 3 [1]: 
use_dockerfile [yes]: 
use_github_actions_CI [yes]: 
deploy_to_heroku [yes]: no
keep_vscode_settings [yes]: 
 [INFO]:   - Removing Procfile (Heroku deploy)

 [SUCCESS]: 🐍 Huruuuu, All done! ✨ 🍰 ✨

What's next?
  1) 🐳 Running using docker
     cd hackernewsclone
     docker-compose up --build

  2) 🐍 Running using virtualenv
     cd hackernewsclone
     make virtualenv
     source .venv/bin/activate
     make all

  Then
     access πŸš€ http://localhost:5000/api

 [INFO]: ⚠️ You must have Docker installed, at least to run the postgres database

Articles

Thanks and Inspirations

Owner
Roger Camargo
Programmer
Roger Camargo
The Django Base Site is a Django site that is built using the best Django practices and comes with all the common Django packages that you need to jumpstart your next project.

Django Base Site The Django Base Site is a Django site that is built using the best Django practices and comes with all the common Django packages tha

Brent O'Connor 167 Jan 03, 2023
A python starter package to be used as a template for creating your own python packages.

Python Starter Package This is a basic python starter package to be used as a template for creating your own python packages. Github repo: https://git

Mystic 1 Apr 04, 2022
A command-line utility that creates projects from cookiecutters (project templates), e.g. Python package projects, VueJS projects.

Cookiecutter A command-line utility that creates projects from cookiecutters (project templates), e.g. creating a Python package project from a Python

18.7k Jan 08, 2023
Vue + Django with no compromises. Django Templates and Vue SFCs in harmony without sacrificing the full power of either.

Cookiecutter Vue Django Vue + Django with no compromise. Cookiecutter Vue Django is a framework for jumpstarting production-ready Django + Vue project

Mike Hoolehan 122 Dec 22, 2022
Template for creating PyPI project

template-for-creating-pypi-project Template for creating PyPI project Hello there! This is a template for creating a PyPI project. Fork or clone this

4 Apr 25, 2022
Um template para quem quiser usar o Docker + PGSQL + Django.

Um template para quem quiser usar o Docker + PGSQL + Django.

Drack 2 Mar 11, 2022
Template repository to build PyTorch projects from source on any version of PyTorch/CUDA/cuDNN.

Template repository to build PyTorch projects from source on any version of PyTorch/CUDA/cuDNN.

Joonhyung Lee/μ΄μ€€ν˜• 651 Dec 12, 2022
A template for some new Python tool or package with a reasonable basic setup.

python-app-template A template with a reasonable basic setup, including: black (formatting) flake8 (linting) mypy (type checking) isort (import sortin

Anton Pirogov 3 Jul 19, 2022
Setup a flask project using a single command, right from creating virtual environment to creating Procfile for deployment.

AutoFlask-Setup About AutoFlask-Setup can help you set up a new Flask Project, right from creating virtual environment to creating Procfile for deploy

Ashutosh Krishna 1 Oct 21, 2021
Forkable, Minimal Template for Starknet Projects.

Forkable, Minimal Template for Starknet Projects.

velleity.eth 44 Oct 09, 2022
Flask Boilerplate - Material Kit Design | AppSeed

Flask Boilerplate - Material Kit Design | AppSeed

App Generator 45 Nov 18, 2022
Simple boilerplate ready for development

StartApp Simple boilerplate ready for development Notes Currently supported frameworks are: FastApi, Flask πŸ”¨ Installation $ sudo pip3 install starta

Sabuhi 16 Oct 16, 2022
Boilerplate code for a Python Flask API

MrMat :: Python :: API :: Flask Boilerplate code for a Python Flask API This variant of a Python Flask API is code-first and using native Flask Featur

0 Dec 26, 2021
Python example making use of best practice file structure and multithreading.

Python example making use of best practice file structure and multithreading.

Bob 1 Oct 13, 2021
Starter project for python based lambda project.

Serverless Python Starter Starter project for python based lambda project. Features FastAPI - Frontend dev with Hot Reload API Gateway Integration (+r

4 Feb 22, 2022
A Django project skeleton that is modern and cutting edge.

{% comment "This comment section will be deleted in the generated project" %} Edge A Fantastic Django project starter. Features Ready Bootstrap-themed

Arun Ravindran 827 Dec 15, 2022
Cookiecutter-allpurpose-minimal-python - A simple cookiecutter template for general-purpose python projects.

cookiecutter-allpurpose-minimal-python A simple cookiecutter template for general-purpose python projects. To use, run pip install cookiecutter cookie

E. Tolga Ayan 2 Jan 24, 2022
King is a simple boilerplate from a bigger Discord Bot project created for my Discord Server.

King A simple Discord bot boilerplate. King is a simple boilerplate from a bigger Discord Bot project created for my Discord Server. I intend to showc

Xminent 0 Aug 21, 2021
A framework for launching new Django Rest Framework projects quickly.

DRFx A framework for launching new Django Rest Framework projects quickly. Comes with a custom user model, login/logout/signup, social authentication

William Vincent 400 Dec 29, 2022
A cookiecutter template for python scripts

cookiecutter-py-script A cookiecutter template for python scripts Prerequisites Git Usage pip install cookiecutter

Zeheng Li 1 Dec 14, 2022