This page contains all the input formats, to see input specific formats see the image or source pages. Inputs have a format associated with them. Depending on the format other options are available for configuration.

Description

An option in Buf is a parameter that can be added to an input string to modify how it is interpreted by Buf commands. Inputs have a format that describes the type of the input, and each format can have specific options that apply only to that format. The most commonly used option is the format option, which can be used to override the derived format of an input. Other options include branch, tag, ref, depth, recurse_submodules, strip_components, and subdir, which are format-specific and can modify how an input is processed by Buf commands. These options are added to the input string as key-value pairs, separated by the = symbol.

The format option is used to specify the format of schemas in the format of images and sources, as well as the format of payloads when using commands like buf convert which has the flags --to and --from which can use format options.

Usage

Options are parsed to input parameters in the following form:

path#option_key1=option_value1,option_key2=option_value2

Options

#format=[dir|git|mod|protofile|tar|zip|bin|json]
FormatDescriptionDerived extensionExample
dirdirectorypath/to/project
gitgit repository.githttps://github.com/foo/bar.git
modbsr modulebuf.build/bufbuild/eliza
protofileprotobuf file.protopath/to/file.proto, path/to/file#format=protofile
tartarball.tararchive.tar, archive#format=tar
zipzip archive.ziparchive.zip, archive#format=zip
binprotobuf binary.binimage.bin, image#format=bin
jsonjson image.jsonimage.json, image#format=json

#format=dir

A local directory. The path can be either relative or absolute. This is the default format. By default, buf uses the current directory as its input for all commands.

Usage

#format=dir

#format=mod

A Module on the Buf Schema Registry. This uses whatever is in this module for the sources.

Usage

#format=mod

#format=git

A Git repository. The path to the Git repository can be either a local .git directory, or a remote http://, https://, ssh://, or git:// location.

When format is git the ref, branch, tag, depth, recurse_submodules, and subdir options are available.

Usage

#format=git,ref=<ref>,branch=<branch>,tag=<tag>,depth=<depth>,recurse_submodules=<bool>,subdir=<subdir>
OptionDescriptionDefaultExample
refA valid git refHEADbuf build https://github.com/foo/bar#format=git,ref=my_branch
branchA valid git branchHEADbuf build path/to/module#format=git,branch=my_branch
tagA valid git tagbuf build https://github.com/foo/bar#format=git,tag=v1.0.0
depthA valid git depth50buf build path/to/module#format=git,depth=1
recurse_submodulesWhether to clone submodules recursivelyfalsebuf build https://github.com/foo/bar#format=git,recurse_submodules=true
subdirWhich subdir to use as base directorybuf build path/to/archive.tar#format=git,subdir=bar

#format=tar

A tarball. The path to this tarball can be either a local file, a remote http/https location, or stdin. To use stdin use -, for example cat archive.tar | buf build -#format=tar.

When format is tar the compression, strip_components, and subdir options are available.

Usage

#format=tar,compression=[gzip|zstd],subdir=<subdir>,strip_components=<integer>

Options

OptionValueDescriptionExample
compressiongzip,zstdcompression to usebuf build image#format=tar,compression=gzip
strip_componentsintegerstrip first n directories, applied before subdirbuf build path/to/archive.tar#format=tar,strip_components=2
subdirstringsubdirectory to use as base directorybuf build path/to/archive.tar#format=tar,subdir=bar

Derived extensions

As well as using the format and compression options, the following file extensions can be used instead.

ExtensionDerived CompressionExample
.tarnonearchive.tar
.tar.gzgziparchive.tar.gz
.tgzgziparchive.tgz
.tar.zstzstdarchive.tar.zst

#format=protofile

A local .proto file. The path can be either relative or absolute, similar to the dir input. This is a special input that uses the file and its imports as the input to buf commands. If a local configuration file is found, dependencies specified are used to resolve file imports first, followed by the local filesystem. If there is no local configuration, the local filesystem is used to resolve file imports.

When format is protofile The include_package_files option is available.

Usage

#format=protofile,include_package_files=<bool>
OptionValueDescriptionExample
include_package_filesboolinclude all other files in the package for the specified .proto filebuf build file.proto#format=protofile,include_package_files=true

#format=zip

A zip archive. The path to this archive can be either a local file, a remote http/https location, or stdin. To use stdin use -, for example cat archive.zip | buf build -#format=zip.

When format is zip the compression, subdir, and strip_components options are available.

Usage

#format=zip,compression=[gzip|zstd],subdir=<subdir>,strip_components=<integer>

Options

OptionValueDescriptionExample
compressiongzip,zstdcompression to usebuf build image#format=zip,compression=gzip
strip_componentsintegerstrip first n directories, applied before subdirbuf build path/to/archive.tar#format=zip,strip_components=2
subdirstringsubdirectory to use as base directorybuf build path/to/archive.tar#format=zip,subdir=bar

#format=bin

Protobuf binary format. The path to this archive can be either a local file, a remote http/https location, or stdin. To use stdin use -, for example cat image.bin | buf build -#format=bin or just cat image.bin | buf build -.

When the format is bin the compression option is available.

Usage

#format=bin,compression=[gzip|zstd]

Options

OptionValueDescriptionExample
compressiongzip,zstdcompression to usebuf build image#format=bin,compression=gzip

Automatically derived formats and compressions

As well as using the format and compression options, the following file extensions can be used instead.

ExtensionDerived CompressionExample
.binnoneimage.bin
.bin.gzgzipimage.bin.gz
.bin.zstzstdimage.bin.zst

#format=json

Protobuf in JSON format. This creates files that use much more space and are slower to parse but result in diffs that show the actual differences between two Protobuf objects in a readable format. The path to this archive can be either a local file, a remote http/https location, or stdin. To use stdin use -, for example cat image.json | buf build -#format=bin.

When the format is json, the compression option is available.

Usage

#format=json,compression=[gzip|zstd]

Options

OptionValueDescriptionExample
compressiongzip,zstdcompression to usebuf build image#format=json,compression=gzip

Automatically derived formats and compressions

As well as using the format and compression options, the following file extensions can be used instead.

ExtensionDerived CompressionExample
.jsonnoneimage.json
.json.gzgzipimage.json.gz
.json.zstzstdimage.json.zst

Automatically derived formats and compressions

By default, buf derives the format and compression of an input from the path via the file extension.

ExtensionDerived formatDerived Compression
.tartarnone
.tar.gztargzip
.tgztargzip
.tar.zsttarzstd
.zipzipnone
.gitgitnone
.protoprotofilenone
.binbinnone
.bin.gzbingzip
.bin.zstbinzstd
.jsonjsonnone
.json.gzjsongzip
.json.zstjsonzstd

There are also two special cases:

  • If the path is -, this is interpreted to mean stdin. By default, this is interpreted as the bin format.

    Of note, the special value - can also be used as a value to output parameters, which is interpreted to mean stdout, and also interpreted by default as the bin format.

  • If the path is /dev/null on Linux or Mac, or nul for Windows, this is interpreted as the bin format.

If no format can be automatically derived, the dir format is assumed, meaning that buf assumes that the path is a path to a local directory.

The format of an input can be explicitly set as described above.

Deprecated formats

The formats below are deprecated. Though they may continue to work, we recommend updating if you are explicitly specifying any of these.

FormatReplacement
bingzUse the bin format with the compression=gzip option.
jsongzUse the json format with the compression=gzip option.
targzUse the tar format with the compression=gzip option.

Examples

Build an image in tar format with gzip compression:

buf build path/to/image#format=tar,compression=gzip

Invoke an RPC using a git repo as the input to buf curl --schema:

buf curl --data '{"sentence": "I feel happy."}' https://demo.connect.build/buf.connect.demo.eliza.v1.ElizaService/Say --schema=https://github.com/bufbuild/connect-demo.git

Invoke an RPC using a binary as the input to buf curl --schema:

buf curl --data '{"sentence": "I feel happy."}' https://demo.connect.build/buf.connect.demo.eliza.v1.ElizaService/Say --schema=eliza.bin

Lint a dir of protobuf files:

buf lint path/to/directory#format=dir

Export from a tar archive with gzip compression:

buf export path/to/archive#format=tar,compression=gzip --output=path/to/output

Export a git repository:

buf export https://github.com/example/repo#format=git --output=path/to/output

Use a zip as the source for buf convert:

buf convert path/to/archive.zip#format=zip,compression=zstd --from=file.json --to=file.bin --type Person

Lint a git repository on a specific branch:

buf lint https://github.com/example/repo#format=git,branch=my_branch