Using Pydantic models within enums

Posted on 2025-04-26 in Programmation • Tagged with Python, Pydantic

In previous articles, I provided some tips on enums and explained how to use a custom class with Pydantic. Now, I’ll dig into all kinds of enum usages with Pydantic, including enums whose members are Pydantic models themselves! Let’s dive right in!

Just like before, you can access …


Continue reading

Reusing Pydantic validators and serializers

Posted on 2025-04-21 in Trucs et astuces • Tagged with Python, Pydantic

I’ll give some tips to reuse field and model validators and serializers. All my examples will use validators, but it works exactly the same for serializers.

Field validators

Assign the validator to a variable like so:

def _is_above_ten(value: int):
    if value > 10:
        return value

    raise ValueError(f"{value …

Continue reading

Using Pydantic with custom classes

Posted on 2025-04-19 in Programmation • Tagged with Python, Pydantic

Pydantic is an awesome data validation library for Python. It’s getting very popular these days because it’s fast, has lots of features and is pleasant to use. I’m using it at work and it personal projects. It’s one of the strong points of FastAPI, the new …


Continue reading