Operational data API for Active Travel England.
- Install Python 3.13
- Install Terraform 1.14
To run the server as a container using a database:
-
Run the services:
docker compose up
-
Invoke the server at http://localhost:8000
To run the server as a container:
-
Build the Docker image:
docker build -t ate-api . -
Run the database image:
docker run --rm -it -e POSTGRES_USER=ate -e POSTGRES_PASSWORD=password -p 5432:5432 postgres:16
-
Run the Docker image:
docker run --rm -it --network=host -e CREATE_DATABASE_SCHEMA=true ate-api
-
Invoke the server at http://localhost:8000
The server can also be run on a different port by specifying the PORT environment variable:
docker run --rm -it --network=host -e CREATE_DATABASE_SCHEMA=true -e PORT=8001 ate-api-
Create a virtual environment:
python3.13 -m venv --prompt . --upgrade-deps .venv -
Activate the virtual environment:
source .venv/bin/activate -
Install the dependencies:
pip install -e .[dev]
-
Run the database image:
docker run --rm -it -e POSTGRES_USER=ate -e POSTGRES_PASSWORD=password -p 5432:5432 postgres:16
Or using Compose:
docker compose up database
-
Run the server:
CREATE_DATABASE_SCHEMA=true make run
-
Invoke the server at http://localhost:8000
To invoke the server running in an environment:
-
Set the target environment, for example:
export ENVIRONMENT=dev -
Request an access token from the identity provider:
cd cloud/identity terraform workspace select ${ENVIRONMENT} ACCESS_TOKEN=$(./request-access-token.sh)
-
Obtain the server details:
cd cloud/service terraform workspace select ${ENVIRONMENT} SERVER_URL=$(terraform output -raw url)
-
Invoke the server with the access token:
curl -H "Authorization: Bearer ${ACCESS_TOKEN}" ${SERVER_URL}/authorities/GMA
The server can be configured with the following environment variables:
| Name | Value |
|---|---|
| DATABASE_URL | Database URL |
| CREATE_DATABASE_SCHEMA | true to create the database schema |
| OIDC_SERVER_METADATA_URL | Authorisation server configuration endpoint |
| RESOURCE_SERVER_IDENTIFIER | Resource server identifier (this must match the audience claim in the JWT access token) |
| DOCS_USERNAME | HTTP Basic Auth username for documentation (unset to disable) |
| DOCS_PASSWORD | HTTP Basic Auth password for documentation |
Environment variables can also be provided in a .env file.
-
Run the formatters:
make format
-
Run the linters:
make lint
Run the tests:
make test