Correct usage of Pydantic in a Temporal Python project

Hi, I’m starting a new temporal project and plan to use Pydantic models for the input and output of my workflows and activities. Could you guide me on the best way to implement this?

I’ve reviewed the example in pydantic converter that shows how to create a custom converter. However, I’m a bit confused about the datetime problem. I won’t be using datetime in my Pydantic models, and I’m also looking to use Pydantic v2.

Would it be sufficient to follow the example’s converter and make the following change?

from pydantic_core import to_jsonable_python

...
        # We let JSON conversion errors be thrown to caller
        return Payload(
            metadata={"encoding": self.encoding.encode()},
            data=json.dumps(value, separators=(",", ":"), sort_keys=True, default=to_jsonable_python).encode(),
        )

This change is discussed in https://github.com/temporalio/samples-python/issues/97

Thanks for your help!