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
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 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
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 this model with another model.
Parameters:
-
other
(BaseModel
) –The other model to merge with.
Returns:
-
Self
–The merged model.
merge_json
Merges a json representation.
Parameters:
-
other
(Dict[str, Any]
) –The other model to merge with as a jsonified dict
Returns:
-
Self
–The merged model.