GithubHelp home page GithubHelp logo

lowolf / flask_template Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cimourdain/flask_template

0.0 0.0 0.0 36 KB

Flask application template with poetry and docker

Python 66.51% Makefile 19.82% Mako 4.29% Dockerfile 9.38%

flask_template's Introduction

Flask application template

Features

  • Poetry dependency manager
  • Pre-build Flask API
  • Docker build & execution
  • database (models in API + factories in tests)
  • lint (black & isort) & style check (black, flake8 & mypy)

Config and init

Update the name of the project folder flask_template:

  • update folder name (and import paths in folder + in tests folder)
  • replace flask-template in network name in network name in docker-compose.yml and docker-compose-no-data.yml
  • value of project name in pyproject.toml

Run project initialization.

$ make init

Run

$ make run

Application is available on http://localhost:5000/

Update dependancies

1 - Update lockfile

$ make shell
app@xxx:~$ poetry add <your_dependency>

2 - Rebuild application (required?)

$ make init

Tests

Run tests with the make command (:bulb: use pytest)

$ make test

Style

Format automatically code (:bulb: use black & isort)

$ make format

Validate automatically code style (:bulb: use flake8 & mypy)

$ make format

Database

Config

Setup your models

In the <flask_template>/models directories setup your models - ๐Ÿ’ก use (and remove) the existing <flask_template>/user.py as an example

Use local database (database from docker-compose service)

Autogenerate migrations with alembic

$ make shell
# auto-generate migrations from your models
app@xxx:~$ poetry run alembic revision --autogenerate -m "first migration" --rev-id=v001
# check the migration file created in `alembic/versions`

# apply migrations to impact database
app@xxx:~$ poetry run alembic upgrade head

Populate database

Use the populate_database method from manage.py file to create your objects (use existing example as a reference).

Then apply the database population by running:

$ make shell
# auto-generate migrations from your models
app@xxx:~$ poetry run python manage.py populate-database

Update tests

  • Update factories in tests/factories to match your models
  • Create your tests

Use remote database

  • update the database SQLALCHEMY_DATABASE_URI in .env
  • comment/remove the database service in docker-compose.yml

TODO

  • marshmallow/pydantic for serialization/deserialization
  • auto openapi generation
  • build
  • hexagonal architecture

flask_template's People

Contributors

cimourdain avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.