Buf Schema Registry (BSR)

Export modules from the BSR

Within the Buf ecosystem, moving .proto files around is unnecessary. You can manage dependencies in your modules and vendor commonly used modules like googleapis/googleapis from the Buf Schema Registry (BSR) community modules. However, tools other than the Buf CLI may require all .proto files to be present locally.

Exporting Protobuf files

To export .proto files from the BSR, you can use either:

  • the Buf CLI's buf export command
  • download and extract an archive file

The buf export command allows you to copy .proto files to your local environment from many types of sources, including the BSR, a Git repository, or a .tar file. From there you can inspect them or move them into other tools or legacy systems.

The basic buf export command requires a local destination directory path for the output and defaults to the current local directory as the source:

$ buf export -o /path/to/directory

You can also specify a BSR module or a Git repository as the source:

Export a module @latest
$ buf export buf.build/grpc/grpc -o /path/to/directory
Export a module at a specific commit
$ buf export buf.build/grpc/grpc:334e348dc5854e4b99a3a0d25d8ff376 -o /path/to/directory
Export the Protobuf files from a Git repo
$ buf export https://github.com/bufbuild/protovalidate.git -o /path/to/directory

When exporting from the BSR, you can append a specific commit, branch, or tag reference to the module name, preceded by a colon (:). By default, exporting from the BSR includes all dependencies.

You can also limit the output to a subset of the source by either excluding or including specific paths to a directory or file (multiple paths must be separated by commas):

Excludes the 'geo' directory
$ buf export buf.build/googleapis/googleapis -o /path/to/directory --exclude-path google/geo
Only exports the 'geo' and 'longrunning' directories
$ buf export buf.build/googleapis/googleapis -o /path/to/directory --path google/geo,google/longrunning

Module archive

The BSR allows you to download an archive file that includes the module content on the BSR to your local environment.

With the curl command, you can download and save the archive file. The basic download command requires a BSR module as the source:

$ curl -sOJ "https://buf.build/acme/petapis/archive/main.zip" # store output to a local file named with the server-provided filename

You can also specify the commit, branch, or tag reference of the BSR module:

Download a module archive at a specific commit
$ curl -sOJ "https://buf.build/acme/petapis/archive/7abdb7802c8f4737a1a23a35ca8266ef.zip"

Include dependencies

By default, the module archive includes only the specified module’s content, excluding any dependencies.

You can extend the module archive output to include all of the target module’s dependencies, including the Well Known Types, by adding the imports=true query parameter:

Includes dependencies
$ curl -sOJ "https://buf.build/acme/petapis/archive/main.zip?imports=true"

Supported file types

In addition to the zip format, you can also download the archive as a gzipped tarball (tar.gz) by specifying the file extension:

Download as a gzipped tarball
$ curl -sOJ "https://buf.build/acme/petapis/archive/main.tar.gz"