The Buf Schema Repository (BSR) provides generated SDKs for Python in the form of a PEP 503-compatible repository.
You can consume generated SDKs from modules and plugins using dependency management tools like
It generates SDKs automatically when you push schema changes,
which eliminates the need to manage a Protobuf toolchain or generate code locally.
pip is configured to use the Python Package Index by default.
To use Buf's Python repository with
you can either specify
--extra-index-url https://buf.build/gen/python in all of your
pip to include the argument by default:
extra-index-url = https://buf.build/gen/python
Private generated SDKs
When using SDKs generated from private BSR repositories, you need to authenticate by including a personal API token for local use or a Bot user's API token for CI workflows. See the Authentication page for instructions.
Installing generated SDKs
To install a generated SDK, use
pip install and reference the SDK name.
For example, to install the
connectrpc/eliza Protobuf module using the
you could install the generated SDK like this:
$ pip install connectrpc-eliza-protocolbuffers-python
See the names and versions section for syntax specifics.
Importing from SDKs
In general, Python Protobuf plugins generate code that matches the package structure of their input Protobuf files, so
having your import path match the package structure of your Protobuf files should work. For example, to import
connectrpc-eliza-protocolbuffers-python package generated from the
buf.build/connectrpc/eliza module, the path would look like this:
from connectrpc.eliza.v1.eliza_pb2 import SayRequest
Names and versions
The BSR Python repository has a special syntax for SDK names:
To discover SDK versions for the Python repository, you can browse a repository's generated SDK page, which has installation instructions and an interactive UI for selecting SDK versions.
As an example:
- Plugin version:
- Plugin revision:
- Commit timestamp:
- Commit short name:
For commits on branches,
the commit timestamp component of the version is always
to easily differentiate SDK versions using commits on branches that aren't
Other package managers
For a full list of supported plugins, navigate to the BSR plugins page and search for Python.
- Try the generated SDKs tutorial to learn how to generate SDKs from the BSR.