fastapi-backend-template
fastapi-backend-template copied to clipboard
FastAPI minimal backend template based on Copier
fastapi-backend-template
This is a template generator based on Copier to help you quicly create a FastAPI backend project, which includes only the essential/minimal components.
Creating a "hello world" Fastapi application is fairly easy. But for people who want to have a proper web backend setup, there are so many configurations, micro decisions, back-and-forth debugging to just make everything running.
For example, it could easily cost you few hours to setup your ORM SQLAlchemy and schema migration tool Alembic to make it fully work. The goal of this template generator is to save your time from all those boilerplates, then you can focus on implementing the really business logics
There are already some nice full stack Fastapi templates available. Here, I will focus on the essential components which can help you quickly build a Backend application.
What are the essential backend components in this template?
FastAPI: REST APIJWT: authenticationPostgresql: relational databaseSQLAlchemy: ORMAlembic: schema migrationPydantic: data modeling and validationPoetry: dependency managementBlack, Ruff, ...: linting toolspre-commit: git pre commit hooksdotenv, Pydantic-settings: configuration managementDocker: containerizationDocker Compose: orchestration
How to use the template?
Install Copier
Install Copier using pipx.
Note: it is encouraged to use pipx to install your wildly-used CLI library. This way, you can have libraries installed in separate environments but in the meantime use them as a global way. If you don't have pipx, install it by following pipx installing guilde
pipx install copier
or (if you really don't want to use pipx)
pip install copier
Generate a project from the template
Note:
--trustis necessary here to run a post task to create the.envfile for you.
copier copy https://github.com/yanbo-huang/fastapi-backend-template <your local project path> --trust
Answer the questions to customize your project, then you have a battery-included project ready.
That's easy, right? 😄
The template will generate a local README.md file you. Check it and see how to start everything. Have fun with building your awesome project!