cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1103
Views
2
Helpful
0
Replies

Pydantic v2.0a1 is released

davidn#
Cisco Employee
Cisco Employee

pydantic.png

If you're new to Pydantic: Pydantic is an open-source Python library that provides powerful data parsing and validation — including type coercion and useful error messages when typing issues arise — and settings management capabilities. It provides an easy and concise way to define data models and enforce type hints at runtime.

Pydantic can be used to validate input data, deserialize JSON or YAML files, and generate documentation. It is particularly useful when dealing with API requests and responses, configuration files, and command-line interfaces.

Here are some of the most interesting new features in the current Pydantic V2 alpha release.

The biggest change to Pydantic V2 is pydantic-core — all validation logic has been rewritten in Rust and moved to a separate package, pydantic-core. This has a number of big advantages:

  • Performance - Pydantic V2 is 5-50x faster than Pydantic V1.
  • Safety & maintainability - We've made changes to the architecture that we think will help us maintain Pydantic V2 with far fewer bugs in the long term.

With the use of pydantic-core, the majority of the logic in the Pydantic library is dedicated to generating "pydantic core schema" — the schema used define the behaviour of the new, high-performance pydantic-core validators and serializers.

Ready for experimentation:

  • BaseModel - the core of validation in Pydantic V1 remains, albeit with new method names.
  • Dataclasses - Pydantic dataclasses are improved and ready to test.
  • Serialization - dumping/serialization/marshalling is significantly more flexible, and ready to test.
  • Strict mode - one of the biggest additions in Pydantic V2 is strict mode, which is ready to test.
  • JSON Schema - generation of JSON Schema is much improved and ready to test.
  • Generic Models - are much improved and ready to test.
  • Recursive Models - and validation of recursive data structures is much improved and ready to test.
  • Custom Types - custom types have a new interface and are ready to test.
  • Custom Field Modifiers - used via Annotated[] are working and in use in Pydantic itself.
  • Validation without a BaseModel - the new AnalyzedType class allows validation without the need for a BaseModel class, and it's ready to test.
  • TypedDict - we now have full support for TypedDict via AnalyzedType, it's ready to test.

More info: https://docs.pydantic.dev/blog/pydantic-v2-alpha/

0 Replies 0