Dataclass Support
Throughout the docs, we use Pydantic models in virtually all of our Python examples for validating task inputs and outputs. This is the recommended path, as it provides lots of safety guarantees as you’re writing tasks. With that said, Hatchet also supports using dataclasses as both input and output types to tasks. Dataclass support was added in SDK version 1.21.0.
Dataclasses do not perform any type validation on instantiation like Pydantic models do.
Usage
To use a dataclass instead of a Pydantic model, you’ll need to:
- Provide an
input_validatoras a parameter to yourworkflowortask(in the case of a standalone task withhatchet.task). - Add return type hints for your
tasks.
Example Usage
dataclass validators work exactly like Pydantic models in Hatchet. First, you create the classes:
And then you provide the classes to your workflow or task:
And finally, triggering works the same as well - you just provide the dataclass instance as input: