This is a simple fastapi boilerplate with db migration and ORM support.
This section describes tools and configurations needed to make local environment ready to develop and run the application locally.
Following tech stacks are required to get the local env up and running.
This is an installation example for Mac users. Please check out official documentations of those above prerequisites for windows/linux. It's assumed that Homebrew is installed in the machine.
# Install python and it's ecosystem
$ brew install python3
# Install pipenv: a tool for python packaging
$ brew install pipenvInstall Postgres: There are two options for installing postgres.
Option 1: Installing in the machine
- Download from here and install it.
Option 2: Using docker containers
- Make sure
dockeranddocker-composeare installed in the machine. Latest docker package (docker for Mac) comes withdocker-composebundled in it though.
- Rename
env.sample-->.env - Fill out the env variables in the file from a team member.
Choose one of the following options to run the application
-
Option 1: Start the postgres app and create a database called
paymentfrom the UI. Execute following commands from the root of the project.# To create and enable virtual env for the project. $ pipenv shell # Install dependencies $ pipenv install # Make start script executable $ chmod +x start # start the project ./start
-
Option 2: Run a docker container using compose file.
# To start the DB engine in a daemon mode $ docker-compose up -d # To stop the DB engine $ docker-compose down # To stop the DB engine and remove the data volumes: $ docker-compose down -v
Once service is up and running successfully hover over the following url for the API documentation: localhost:9000/docs
Alembic can view the status of the database and compare against the table metadata in the application, generating the obvious migrations based on a comparison.
If new models are added alembic would be able to detect it. Run the following commands to create new migration version using --autogenerate option.
# Tpo autogenerate new version
$ alembic --config migrations/alembic.ini revision --autogenerate -m "<commit_message>"
# upgrade to the latest version
$ alembic --config migrations/alembic.ini upgrade head
TODO:
- Add tests
TODO:
- Add CI/CD configuration
- Document deployment processes.
State the roadmap of the project
I've taken inspirations from these following two repos while making this boilerplate.