wqautils is a batteries-included toolkit for evaluating water-quality observations, generating indices, and shipping analysis workflows to both the command line and web services. It combines configurable regulatory standards, Pydantic data contracts, calibration and unit normalization helpers, and analytics utilities that cover time-series inspection, notifications, visualization, and reporting.
- Configurable standards — load WHO/EPA defaults or bring your own JSON/SQLite tables and switch profiles at runtime.
- Rich data models — strongly typed
WaterQualityParameters, metadata capture, and aWaterQualityStatusenum that surfaces OK vs. Alert states. - Calibrations & unit handling — normalize mixed units (°C/°F/K, µS/mS) and apply per-sensor calibration curves before evaluation.
- Indices & analytics — compute NSF and CCME Water Quality Indices, derive moving averages, z-score anomalies, trend slopes, and sustained alert streaks.
- Ingestion & export — helpers for CSV/JSON ingestion, serialization, and visualization hooks via Matplotlib.
- Interfaces included — Typer-powered CLI for batch analysis and a FastAPI service for programmatic integration, plus a notification system with cooldown management.
Clone the repository and install dependencies with Poetry (recommended for development):
poetry installTo use the library from another project you can also install it locally:
pip install .from datetime import datetime
from wqautils.calibration import CalibrationSetting
from wqautils.models import WaterQualityParameters
from wqautils.utils import check_water_quality
sample = WaterQualityParameters(
temperature=20.5,
dissolved_oxygen=8.1,
conductivity=1.2,
turbidity=1.8,
ph=7.1,
metadata={
"sample_id": "station-7",
"collected_at": datetime.utcnow().isoformat(),
"latitude": 45.1,
"longitude": -122.7,
},
)
results = check_water_quality(
sample,
standard="default",
calibrations={"conductivity": CalibrationSetting(scale=950)},
units={"conductivity": "ms_cm"},
)
print(results.overall_status()) # -> WaterQualityStatus.OK
print(results.nsf_wqi, results.ccme_wqi)
print(results.conductivity.explanation)WaterQualityResults.as_dict() returns a JSON-ready payload containing metadata, per-parameter explanations, computed indices, and timestamps.
Built-in standards (default, freshwater_aquatic) live under wqautils/data/standards. You can list them via the CLI:
poetry run wqautils standardsLoad a bundled configuration or point to your own JSON/SQLite definition:
from wqautils.standards import load_standard, load_standard_from_sqlite
who = load_standard("default")
custom = load_standard("/path/to/custom_standard.json")
lake_rules = load_standard_from_sqlite("standards.db", name="lake-alpha")JSON parameters accept bounds, messaging, optional labels, and allow_negative flags. See wqautils/data/standards/default.json for a template.
wqautils.indices.compute_indicesreturns NSF & CCME WQI scores for compatible samples.wqautils.timeseriesprovidesto_dataframe,moving_average,rolling_zscore,detect_anomalies,trend_slope, andsustained_alertshelpers for pandas DataFrames.- Visualization helpers in
wqautils.visualizationgenerate Matplotlib figures for parameter trends and anomaly overlays.
Use wqautils.notifications.AlertNotifier to emit callbacks when parameters transition into alert states. Cooldowns prevent duplicate alerts, and results are passed through a structured AlertEvent payload.
The Typer CLI supports batch analysis of CSV/JSON files:
poetry run wqautils analyze data/samples.csv --standard default --output results.jsonInputs can be CSV, JSON, or newline-delimited JSON. Results are printed to stdout or written to disk as pretty-printed JSON.
Serve the analyzer over HTTP using Uvicorn:
poetry run uvicorn wqautils.service:app --reloadKey endpoints:
GET /standards– list bundled standard names.POST /analyze– submit a list ofWaterQualityParameterspayloads and receive structured results.GET /health– lightweight health check for deployment probes.
Utilities in wqautils.io cover CSV/JSON ingestion with schema validation and lossless export of analysis results. Pair them with wqautils.utils.check_water_quality for end-to-end pipelines.
Run the test suite and static checks from the project root:
poetry run pytest
poetry run ruff checkFeel free to extend the library with new standards, analytics, or notification sinks—comprehensive unit tests cover the existing surface area to help you iterate safely.