Skip to content

YamlBaseModel

Bases: BaseModel

A base model that can be used to create instances of models from yaml files.

This class augments the Pydantic base model with the ability to load data from yaml files. Moreover, it offers the ability to merge multiple yaml files into a single model. It also internally resolves references to other objects in the yaml files. Lastly, it offers the ability to apply cli arguments to the model.

Info

All Pydantic models that are generated using py-gen-ml will inherit from this class. So make sure to read the documentation on this class to fully leverage all the features of py-gen-ml.

from_yaml_file classmethod

from_yaml_file(path: str) -> Self

Create a new instance of the model from a yaml file.

Parameters:

  • path (str) –

    The path to the yaml file.

Returns:

  • Self

    The new instance of the model.

load_data_with_references classmethod

load_data_with_references(path: str) -> Dict[str, Any]

Load data from a yaml file and resolve references.

Parameters:

  • path (str) –

    The path to the yaml file.

Returns:

  • Dict[str, Any]

    Dict[str, Any]: The loaded data.

from_yaml_files classmethod

from_yaml_files(paths: List[str]) -> Self

Create a new instance of the model by merging the data from multiple yaml files.

The data from the files must be either the base model type that follows the schema defined in the protobufs, or it must be an overlay that can be merged with the same base model type.

Parameters:

  • paths (List[str]) –

    The paths to the yaml files.

Returns:

  • Self

    The new instance of the model.

merge

merge(other: BaseModel) -> Self

Merge this model with another model.

Parameters:

  • other (BaseModel) –

    The other model to merge with.

Returns:

  • Self

    The merged model.

merge_json

merge_json(other: Dict[str, Any]) -> Self

Merges a json representation.

Parameters:

  • other (Dict[str, Any]) –

    The other model to merge with as a jsonified dict

Returns:

  • Self

    The merged model.

apply_cli_args

apply_cli_args(other: BaseModel) -> Self

Merge CLI args base model.

Parameters:

  • other (BaseModel) –

    The other model to merge with.

Returns:

  • Self

    The merged model.