Quiz app using FastAPI.
This project uses Poetry for dependency management.
$ curl -sSL https://install.python-poetry.org | python3 - # install Poetry
$ poetry install # install project dependencies using Poetry
Poetry is also used to run different commands to start the server or run tests, which requires installing the Poe the Poet task runner. Poe the Poet is already added as a dependency in the pyproject.toml
file, so it should have been installed with the poetry install
command, but the separate Poetry plugin must also be added.
$ poetry self add 'poethepoet[poetry_plugin]'
At this point, the following commands can be run:
$ poetry poe start # run Uvicorn server
$ poetry poe test # run testcases
$ poetry poe lint # run Ruff linter
$ poetry poe format # format code with Ruff
$ poetry poe precommit # run pre-commit hooks
More arguments can be added to the base commands, for example poetry poe start --reload
.
There are also pre-commit hooks configured to run the Ruff linter and code formatter. To install them, run pre-commit install
.
- Set
USE_SQLITE=true
in the.env
file. - Build the image (
-t
to tag the image).
$ docker build -t fastapi_quiz .
- Run the container (
-d
for detached mode to run the container in the background,-p HOST:CONTAINER
to map the ports).
$ docker run -d -p 8000:8000 --name fastapi_cont fastapi_quiz
- The app can now be accessed from http://0.0.0.0:8000 (docs at http://0.0.0.0:8000/docs).
- Access app logs (
-f
to follow the logs).
$ docker logs fastapi_cont -f
- Stop and remove the containers.
$ docker stop fastapi_cont
$ docker rm fastapi_cont
- Run docker compose (optional
--build
to rebuild the images).
$ docker compose up -d
- The app can now be accessed from http://0.0.0.0:8000 (docs at http://0.0.0.0:8000/docs). The pgAdmin platform can be accessed from http://0.0.0.0:5050, using
email=pgadmin4@pgadmin.org
andpassword=admin
to login (they are defined in thedocker-compose.yml
file). - Access app logs (-f to follow the logs).
$ docker logs fastapi_app -f # FastAPI app logs
$ docker logs postgres_db -f # PostgreSQL logs
- Stop and remove the containers (
-v
to also delete the volume used for PostgreSQL data).
$ docker compose down -v