Skip to content

utils

dict_to_pydantic

dict_to_pydantic(data: Dict[str, Any], cls: Type[M]) -> M

Convert a dictionary to a Pydantic object.

Source code in src/appl/caching/utils.py
def dict_to_pydantic(data: Dict[str, Any], cls: Type[M]) -> M:
    """Convert a dictionary to a Pydantic object."""
    return cls.model_validate(data)

encode_to_uuid_v5

encode_to_uuid_v5(
    value: str, namespace: UUID = uuid.NAMESPACE_DNS
) -> str

Encode a string into a UUID version 5.

Parameters:

  • value (str) –

    The input string to encode.

  • namespace (UUID, default: NAMESPACE_DNS ) –

    The namespace for the UUID (default: DNS namespace).

Returns:

  • str

    The generated UUID as a string.

Source code in src/appl/caching/utils.py
def encode_to_uuid_v5(value: str, namespace: uuid.UUID = uuid.NAMESPACE_DNS) -> str:
    """Encode a string into a UUID version 5.

    Args:
        value: The input string to encode.
        namespace: The namespace for the UUID (default: DNS namespace).

    Returns:
        The generated UUID as a string.
    """
    return str(uuid.uuid5(namespace, value))

pydantic_to_dict

pydantic_to_dict(obj: BaseModel) -> Dict[str, Any]

Convert a Pydantic object to a dictionary.

Source code in src/appl/caching/utils.py
def pydantic_to_dict(obj: BaseModel) -> Dict[str, Any]:
    """Convert a Pydantic object to a dictionary."""
    return obj.model_dump()