FrozenBaseModel#
- pydantic model tollan.config.FrozenBaseModel[source]#
Base model class with immutability and YAML support.
Provides common configuration for astronomy data models: - Frozen by default - Strict type validation - YAML loading/dumping support - Custom JSON schema generation
Examples
>>> class MyConfig(FrozenBaseModel): ... name: str ... value: int >>> config = MyConfig(name="test", value=42) >>> yaml_str = config.model_dump_yaml() >>> loaded = MyConfig.model_validate_yaml(yaml_str)
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.Show JSON schema
{ "title": "FrozenBaseModel", "description": "Base model class with immutability and YAML support.\n\nProvides common configuration for astronomy data models:\n- Frozen by default\n- Strict type validation\n- YAML loading/dumping support\n- Custom JSON schema generation\n\nExamples\n--------\n>>> class MyConfig(FrozenBaseModel):\n... name: str\n... value: int\n>>> config = MyConfig(name=\"test\", value=42)\n>>> yaml_str = config.model_dump_yaml()\n>>> loaded = MyConfig.model_validate_yaml(yaml_str)", "type": "object", "properties": {} }
- Config:
frozen: bool = True
validate_default: bool = True
ignored_types: tuple = (<class ‘functools.cached_property’>,)
strict: bool = True
- classmethod model_json_schema(*args: Any, **kwargs: Any) dict[str, Any][source]#
Generate JSON schema using custom schema generator.
This uses our custom GenerateJsonSchema which knows how to serialize astronomy types (Time, Quantity) in default values.
- Parameters:
*args – Arguments passed to BaseModel.model_json_schema()
**kwargs – Keyword arguments passed to BaseModel.model_json_schema()
- Returns:
JSON schema for the model
- Return type:
- classmethod model_validate_yaml(yaml_source: str | Path, **kwargs: Any) Self[source]#
Validate model from YAML.
- Parameters:
yaml_source (str | Path) – YAML source to load
**kwargs – Arguments passed to model_validate()
- Returns:
Validated model instance
- Return type:
Self
- static yaml_dump(data: object, output: str | os.PathLike | TextIOBase | None = None, **kwargs: object) None | str#
Serialize data as YAML and write to a file, stream, or return as string.
- Parameters:
data (object) – The data to serialize.
output (str or os.PathLike or TextIOBase or None, optional) – Output destination: - None: return YAML as string - str or PathLike: write to file - TextIOBase: write to stream
**kwargs – Additional keyword arguments passed to
yaml.dump.
- Returns:
YAML string if output is None, otherwise None.
- Return type:
str or None
- Raises:
TypeError – If output is not a valid type.
- static yaml_load(source: str | os.PathLike | TextIOBase) object#
Load YAML data from a file, stream, or string.
- Parameters:
source (str or os.PathLike or TextIOBase) – The YAML source. Can be: - File path: read from file - File object: read from stream - String: parse as YAML
- Returns:
Parsed YAML data.
- Return type:
- Raises:
TypeError – If source is not a valid type.