Pydantic V2 leverages Rust's Superpowers [video]

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • koda-validate

    Typesafe, Composable Validation

  • As someone who built a pure python validation library[0] that's much faster than pydantic (~1.5x - 12x depending on the benchmark), I have to say that this whole focus on Rust seems premature. There's clearly a lot of room for pydantic to optimize its Python implementation.

    Beyond that, rust seems like a great fit for tooling (i.e. ruff), but as a library used at runtime, it seems a little odd to make a validation library (which can expect to receive any kind of data valid python data) to also be constrained by a separate set of data types which are valid in rust.

    [0]: https://github.com/keithasaurus/koda-validate

  • pydantic-core

    Core validation logic for pydantic written in rust

  • > to also be constrained by a separate set of data types which are legal in rust.

    This isn't really how writing rust/python iterop works. You tend to have opaque handles you call python methods on. Here's a decent example I found skimming the code.

    https://github.com/pydantic/pydantic-core/blob/main/src/inpu...

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
  • Maat

    Validation and transformation library powered by deductive ascending parser. Made to be extended for any kind of project.

  • Personally, I think it's great to have many projects solving the same problem and pushing each other further. Although the differences between the faster validations are small, the older ones were quite slow. This will save unnecessary CPU cycles, making it eco-friendly. And now the bar will be even higher with a Rust version, which is really great.

    [0]Maat is 2.5 times faster than Pydantic on their own benchmark, as stated in their readme.

    [0]https://github.com/Attumm/Maat

  • serialite

    Serialization and deserialization library for Python

  • Pydantic is so cool and I am really excited to migrate to v2. My biggest pain point in Pydantic is that it has no abstract base class for a serializer/deserializer. There is just BaseModel. This means that there is no "Pydantic interface" to implement. If I need to serialize/deserialize something other than an object with attributes, I basically can't do it in Pydantic, or at least I couldn't figure out how to do it.

    In contrast, when I designed Serialite [1], I designed it to have a Serializer base class with two abstract methods: to_data and from_data. Then I added a @serializable decorator that can be applied to any dataclass, which injects concrete implementations of to_data and from_data. The decorator is what I usually use, but I sometimes implement the base class directly when it gets too complicated.

    Making Serialite work with FastAPI was almost impossible because there is no interface to implement, duck type or otherwise. In the end, Serialite monkey patches some key FastAPI functions to make them understand Serialite Serializers and that seems to work.

    [1] https://github.com/drhagen/serialite

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts