An over-featured API template to provide low-cost, cloud-based backend functionality for Raspberry Pi projects.
Features:
- Docker development and Compose production builds
- Unit testing with Pytest
- Low-user authorization with API keys (manually added)
- Linting and formatting with Black and Flake8
- Payload validation with Pydantic
- Custom error handling
SQLAlchemy database
The development workflow commands are aliased in the Makefile.
-
Install development dependencies
make devel-install
-
Create and populate a
.env
file based on .env.templatecp .env.template .env
The USER_API_KEY is required to access any restricted endpoints in this application. A user API key can be generated with
uuid-gen
and then provided to the Raspberry Pi frontend node(s). Keys to access any external APIs should also be added via.env
. -
Lint and reformat any new code
make format # Reformats all code make format-check # Reports issues but doesn't auto-format
-
Run tests with Pytest
make test
The pytest configuration is specified and can be updated in
tests/pytest.ini
. -
Build and run the API image
make devel-build make devel-run
This kicks off a multi-stage docker build to create a pared down final image running a Gunicorn server.
TODO
docker compose up