hydromodpy.config.schema_export#

JSON Schema export for HydroModPy Pydantic configuration models.

Exports the JSON Schema describing HydroModPyConfig (or any sub-model) so that IDEs (VS Code + even-better-toml, JSON-Schema-aware UIs) can provide autocompletion, validation, and documentation for HydroModPy TOML configurations.

The exporter preserves the rich json_schema_extra annotations attached to fields (widget_type, unit, display_name_fr, help_text_fr, display_min, display_max) which a front-end (Streamlit, React, …) can consume to render tailored widgets.

Profile filtering#

Use profile="user" (or "dev", "expert") to drop fields whose x-hmp-profile exceeds the requested level. Frontends targeted at hydrogeologists can then receive a pre-trimmed schema instead of filtering every property themselves.

Usage#

Python API:

from hydromodpy.config.schema_export import export_schema, ROOT_SECTIONS
from hydromodpy.physics.flow.flow_config import FlowConfig

schema = export_schema(FlowConfig)
# full root schema:
schema = export_schema()

# by section name (e.g. "flow", "workspace", ...)
schema = export_schema(section="flow")

# filtered by profile
schema = export_schema(profile="user")

CLI:

hmp config schema                     # full root schema to stdout
hmp config schema --section flow      # one section
hmp config schema --profile user      # filtered to user-level fields
hmp config schema --out schema.json   # write to file

Functions

export_schema([model_cls, section, profile])

Export a JSON Schema dict for a HydroModPy configuration model.

schema_sha256([model_cls])

Return the SHA-256 of the canonical JSON Schema for model_cls.

write_schema(path, *[, model_cls, section, ...])

Serialize an exported schema to a JSON file.