gemseo.utils.pydantic module#

Tools for Pydantic.

copy_field(name, model, **kwargs)[source]#

Copy a Pydantic model Field, eventually overriden.

Parameters:
  • name (str) -- The name of the field.

  • model (type[BaseModel]) -- The model to copy the field from.

  • **kwargs (Any) -- The arguments of the field to be overriden.

Returns:

The copied field.

Return type:

FieldInfo

create_model(Model, settings_model=None, **settings)[source]#

Create a Pydantic model.

Parameters:
  • Model (type[T]) -- The class of the Pydantic model.

  • settings_model (T | None) -- The settings as a Pydantic model. If None, use **settings.

  • **settings (Any) -- The settings. These arguments are ignored when settings_model is not None.

Returns:

A Pydantic model

Raises:

ValueError -- When the class of the "settings" argument is not Model.

Return type:

T

get_algo_name(settings_model, settings)[source]#

Return the algorithm name.

Parameters:
  • settings_model (BaseModel | None) -- The algorithm settings as a Pydantic model. If None, use **settings.

  • settings (dict[str, Any]) -- The algorithm settings, including the algorithm name (use the keyword "algo_name"). The function will remove the "algo_name" entry. These settings are ignored when settings_model is not None.

Returns:

The algorithm name.

Return type:

str

update_field(model, field_name, **kwargs)[source]#

Update a Field of a Pydantic model.

Parameters:
  • model (type[BaseModel]) -- The model.

  • field_name (str) -- The name of the field.

  • **kwargs (Any) -- The arguments of the field to be overridden. See Field() for the description of the arguments.

Return type:

None