A lightweight, modular FastAPI application with Swagger UI, Docker support, Keycloak authentication, and Gunicorn + Uvicorn for production.
Giswater API exposes a clean HTTP surface to query and operate a Giswater database. It wraps existing GIS and network operations behind FastAPI endpoints, so desktop tools, mobile apps, and integrations can run the same workflows without directly touching the database.
How it works
Why it is useful
How to use it
/api/v1 (Swagger docs at /api/v1/docs)..env (API_* toggles).This service is versioned alongside the Giswater database. Use matching ranges to avoid subtle schema/API mismatches.
giswater-api version | Supported Giswater DB versions |
|---|---|
| 0.1 ā 0.7 | 4.0 ā 4.7 |
| 0.8 | 4.8+ |
git clone https://github.com/Giswater/giswater-api.git
cd giswater-api
python3 -m venv venv
source venv/bin/activate # for Windows PowerShell: .\venv\Scripts\activate
pip install -e ".[dev]"
uvicorn app.main:app --reload
š API Docs available at: http://127.0.0.1:8000/api/v1/docsā
Copy the env template and customize:
cp .env.example .env
API toggles (enable/disable modules):
API_BASIC=true
API_PROFILE=true
API_MINCUT=true
API_MAPZONES=true
API_ROUTING=true
API_CRM=true
Database:
DB_HOST=localhost
DB_PORT=5432
DB_NAME=giswater_db
DB_USER=postgres
DB_PASSWORD=postgres
DB_SCHEMA=ws
# DATABASE_URL=postgresql://user:pass@host:5432/dbname
Keycloak (optional):
KEYCLOAK_ENABLED=false
KEYCLOAK_URL=https://keycloak.example.com
KEYCLOAK_REALM=your-realm
KEYCLOAK_CLIENT_ID=giswater-api
KEYCLOAK_CLIENT_SECRET=your-secret
KEYCLOAK_ADMIN_CLIENT_SECRET=your-admin-secret
KEYCLOAK_CALLBACK_URI=http://localhost:8000/callback
Keycloak integration is optional. When enabled:
get_current_user() dependencyWhen disabled, endpoints are public and return an anonymous user context.
Custom plugins can extend the API. Place plugin folders in plugins/:
plugins/
āāā my-plugin/
āāā ...
Plugins are auto-loaded at startup. See example pluginā .
docker build -t giswater-api .
docker run -d -p 8000:8000 giswater-api
docker run -d -p 8000:8000 \
--env-file .env \
-v /var/log/giswater-api:/app/logs \
giswater-api
Set the variables listed in the Configuration section (or via --env-file).
For production, run:
gunicorn -w 4 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8000 app.main:app
| Endpoint | Method | Description |
|---|---|---|
/ | GET | Root endpoint (version info) |
/health | GET | Health check (DB connection status) |
| Endpoint | Method | Description |
|---|---|---|
/basic/getfeaturechanges | GET | Fetch GIS features modified since specified date |
/basic/getinfofromcoordinates | GET | Fetch GIS features info from coordinates |
/basic/getfeaturesfrompolygon | GET | Fetch GIS features inside a polygon |
/basic/getselectors | GET | Fetch current selectors |
/basic/getsearch | GET | Search features |
/basic/getarcauditvalues | GET | Fetch arc audit values |
/basic/getlist | GET | Generic list query with paging and filters |
| Endpoint | Method | Description |
|---|---|---|
/crm/hydrometers | POST | Insert hydrometers (single or bulk) |
/crm/hydrometers/{code} | PATCH | Update single hydrometer by code |
/crm/hydrometers | PATCH | Update multiple hydrometers in bulk |
/crm/hydrometers/{code} | DELETE | Delete single hydrometer by code |
/crm/hydrometers | DELETE | Delete multiple hydrometers in bulk |
/crm/hydrometers | PUT | Replace all hydrometers (full sync mode) |
| Endpoint | Method | Description |
|---|---|---|
/om/mincuts | GET | List mincuts |
/om/mincuts/{mincut_id} | GET | Get mincut dialog data |
/om/mincuts | POST | Create a new mincut |
/om/mincuts/{mincut_id} | PATCH | Update an existing mincut |
/om/mincuts/{mincut_id} | DELETE | Delete a mincut |
/om/mincuts/{mincut_id}/valves | GET | List valves associated to a mincut |
/om/mincuts/{mincut_id}/valves/{valve_id}/toggle-unaccess | POST | Toggle valve unaccess status and recalculate mincut |
/om/mincuts/{mincut_id}/valves/{valve_id}/toggle-status | POST | Update valve status in a mincut |
/om/mincuts/{mincut_id}/start | POST | Start mincut and interrupt supply |
/om/mincuts/{mincut_id}/end | POST | End mincut and restore supply |
/om/mincuts/{mincut_id}/cancel | POST | Cancel mincut and keep issue recorded |
| Endpoint | Method | Description |
|---|---|---|
/om/profiles | POST | Create a new profile |
| Endpoint | Method | Description |
|---|---|---|
/om/flow | POST | Calculate upstream/downstream flow trace |
| Endpoint | Method | Description |
|---|---|---|
/om/dmas | GET | Returns collection of DMAs |
/om/macrodmas | GET | Returns collection of macro DMAs |
/om/dmas/{dma_id}/hydrometers | GET | Retrieve DMA hydrometers data with location, status, and measurements |
/om/dmas/{dma_id}/parameters | GET | Retrieves DMA parameters for performance analysis |
/om/dmas/{dma_id}/flowmeters | GET | Retrieve DMA flowmeters data with location, status, and flow |
/om/dmas/{dma_id}/connecs | GET | Retrieve DMA connecs data from ve_connec |
| Endpoint | Method | Description |
|---|---|---|
/om/macrosectors | GET | Returns collection of macrosectors |
/om/sectors | GET | Returns collection of sectors |
/om/presszones | GET | Returns collection of presszones |
/om/macrodqas | GET | Returns collection of macro DQAs |
/om/dqas | GET | Returns collection of DQAs |
/om/macroomzones | GET | Returns collection of macro OM zones |
/om/omzones | GET | Returns collection of OM zones |
/om/omunits | GET | Returns collection of OM units |
| Endpoint | Method | Description |
|---|---|---|
/routing/getobjectoptimalpathorder | GET | Get optimal path through network points using Valhalla routing engine |
/routing/getobjectparameterorder | GET | Get features ordered by parameter |
giswater-api/
āāā app/
ā āāā .env.example # Environment variable template
ā ā
ā āāā models/ # Pydantic models (organized by module)
ā ā āāā basic/ # Basic module models
ā ā āāā crm/ # CRM module models
ā ā āāā om/ # OM (mincut, dma, mapzones) models
ā ā āāā routing/ # Routing module models
ā ā āāā util_models.py # Shared utility models
ā ā
ā āāā routers/ # API endpoints (organized by module)
ā ā āāā basic/ # GIS feature queries
ā ā āāā crm/ # Hydrometer CRUD
ā ā āāā om/ # OM operations (mincut, profile, flow, dma, mapzones)
ā ā āāā routing/ # Optimal path routing
ā ā
ā āāā utils/ # Utilities and helpers
ā ā āāā utils.py # General utilities
ā ā āāā routing_utils.py # Valhalla routing helpers
ā ā
ā āāā config.py # Configuration loader
ā āāā database.py # Database connection manager
ā āāā dependencies.py # FastAPI dependencies
ā āāā keycloak.py # Keycloak OAuth2/OIDC integration
ā āāā main.py # FastAPI app entry point
ā āāā static/ # Static files (favicon, etc.)
ā
āāā plugins/ # Plugin directory (see plugins/readme.md)
āāā tests/ # Unit and integration tests
āāā .github/workflows/ # CI/CD (flake8 lint, pytest)
āāā Dockerfile # Docker build config
āāā gunicorn.conf.py # Gunicorn production config
āāā pyproject.toml # Project metadata, dependencies, and tooling config
āāā scripts/
ā āāā release.sh # Release script (bash)
ā āāā release.ps1 # Release script (PowerShell)
āāā README.md
pytest
ruff check .
CI/CD runs both on push via GitHub Actions (.github/workflows/).
CHANGELOG.md with the new version's changes and commit.# Bash
./scripts/release.sh 0.8.0
# PowerShell
.\scripts\release.ps1 0.8.0
The script will:
pyproject.tomlvX.Y.Z, create branch release/X.YThis project is free software, licensed under the GNU General Public License (GPL) version 3 or later. Refer to the LICENSEā file for details.
Content type
Image
Digest
sha256:0800fe6feā¦
Size
74.1 MB
Last updated
4 months ago
docker pull bgeoopengis/giswater-api