FastAPI + PostGIS backend that serves AdaptaBrasil indicator values as GeoJSON, rendered as a choropleth map with MapLibre GL in a static frontend.
- Python 3.12+
- Access to a PostgreSQL/PostGIS database with the
adaptabrasilschema (tablessep,indicator,state,county,geoobject, and thegeovaluematerialized view) - Docker (optional, for containerized runs)
-
Clone the repo and create a virtual environment:
git clone https://github.com/AdaptaBrasil/webtests.git cd webtests python -m venv .venv .venv\Scripts\activate # Windows source .venv/bin/activate # macOS/Linux
-
Install dependencies:
pip install -r requirements.txt
-
Copy
.env.exampleto.envand fill in your database credentials:cp .env.example .env
Variable Description DB_HOSTDatabase host PORTDatabase port DB_NAMEDatabase name DB_USERDatabase user DB_PASSWORDDatabase password DB_SCHEMASchema holding the application tables .envis gitignored — never commit real credentials. -
Run the app:
uvicorn main:app --reload
Open http://127.0.0.1:8000 in a browser.
docker compose up --buildThis builds the image, loads environment variables from .env, and exposes
the app on http://localhost:8000.
| Endpoint | Query params | Description |
|---|---|---|
GET /api/seps |
— | List strategic sectors |
GET /api/indicators |
sep_id |
List indicators for a sector |
GET /api/states |
— | List states |
GET /api/counties |
state_id |
List counties for a state |
GET /api/geovalues |
indicator_id, state_id, county_id (opt.) |
GeoJSON FeatureCollection of indicator values |
For /api/geovalues without county_id (state-wide view), geometry is
simplified server-side (ST_SimplifyPreserveTopology) since state views can
include tens of thousands of sub-county polygons; county-scoped requests are
served at full resolution.
main.py FastAPI app and route definitions
lib/db.py Database queries (SQLAlchemy + pandas)
static/ Frontend (MapLibre GL map, vanilla JS)