Dockerized FastAPI boilerplate for a quick environment setup with some (opinionated) sane defaults.
Build with:
- Docker & Docker Compose (for local development)
- Tortoise-ORM with PostgreSQL
- Migrations by aerich
- User management by FastAPI-users
- Uvicorn
1. Clone the repo
$ git clone [email protected]:villeristi/fastapi-boilerplate.git
2. Create the .env
-file
$ cp .env.example .env
3. Start the containers
$ docker-compose up -d
4. Get to tha choppa container
$ docker exec -it fabp_app
5. Initialize base DB-schema
$ aerich init-db # inside the container
6. Create superuser
$ ./bin/createsuperuser # inside the container
(6.5 Optional: Generate fake data)
$ ./bin/fakedata # inside the container
7. Logging
Default logging is configured in src/util/logger.py
and logs everything to stdout
. To actually see what's going on in your application, just grab the logs from the container using
$ docker logs fabp_app -f
Uvicorn is watching the src
directory by default and reloads application accordingly.
8. Done!
Now everything's set up and one can start building something useful!
- Create migrations after initializing new models / changing existing models
aerich migrate # inside the container
- Apply migrations
aerich upgrade # inside the container
- Fake data
- Sample CRUD-applicaiton (Items)
- Testing
- Production