Skip to main content

pydantic_wrapper

Wrapper to validate arguments and serialize return values using Pydantic.

def pydantic_wrapper(
app: Celery,
task_fun: typing.Callable[..., typing.Any],
task_name: str,
strict: bool = True,
context: typing.Optional[typing.Dict[str, typing.Any]] = null,
dump_kwargs: typing.Optional[typing.Dict[str, typing.Any]] = null
) - > typing.Callable

Wrapper to validate arguments and serialize return values using Pydantic.

Parameters

NameTypeDescription
appCeleryThe Celery application instance associated with the task.
task_funtyping.Callable[..., typing.Any]The original task function to be wrapped and validated.
task_namestrThe unique string identifier for the Celery task.
strictbool = TrueWhether to use Pydantic's strict mode for model validation.
contexttyping.Optional[typing.Dict[str, typing.Any]] = nullAdditional context data passed to the Pydantic validation process.
dump_kwargstyping.Optional[typing.Dict[str, typing.Any]] = nullConfiguration arguments passed to Pydantic's model_dump method during serialization.

Returns

TypeDescription
typing.CallableA wrapped version of the task function that performs Pydantic validation on inputs and serialization on outputs.