Skip to content
You're viewing docs for Dev. See the latest version →

Aliases

Support for alias configurations.

AliasPath

A data class used by validation_alias as a convenience to create aliases.

Attributes

path

A list of string or integer aliases.

Type: list[int | str]

Methods

convert_to_aliases

def convert_to_aliases() -> list[str | int]

Converts arguments to a list of string or integer aliases.

Returns

list[str | int] — The list of aliases.

search_dict_for_path

def search_dict_for_path(d: dict) -> Any

Searches a dictionary for the path specified by the alias.

Returns

Any — The value at the specified path, or PydanticUndefined if the path is not found.

AliasChoices

A data class used by validation_alias as a convenience to create aliases.

Attributes

choices

A list containing a string or AliasPath.

Type: list[str | AliasPath]

Methods

convert_to_aliases

def convert_to_aliases() -> list[list[str | int]]

Converts arguments to a list of lists containing string or integer aliases.

Returns

list[list[str | int]] — The list of aliases.

AliasGenerator

A data class used by alias_generator as a convenience to create various aliases.

Attributes

alias

A callable that takes a field name and returns an alias for it.

Type: Callable[[str], str] | None

validation_alias

A callable that takes a field name and returns a validation alias for it.

Type: Callable[[str], str | AliasPath | AliasChoices] | None

serialization_alias

A callable that takes a field name and returns a serialization alias for it.

Type: Callable[[str], str] | None

Methods

generate_aliases

def generate_aliases(
    field_name: str,
) -> tuple[str | None, str | AliasPath | AliasChoices | None, str | None]

Generate alias, validation_alias, and serialization_alias for a field.

Returns

tuple[str | None, str | AliasPath | AliasChoices | None, str | None] — A tuple of three aliases - validation, alias, and serialization.