Skip to main content

7 posts tagged with "pydantic"

pydantic tag description

View All Tags

Deep dive into pydantic BaseModel class decorators

· 9 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

Pydantic BaseModel class decorators are a powerful and modern way to customize a model's behavior and validation logic. While a lot of Pydantic's functionality is configured through class attributes or the ConfigDict, decorators offer a more explicit and code-centric approach, especially for complex validation.

Pydantic V2 introduced several new decorators to enhance validation and model configuration. The most important ones are:

  • @model_validator
  • @field_validator
  • @computed_field

These decorators are typically imported from pydantic.

Benchmark: msgspec vs. Pydantic v2

· 5 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

msgspec is an extremely fast serialization and validation library that consistently outperforms Pydantic v2 in benchmarks. This performance advantage comes from its design as a lean, compiled-code-based library focused on a narrow set of data handling tasks, whereas Pydantic v2 is a feature-rich framework.

The performance differences are most pronounced in two key areas: parsing/decoding (converting data like JSON into Python objects) and serialization/encoding (converting Python objects into data like JSON).

msgspec Struct

· 4 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

msgspec.Struct is a powerful data class in the msgspec library that's used to define the schema of your data. It's similar to Python's built-in dataclasses or typing.NamedTuple, but it's specifically optimized for high-performance serialization and validation. When you use a Struct, msgspec can perform operations like JSON encoding and decoding significantly faster than standard Python methods because it has a predefined, static understanding of your data's layout.

Drawbacks of Msgspec Compared to Pydantic: A Deep Dive with Examples

· 5 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

msgspec is gaining attention in the Python ecosystem due to its incredible speed and minimalist design. It's written in Rust, supports JSON and MsgPack, and uses type hints for validation. But like every tool, it’s not perfect - and when compared to the battle-tested and feature-rich Pydantic, there are several key trade-offs to be aware of.

In this article, we’ll explore what msgspec lacks compared to Pydantic, illustrated with code examples and practical reasoning.

Python Data Serialization in 2025 - Alternatives to Pydantic and the Future Landscape

· 5 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

As of 2025, Pydantic remains a cornerstone of data validation and serialization in the Python ecosystem. Yet, with the evolving needs of performance-critical applications and broader standardization efforts in the language, new contenders have emerged - and old ones are adapting.

In this article, we explore the current landscape of Python data serialization libraries, their strengths, weaknesses, and futures.

Best Practices for Using Pydantic with Flask for Request and Response Serialization

· 5 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

Pydantic is widely known for its powerful data validation and parsing capabilities using Python type hints. While it's most popular with FastAPI, it can be elegantly integrated with Flask to improve request validation, input parsing, and response formatting.

This article outlines best practices for combining Flask with Pydantic in a clean, maintainable way.