Skip to content

Irishery/fastapi-service

 
 

Repository files navigation

Bootstrap env

  • install pyenv first to able to use pyenv install 3.10.1
  • then use pyenv use 3.10.2 and pip install poetry
  • poetry install to init your env
  • poetry run pre-commit install to autoformat your code

Project commands [inside app/bin.py]

  • poetry run test -> runs docker compose containers and then runs tests
  • poetry run server -> runs docker compose and starts dev server with auto reload
  • poetry run recreatemigrations -> recreates initial migration, we can use this when service not deployed
  • poetry run makemigration {description} -> create migration for db
  • poetry run migrate -> upgrades to heads migration

Manage packages

  • use poetry add {name} to add package
  • use poetry add -D {name} to add package only for development

Code styleguide

  • for first level module variables use UPPER_CASE = 1 API etc.
  • all new features should be placed at features module
  • db tables always lower case some_table_name

Helpful urls

TODO:

  • branch management: -> production branch (last production version with tag of latest release) -> auto commit creates a tag (not pushed into prod, only manually from github workflow -> workflow creates pull request into main rebase) -> hotfix/someshing needs to be fixed -> main branch (all stuff goes here) -> (feature or bugfix)/example-button branch from develop branch (service will create feautre-env -> all from develop + service for feature, all other services auto updated) -> could be fast forward
  • add pipeline (python build with deps -> gitlab ci runner + cache)
  • init git branch production

Feature development

  • New features located at app.features module -> to create new feature you can use command poetry run feature <name>
  • This will create new folder with stub API and wired module inside app/init.py
  • Feature structure:
    • __init__.py - includes global instances that could not be initialized by container, like API of FastAPI APIRouter instance
    • models.py - defines pydantic models for endpoints, DB objects and general object validation
    • tables.py - defines DB tables with keys, relations, indexes etc.
    • services.py - defines incapsulated part of reused or isolated part of logic
    • managers.py - defines aggregated flows using services,resources into business logic
    • containers.py - defines construction of all dependencies (services, managers, tables, etc.)
    • api.py - defines endpoints with injected container dependencies

About

Template for FastAPI service

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 97.6%
  • Mako 2.4%