Data Models#
Base Model Classes#
The SGUBaseModel and SGUResponse classes provide the foundation for all data models.
Base model classes for SGU Client.
- class sgu_client.models.base.SGUBaseModel(**data)[source]#
Bases:
BaseModelBase model for all SGU data structures.
- Parameters:
data (
Any)
- model_config: ClassVar[ConfigDict] = {'extra': 'allow', 'use_enum_values': True, 'validate_assignment': True, 'validate_by_alias': True, 'validate_by_name': True}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sgu_client.models.base.SGUResponse(**data)[source]#
Bases:
SGUBaseModelBase response wrapper for SGU API responses.
- Parameters:
data (
Any)
- to_dataframe(**kwargs) pd.DataFrame#
Convert to pandas DataFrame.
- Returns:
DataFrame with the data
Examples
This is an abstract method that must be implemented by subclasses. Use concrete collection classes instead:
>>> from sgu_client import SGUClient >>> client = SGUClient() >>> # Use specific collection types like GroundwaterStationCollection >>> stations = client.levels.observed.get_stations(limit=5) >>> df = stations.to_dataframe() # This works!
- model_config: ClassVar[ConfigDict] = {'extra': 'allow', 'use_enum_values': True, 'validate_assignment': True, 'validate_by_alias': True, 'validate_by_name': True}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Domain-Specific Models#
For domain-specific data models, see:
Groundwater Levels API - Observed and modeled groundwater level models
Groundwater Chemistry API - Groundwater chemistry measurement models
Working with Models#
Type Hints Example:
from sgu_client import SGUClient
client = SGUClient()
stations = client.levels.observed.get_stations(limit=5)
# full type hints for IDE autocomplete
for station in stations.features:
print(f"Station: {station.properties.station_name}")
print(f"Municipality: {station.properties.municipality}")
print(f"Coordinates: {station.geometry.coordinates}")
DataFrame Conversion:
# convert to pandas DataFrame (requires pandas)
df = stations.to_dataframe()
# geometry and properties are automatically flattened
print(df.columns) # station_id, longitude, latitude, municipality, etc.