This release is primarily about JSON - we have implemented JSON marshaling in the native extension bringing significant performance improvements, usually 10-20x. As a reminder, connect-py makes it easy to build services using binary or JSON encoding, and with this you should feel comfortable using JSON in production if your use case needs it as the performance difference with binary tends to be 4-5x, not 20x. And new Pydantic integration means you can even use it with normal FastAPI endpoints.
Pydantic integration
Protobuf Message now implement a hook allowing them to be used in most cases a Pydantic model can be - see how it can be used in the docs. Notably, because FastAPI natively supports Pydantic types in API handlers, you can now use messages in place of custom defined models.
from typing import Annotated
from fastapi import Body, FastAPI
from gen.user_pb import User
app = FastAPI()
@app.post("/users")
async def create_user(user: Annotated[User, Body()]) -> User:
user.active = True
return userThe messages will be fully documented and debuggable in the /docs endpoint as well.
📈 Enhancements
- Allow passing in CLI parameters to plugin run by @anuraaga in #20
- Add optional pydantic integration by @anuraaga in #26
- Use fastpath attribute access on free-threaded Python by @anuraaga in #41
- Encode into a bytearray for pure Python by @anuraaga in #42
- Add native JSON marshaler by @anuraaga in #28
- Use a Python-backed global allocator in Rust by @anuraaga in #46
- Add public helpers for codegen plugins by @anuraaga in #53
Full Changelog: v0.2.0...v0.3.0