Utility functions

flame_hub.get_field_names(model: type[ResourceT]) tuple[str, ...]

Returns all optional field names for a given model.

This function traverses a given model and all of its bases using the method resolution order. While traversing, all attributes are checked if they are annotated with the IsField sentinel which marks an optional field. The names of all annotated attributes are returned as a tuple.

Parameters:
modeltype[ResourceT]

A resource model for which all field names should be retrieved. Note that fields are not consequently annotated for Create and Update models due to inheritance.

Returns:
tuple[str, …]

Returns a tuple of all attribute names that are annotated with IsField.

flame_hub._base_client.obtain_uuid_from(uuid_identifiable: UuidModel | UUID | str) UUID

Extract a UUID from a model containing an id property, UUID object or a string.

Raises:
ValueError

If uuid_identifiable is neither an instance of BaseModel, str nor UUID.

See also

UuidIdentifiable, UuidModel, ResourceT
flame_hub._base_client.uuid_validator(value: Any, handler: ValidatorFunctionWrapHandler) UUID

Callable for Pydantic’s wrap validator WrapValidator to cast resource type instances and strings to UUID.

This function tries to validate value with handler and if this raises a validation error, it tries to cast value to a UUID with obtain_from_uuid().

Raises:
ValidationError

If obtain_from_uuid() raises a ValueError, the original ValidationError is raised.

See also

UuidIdentifiable, UuidModel, ResourceT, obtain_from_uuid()