Protocols and public contracts#
HydroModPy V1 makes its public surface explicit through three layers:
the public facade
hydromodpy(re-exportsopen,read,run,calibrate,index,viz,mlstubs);a small set of Protocols that pin the structural contract for storage backends and field readers;
a field registry that maps logical names to physical readers.
This page documents what users and integrators can rely on.
The hmp public facade#
The single supported import path is import hydromodpy as hmp. The
package exposes a flat set of verbs and helpers re-exported from
hydromodpy._api:
Symbol |
Role |
|---|---|
|
Open a project catalog. Returns a |
|
Read a logical field from a |
|
Execute a workflow declared in the project TOML. |
|
Drive a calibration session. |
|
Open the machine-wide |
|
Render one figure for a run. Scalable defaults via datashader / LTTB. |
Storage Protocol: CatalogBackend#
Source: hydromodpy/results/catalog/ports.py.
The catalog facade interacts with the SQL store only through this
Protocol. The in-tree adapter is DuckDBBackend.
Required surface:
class CatalogBackend(Protocol):
def ensure_schema(self) -> None: ...
def query(self, sql: str, params: ...) -> pandas.DataFrame: ...
def execute(self, sql: str, params: ...) -> None: ...
def fetch_one(self, sql: str, params: ...) -> tuple | None: ...
def fetch_all(self, sql: str, params: ...) -> list[tuple]: ...
def insert(self, table: str, row: dict[str, Any]) -> None: ...
# ... plus transaction context manager and close()
Conformance is structural (@runtime_checkable). No base class to
inherit. ensure_schema() runs the Alembic-like migration runner so
the catalog is always at the version pinned by the library.
Simulation store Protocol#
Source: hydromodpy/results/storage_contract.py
(SimulationStore Protocol).
Covers the minimal write/read surface that workflow steps, solver adapters, and post-run extractors actually call:
registration:
register_simulation;per-simulation writes:
write_parameters,write_timeseries,write_field,write_time,write_crs,write_mesh,write_provenance,write_metric,write_run_environment,register_tracked_files;reads:
query_timeseries,list_simulations,__getitem__,open_zarr;lifecycle:
finalize,closeand the context-manager protocol.
The default implementation is
SimulationCatalog. Conforming
alternative backends (PostgreSQL, Parquet-only, in-memory, remote
object storage) can plug in without touching workflow code.
Field registry#
Source: hydromodpy/results/field_registry.py.
Maps a logical field name ("head", "watertable_depth",
"accumulation_flux", …) to:
the physical store kind (
"zarr"or"parquet");the canonical path inside that store (
field/head,timeseries.parquet?variable=head);the CF
standard_nameand the unit.
hmp.read reads the registry first and dispatches to the matching
reader. Adding a new field is a registry entry plus a writer; readers
keep working unchanged.
Versioned schema constants#
Constant |
Definition |
|---|---|
|
one row per applied migration; latest is the active version. |
|
separate ledger row scoped to the cache component. |
|
separate ledger row scoped to the index component. |
|
Pinned to |
|
Pinned to |
|
Pinned to |
For the migration runner mechanics, see Schema Evolution.
Stability promise#
The public facade hmp.* and the two Protocols above are the V1
stable surface. Backwards-compatibility shims, aliases, and
re-exports outside the facade are forbidden (see CLAUDE.md under
“What this codebase forbids”).
A change to any of the four areas above is a breaking change that requires:
a migration entry under the relevant
hydromodpy/.../migrations/directory;a version bump of the matching constant (
ZARR_SCHEMA_VERSION,PARQUET_SCHEMA_VERSION,GEOPARQUET_SCHEMA_VERSION);a docs update on this page and on Storage Layout.
See also#
Storage Layout for the on-disk layout these Protocols cover.
Schema Evolution for the migration policy.
results for the Python surface.