Core Delivery Platform Python Backend Template.
This is work-in-progress. See To Do List
Please install python >= 3.12 and configure your python virtual environment:
# create the virtual environment
python -m venv .venv
# activate the the virtual environment in the command line
source .venv/bin/activate
# update pip
python -m pip install --upgrade pip
# install the dependencies
pip install -r requirements-dev.txtThis opinionated template uses the Fast API Python API framework.
This and all other runtime python libraries must reside in requirements.txt
Other non-runtime dependencies used for dev & test must reside in requirements-dev.txt
This repository uses Docker throughput its lifecycle i.e. both for local development and the environments. A benefit of this is that environment variables & secrets are managed consistently throughout the lifecycle
See the Dockerfile and compose.yml for details
Libraries: Ensure the python virtual environment is configured and libraries are installed using requirements-dev.txt, as above
Environment variables: compose/aws.env
Secrets: compose/secrets.env. You need to create this, as it's excluded from version control.
The app can be run locally using Docker compose. This template contains a local environment with:
- Localstack
- MongoDB
- This service
To run the application in development mode:
docker compose watchEnsure the python virtual environment is configured and libraries are installed using requirements-dev.txt, as above
Testing follows the FastApi documented approach; using pytest & starlette.
To test the application run:
pytestTo mimic the application running in `production mode locally run:
docker compose up --build -dStop the application with
docker compose down| Endpoint | Description |
|---|---|
GET: /docs |
Automatic API Swagger docs |
GET: /example |
Simple example |
Uses the aws embedded metrics library. An example can be found in metrics.py
In order to make this library work in the environments, the environment variable AWS_EMF_ENVIRONMENT=local is set in the app config. This tells the library to use the local cloudwatch agent that has been configured in CDP, and uses the environment variables set up in CDP AWS_EMF_AGENT_ENDPOINT, AWS_EMF_LOG_GROUP_NAME, AWS_EMF_LOG_STREAM_NAME, AWS_EMF_NAMESPACE, AWS_EMF_SERVICE_NAME
We have added an example dependabot configuration file to the repository. You can enable it by renaming
the .github/example.dependabot.yml to .github/dependabot.yml
Instructions for setting up SonarCloud can be found in sonar-project.properties
THIS INFORMATION IS LICENSED UNDER THE CONDITIONS OF THE OPEN GOVERNMENT LICENCE found at:
http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3
The following attribution statement MUST be cited in your products and applications when using this information.
Contains public sector information licensed under the Open Government license v3
The Open Government Licence (OGL) was developed by the Controller of Her Majesty's Stationery Office (HMSO) to enable information providers in the public sector to license the use and re-use of their information under a common open licence.
It is designed to encourage use and re-use of information freely and flexibly, with only a few conditions.