Skip to content

v2.0.0

Latest

Choose a tag to compare

@anuraaga anuraaga released this 19 Aug 00:43
· 20 commits to main since this release
597a15c

This release targets protovalidate 1.2.0.

This is a huge release, marked by our first major version bump to v2 and a repository rename to protovalidate-py to match our new friends protobuf-py and connect-py. There are breaking changes in this release. Read on for more details.

Native performance

protovalidate-py is now a native Python extension, wrapping the implementation from protovalidate-cc while still providing a Python-native experience. Performance has been commonly brought up as an issue using protovalidate, and we hope finally we can give you performance you can be comfortable with. Many operations will be hundreds of times faster, with one of our benchmarks even showing a 800x improvement. Yes... we're sorry it took so long to address this but going forward performance is a high priority for this project. This is not the end and we have more ideas to improve even further, stay tuned.

Going native should not mean users need to build the library - we publish wheels for Linux (glibc and musl), macOS, and Windows, on amd64 and arm64. By using the Python stable ABI, they are always compatible with any version of Python 3, including the next one. In fact, this is wider compatibility then previously where our hard dependency on re2, itself a native library, would cause some lag after a new Python version. We believe this means almost all users will download the prebuilt wheel and use it just like the pure Python version, and for users that use a different platform, you only need Rust and C++ compilers installed for uv or pip to automatically build the extension (as a large amount of C++ code, it will take some time though).

Targets protobuf-py, supports google.protobuf

With this release, we have migrated our base protobuf implementation from google.protobuf to protobuf-py. This primarily means our public API returns Validation protos as protobuf-py messages instead of google.protobuf. Validating google.protobuf messages is still 100% supported, and we have no plan to ever lose that. You can still pass them to the same validation APIs with no change. We don't have a dependency declaration anymore on the protobuf package - if you happened to be pulling it in transitively via protovalidate, you will need to add protobuf directly to your project.

Validation.proto has changed to return a protobuf-py message, read-only access is similar to before, but inner messages can be None instead of automatically instantiated to an empty message. Also, if you marshal the violation protobuf, perhaps to log as JSON in a log message, you will need to update to the protobuf-py idiom for it.

Before:

for violation in validator.collect_violations(message):
  print(violation.proto.rule_id)
  for element in validation.proto.field.elements:
    print(element)
  print(MessageToJson(violation.proto))

After:

for violation in validator.collect_violations(message):
  print(violation.proto.rule_id)
  if field := validation.proto.field:
    for element in field.elements:
      print(element)
  print(violation.proto.to_json())

Vendored in buf.validate

protovalidate now vendors gencode for buf.validate protos, meaning the library itself does not require a user to "bring their protos". This is made possible because protobuf-py does not have a global singleton that causes conflicts when multiple libraries vendor the same proto.

This does not yet solve the issue that users must bring in buf.validate as a dependency for their own protos - we are still working on support for this in protobuf-py. Until that is solved, we continue to recommend using include_imports when you generate your protos. When using protobuf-py, this has no risk of process crash so should be safe in almost all cases. We understand that when using multiple packages that do this, it can result in bloated generated code - solving the underlying issue for imports so you can depend on a package for buf.validate continues to be important to us to fix.

New Contributors

Full Changelog: v1.2.0...v2.0.0