Generated Python SDKs are now available in the BSR
Authored by Stefan VanBuren
Today we’re announcing the release of Python support for generated SDKs in the Buf Schema Registry (BSR)! Python engineers no longer need to manage a Protobuf toolchain or generate code locally—they can now download pre-packaged generated code for their Protobuf schemas from the BSR using package management tools like pip, Poetry, Conda, and others that support PEP 503 - Simple Repository API. These packages are automatically made available when schema changes are pushed to the BSR.
We've updated each BSR module’s Generated SDKs tab with instructions on how to get started with Python generated SDKs using
You can also find instructions and more details in our documentation.
Using generated SDKs with
Let’s create a small project using
pip to pull a package from the Buf Python Repository and then use it to interact with the Connect Demo API.
First, ensure that
python3 is on your
$PATH. Then, create a new directory for the example:
$ mkdir buf-python-example
$ cd buf-python-example
Next, create and activate a virtual environment to install your dependencies in:
$ python3 -m venv venv
$ source ./venv/bin/activate
After that, install the dependency while specifying the Buf Python Repository as an extra index:
$ python3 -m pip install connectrpc-eliza-grpc-python --extra-index-url https://buf.build/gen/python
Then, paste the following code into a file called
from connectrpc.eliza.v1.eliza_pb2_grpc import ElizaServiceStub
from connectrpc.eliza.v1.eliza_pb2 import SayRequest
channel_credentials = grpc.ssl_channel_credentials()
channel = grpc.secure_channel("demo.connectrpc.com", channel_credentials)
stub = ElizaServiceStub(channel)
say_response = stub.Say(SayRequest(sentence="Hello there!"))
if __name__ == "__main__":
From here, we can execute
main.py to interact with the Connect Demo API:
$ python3 -m main
Hello...I'm glad you could drop by today.
The above example installs just the basics we need to run a Python script, but we’ll also want to be able to use tools like
pyright to type check the code.
For that, we can use type-stub packages that are generated by plugins like pyi and mypy-protobuf.
$ python3 -m pip install mypy
Next, we’ll install our type-stub package:
$ python3 -m pip install connectrpc-eliza-protocolbuffers-pyi --extra-index-url https://buf.build/gen/python
Now we can type check our script with
$ python3 -m mypy main.pyOutputSuccess: no issues found in 1 source file
Where to go from here
Head over to our documentation to get started with generated SDKs for Python (or any of our other supported languages). As always, we’d love to hear from you—feedback and questions are welcome on the Buf Slack!