A source refers to a collection of uncompiled Protobuf files in a project.

The commands that may take a source are:

Along with these, the following only take a source:

Description

A source refers to a collection of uncompiled Protobuf files, which can be stored in various formats such as git, directory, module, tar, protofile, or zip. It is important to note that an image built with buf build is not considered a source.

Several commands in the buf tool can accept a source as their first argument. The export and format commands only accept a source, while other commands such as breaking, build, convert, generate, and lint can accept both a source and an Image.

Additionally, the buf breaking --against command and the buf curl --schema command can accept a source as well.

Usage

Options are parsed to input parameters in the following form:

path#key=value

Options

#format=[dir|git|mod|protofile|tar|zip]

This page contains source formats, to see all formats see the format page.

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

#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 - for stdin.

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
.tarnoneimage.tar
.tar.gzgzipimage.tar.gz
.tgzgzipimage.tgz
.tar.zstzstdimage.tar.zst

#format=protofile

A local Protobuf 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. When using stdin

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

Examples

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

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