- fastapi-poetry-starter
A project starter for personal usage containing the following:
- Python 3.12.*
- FastAPI web framework
- Structured logging using
structlog
- Dependency management using
poetry
- Containerisation using a Dockerfile
- Testing with
pytest
and optionally with coverage withpytest-cov
- Linting/formatting using
ruff
.gitignore
MacOS (using brew
)
brew install python3 poetry
Ubuntu/Debian
sudo apt install python3 python3-venv pipx
pipx ensurepath
pipx install poetry
From the root of the project execute:
poetry install
From the root of the project execute:
poetry shell
Runs the FastAPI web application on port 8000
using uvicorn:
uvicorn fastapi_poetry_starter.main:app --reload
pytest
pytest --cov=app
pytest --cov-report html --cov=app
ruff check fastapi_poetry_starter/* tests/*
ruff format fastapi_poetry_starter/* tests/*
The following podman
commands are direct replacements of the Docker CLI. You can see that their syntax is identical:
podman image build -t fastapi-poetry-starter .
Run our FastAPI application and map our local port 8000
to 80
on the running container:
podman container run -d --name fastapi-poetry-starter -p 8000:80 --network bridge fastapi-poetry-starter
podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
78586e5b4683 localhost/fastapi-poetry-starter:latest uvicorn main:app ... 13 minutes ago Up 5 minutes ago 0.0.0.0:8000->80/tcp nifty_roentgen
Our FastAPI server now runs on port 8000
on our local machine. We can test it with:
curl -i http://localhost:8000/healthcheck
Output:
HTTP/1.1 200 OK
server: uvicorn
content-length: 0