This repository serves a Flask API and contains data pipeline scripts that rebuild the SQLite database used by the API.
- Python 3.11
uvinstalled: https://docs.astral.sh/uv/- MIDAS API key in
key.txt(required for data refresh scripts) - Google Cloud SDK (
gcloud) for deployment
From the repo root:
uv syncRun the API locally:
echo "user=DEV" > .env
uv run flask --app app --debug runRun tests:
uv run pytest -vRun all commands from the repo root unless noted.
- Ensure
key.txtexists and contains a valid MIDAS API key. - Ensure
.envpoints to local config:
echo "user=DEV" > .env- Pull latest upstream JSON data:
uv run python data_updates/update_midas_data.py- Rebuild the SQLite database (
midasDBby default viaconfig.ini):
uv run python data_updates/update_database.py- Optional validation: start API and hit an endpoint.
uv run flask --app app --debug runNotes:
config.inicontrols database path by environment section (DEVandSERVER).- The app reads
.envvariableuserto select the section inconfig.ini.
Build image:
docker build -t midas-api:local .Run locally:
docker run --rm -p 8080:8080 midas-api:localThis deployment path uses Artifact Registry + Cloud Run.
Set variables (edit values):
export PROJECT_ID="your-gcp-project-id"
export REGION="us-central1"
export REPO_NAME="midas-api"
export SERVICE_NAME="midas-api"Authenticate and configure project:
gcloud auth login
gcloud config set project "$PROJECT_ID"
gcloud services enable run.googleapis.com artifactregistry.googleapis.com cloudbuild.googleapis.comCreate Artifact Registry repository (one-time):
gcloud artifacts repositories create "$REPO_NAME" \
--repository-format=docker \
--location="$REGION" \
--description="MIDAS API container images"Build and push image with Cloud Build:
gcloud builds submit \
--tag "$REGION-docker.pkg.dev/$PROJECT_ID/$REPO_NAME/midas-api:latest"Deploy to Cloud Run:
gcloud run deploy "$SERVICE_NAME" \
--image "$REGION-docker.pkg.dev/$PROJECT_ID/$REPO_NAME/midas-api:latest" \
--region "$REGION" \
--platform managed \
--allow-unauthenticatedSet runtime environment selector so app uses server config:
gcloud run services update "$SERVICE_NAME" \
--region "$REGION" \
--update-env-vars user=SERVERmidasDBmust be present in the container filesystem at runtime for query endpoints to work.- If you rebuild
midasDB, rebuild and redeploy the image so Cloud Run gets the updated database file. - For larger or frequently updated datasets, consider moving database storage off-image (for example Cloud SQL or mounted volume patterns) and update
config.iniaccordingly.
# install/update deps
uv sync
# local api
uv run flask --app app --debug run
# tests
uv run pytest -v
# data refresh
uv run python data_updates/update_midas_data.py
uv run python data_updates/update_database.py