Get the latest tech news
Keep Pydantic out of your Domain Layer
Stop Pydantic leaking into your domain layer. Use lightweight mappers or dacite to convert Pydantic models into pure old python dataclasses and keep your domain layer free of third-party libraries.
If you’re building a simple CRUD app, it might feel like overkill to write a bunch of extra boilerplate just to keep Pydantic out of everything except the edges of your application, like the presentation and infrastructure layers. What mainly makes it difficult to convert a Pydantic BaseModel to plain Python dataclasses is that, quite obviously, it takes a lot of manual work to re-initialize the nested structures, especially if you already have a fairly deep object hierarchy. The previous example was nice to quickly get a sense of the functionality of Dacite and the obvious alternative for translating Pydantic Basemodels into pure old Python dataclasses.
Or read this on Hacker News