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

You might also like...
Template for creating ds simple projects

ds-project-template Template for creating ds simple projects Requirements pyenv python==3.9.4 Setup For this purpose you use following commands: pytho

A low dependency and really simple to start project template for Python Projects.
A low dependency and really simple to start project template for Python Projects.

Python Project Template A low dependency and really simple to start project template for Python Projects. HOW TO USE THIS TEMPLATE DO NOT FORK this is

Forkable, Minimal Template for Starknet Projects.

Forkable, Minimal Template for Starknet Projects.

Basic Docker Compose template application with Flask, Celery, Redis, MySQL, SocketIO, Nginx and Gunicorn.

Nginx / Gunicorn / Flask 🐍 / Celery / SocketIO / MySQL / Redis / Docker 🐳 sample application Basic Docker Compose template application for orchestat

Get a Django app up and running in dev, test, and production with best practices in 10 minutes

Django template for Docker + Heroku This is how I set up Django projects to get up and running as quick as possible. In includes a few neat things: De

A test Django application with production-level docker setup

DockerApp A test Django application with production-level docker setup. Blog: https://medium.com/@siddharth.sahu/the-near-perfect-dockerfile-for-djang

A boilerplate Django project for quickly getting started.
A boilerplate Django project for quickly getting started.

The Definitive Django Learning Platform. Django Project Boilerplate This repository is a boilerplate Django project for quickly getting started. Getti

Bleeding edge django template focused on code quality and security.

wemake-django-template Bleeding edge django2.2 template focused on code quality and security. Purpose This project is used to scaffold a django projec

Project template layout for Django 3.0+

Django 3.0+ project template This is a simple Django 3.0+ project template with my preferred setup. Most Django project templates make way too many as

Comments
  • Add item: running on Windows

    Add item: running on Windows

    #Do you use Windows 10 Operating System?

    ##Follow these steps to run this application:

    Type in your browser, the following address:

    https://docs.docker.com/desktop/windows/install

    In system requirements look for how to enable WSL 2, details and instructions in:

    https://docs.microsoft.com/en-us/windows/wsl/install

    In Microsoft documentation, session install, copy and paste the following command, in Power Shell:

    wsl --install

    At the end, restart Windows to enable WSL (Windows Subsystem for Linux) and install Ubuntu. When finished, a Linux terminal will be active on your screen

    Back to the Docker documentation page, look for the "Docker Desktop for Windows" button and double-click

    Restart Windows again and presto, Windows Docker is installed. Opening Docker Desktop, follow the four-step instructions to activate the "container"

    Create a folder on your computer and activate a virtual environment

    Now, follow the instructions contained in the Get Started (Usage) Section of the project's README.md

    enhancement 
    opened by GetulioCastro 0
  • Make works on windows

    Make works on windows

    Description

    Run the command cookiecutter repo URL Answer the questions Run the extra commands

    Make sure it is working on windows

    Didn't work? Create a bug with the errors and details...

    enhancement 
    opened by huogerac 4
Owner
Roger Camargo
Programmer
Roger Camargo
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
Mad-cookiecutter - Cookiecutter templates for MaD projects

MaD Cookiecutter Templates A set of templates that can be used to quickly get st

Machine Learning and Data Analytics Lab FAU 1 Jan 10, 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
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

null 18.7k Jan 8, 2023
Combine the power of FastAPI and Django to build a production-ready application capable of utilizing all of the best features of both worlds.

FastAPI and Django Combo This projects aims to combine FastAPI and Django to build a Production ready application capable of utilizing all of the feat

Nsikak Imoh 33 Dec 27, 2022
Template to quickly start your playwright-python project

Playwright-python template ?? Template to quickly start your playwright-python project Getting started β€’ Demo β€’ Configuration Getting started Clone th

Constantin 1 Dec 13, 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
Cookiecutter to create a Google Function. Powered by Poetry, GitHub actions, and Google Cloud Platform

Cookiecutter Google Function Cookiecutter template for a Google Function. Powered by Poetry, and GitHub actions. Quickstart Install the latest Cookiec

Arthur 1 Jan 7, 2022
A simple cookiecutter to create Python Telegram bots, wrapped with Django.

PTB Django cookiecutter A simple cookiecutter to create Python Telegram bots, wrapped with Django. Based on this cool projects python-telegram-bot (PT

Carlos Lugones 20 Nov 12, 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