Convert Figma logo to code with AI

bufbuild logobuf

The best way of working with Protocol Buffers.

11,298
364
11,298
57

Top Related Projects

10,076

Go support for Google's protocol buffers

45,395

C++ based gRPC (C++, Python, Ruby, Objective-C, PHP, C#)

Your Swiss Army Knife for Protocol Buffers

Documentation generator plugin for Google Protocol Buffers

Quick Overview

Buf is a modern Protocol Buffers ecosystem, providing tools for API design, linting, breaking change detection, and code generation. It aims to simplify and streamline the development process for Protocol Buffer-based APIs, offering a more user-friendly and efficient alternative to traditional protoc-based workflows.

Pros

  • Simplified workflow for Protocol Buffer development and management
  • Powerful linting and breaking change detection capabilities
  • Supports remote generation and caching of generated code
  • Integrates well with existing Protocol Buffer ecosystems

Cons

  • Learning curve for developers familiar with traditional protoc workflows
  • May require changes to existing build processes and CI/CD pipelines
  • Limited support for some less common Protocol Buffer features
  • Relatively new project, still evolving and stabilizing

Code Examples

  1. Initializing a Buf project:
buf mod init

This command initializes a new Buf module in the current directory.

  1. Linting Protocol Buffer files:
buf lint

This command runs the Buf linter on your Protocol Buffer files, checking for style and best practice violations.

  1. Detecting breaking changes:
buf breaking --against '.git#branch=main'

This command checks for breaking changes between the current branch and the main branch.

Getting Started

To get started with Buf, follow these steps:

  1. Install Buf:

    brew install bufbuild/buf/buf
    
  2. Initialize a Buf project:

    buf mod init
    
  3. Create a buf.yaml configuration file:

    version: v1
    lint:
      use:
        - DEFAULT
    breaking:
      use:
        - FILE
    
  4. Run Buf commands:

    buf lint
    buf generate
    buf breaking --against '.git#branch=main'
    

These steps will set up a basic Buf project and demonstrate some of its core functionalities.

Competitor Comparisons

10,076

Go support for Google's protocol buffers

Pros of protobuf

  • Mature and widely adopted in the Go ecosystem
  • Directly supported and maintained by the Go team
  • Extensive documentation and community resources

Cons of protobuf

  • Limited built-in linting and formatting capabilities
  • Lacks advanced features for managing multiple proto files and dependencies
  • Requires additional tools for a complete protobuf workflow

Code Comparison

protobuf:

import "google.golang.org/protobuf/proto"

message := &MyProtoMessage{Field: "value"}
data, err := proto.Marshal(message)

buf:

import "github.com/bufbuild/buf/cmd/buf/command"

cmd := command.NewRoot()
err := cmd.Execute()

Key Differences

  • buf focuses on providing a comprehensive toolkit for Protocol Buffers, including linting, formatting, and dependency management
  • protobuf is primarily a library for working with Protocol Buffers in Go
  • buf offers a more streamlined workflow for managing proto files across projects
  • protobuf provides lower-level access to Protocol Buffer internals

Use Cases

  • Choose protobuf for direct integration with Go projects and when lower-level control is needed
  • Opt for buf when working on larger projects with multiple proto files, or when seeking a more robust development workflow

Community and Ecosystem

  • protobuf has a larger user base and more third-party integrations
  • buf is gaining popularity for its modern approach to Protocol Buffer development
45,395

C++ based gRPC (C++, Python, Ruby, Objective-C, PHP, C#)

Pros of gRPC

  • Mature and widely adopted framework with extensive language support
  • Comprehensive ecosystem with tools for load balancing, authentication, and monitoring
  • High-performance, low-latency communication using HTTP/2

Cons of gRPC

  • Steeper learning curve and more complex setup compared to Buf
  • Requires more boilerplate code for basic implementations
  • Limited browser support without additional proxies or libraries

Code Comparison

gRPC (Python):

import grpc
from example_pb2 import ExampleRequest
from example_pb2_grpc import ExampleServiceStub

channel = grpc.insecure_channel('localhost:50051')
stub = ExampleServiceStub(channel)
response = stub.ExampleMethod(ExampleRequest(name='John'))

Buf (Go):

import (
    "context"
    "github.com/bufbuild/connect-go"
    "github.com/bufbuild/connect-grpcreflect-go"
)

client := connect.NewClient[ExampleServiceClient](http.DefaultClient, "http://localhost:8080")
resp, err := client.ExampleMethod(context.Background(), connect.NewRequest(&ExampleRequest{Name: "John"}))

Summary

gRPC offers a robust, high-performance framework with extensive language support and a comprehensive ecosystem. However, it comes with a steeper learning curve and more complex setup. Buf provides a simpler, more streamlined approach to building and managing Protocol Buffers-based APIs, making it easier to get started but potentially sacrificing some of the advanced features and ecosystem support that gRPC offers.

Your Swiss Army Knife for Protocol Buffers

Pros of Prototool

  • More mature project with longer history and established user base
  • Offers linting and formatting capabilities out of the box
  • Provides a single binary for multiple protobuf-related tasks

Cons of Prototool

  • Less active development and maintenance compared to Buf
  • Limited support for modern protobuf features and ecosystem integrations
  • Slower performance for large protobuf projects

Code Comparison

Prototool configuration:

lint:
  rules:
    add:
      - ENUM_NAMES_UPPER_SNAKE_CASE
    remove:
      - ENUM_NAMES_CAMEL_CASE

Buf configuration:

version: v1
lint:
  use:
    - DEFAULT
  enum_zero_value_suffix: _UNSPECIFIED
breaking:
  use:
    - FILE

Prototool focuses on a more traditional approach to protobuf management, while Buf offers a more modern and comprehensive solution. Buf provides better performance, more extensive ecosystem support, and a stronger focus on breaking change detection. However, Prototool may be preferred by users who need a simpler, all-in-one tool for basic protobuf tasks and are comfortable with its established workflow.

Documentation generator plugin for Google Protocol Buffers

Pros of protoc-gen-doc

  • Focused specifically on generating documentation for Protocol Buffers
  • Supports multiple output formats (HTML, Markdown, JSON)
  • Lightweight and easy to integrate into existing protoc workflows

Cons of protoc-gen-doc

  • Limited to documentation generation, lacking broader protobuf tooling features
  • Requires manual integration with protoc, potentially more setup work
  • Less active development and community support compared to Buf

Code Comparison

protoc-gen-doc usage:

protoc --doc_out=./docs --doc_opt=html,index.html protos/*.proto

Buf usage:

buf generate

Key Differences

Buf is a comprehensive Protocol Buffers ecosystem tool, offering features like linting, breaking change detection, and a remote schema registry. protoc-gen-doc, on the other hand, is a specialized tool for generating documentation from protobuf files.

Buf aims to simplify the entire protobuf workflow, including code generation and management, while protoc-gen-doc focuses solely on documentation generation.

Buf has a more active development community and frequent updates, whereas protoc-gen-doc has a more stable but less frequently updated codebase.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

The Buf logo

Buf

License Release CI Docker Homebrew Slack

Buf is the modern toolchain for Protobuf. It replaces day-to-day protoc use with a fast compiler, module-aware workspaces, formatting, linting, breaking-change detection, code generation, dependency management, API calls, and a client for the Buf Schema Registry.

If you are still driving Protobuf with shell scripts around protoc -I ..., Buf is the upgrade you want: the same schema language, the same generated-code plugin model, fewer moving parts, and a direct path from local .proto files to governed, versioned APIs.

Start

Install buf with Homebrew:

brew install bufbuild/buf/buf

Initialize a workspace and run the checks you should expect every Protobuf repository to pass:

buf config init
buf build
buf format -w
buf lint
buf breaking --against '.git#branch=main'

Generate code from a checked-in buf.gen.yaml instead of a hand-maintained shell command:

buf generate

For a guided walkthrough from an empty workspace to a working Connect service, run the Buf CLI quickstart.

Why Buf wins

Protobuf workWith protoc and scriptsWith Buf
Finding filesMaintain -I paths and hope import order does not change behavior.Declare modules once in buf.yaml; Buf discovers files and rejects ambiguous imports.
CompilingManage a local protoc install and parse changing stderr output.Use Buf's internal compiler, tested against protoc descriptor output and built for deterministic parallel compilation.
StyleRely on review comments or separate tooling.Run buf lint locally, in editors, in CI, and on the BSR with 40+ built-in rules plus custom plugins.
CompatibilityFind breakage after generated code fails, clients fail, or serialized data becomes unreadable.Run buf breaking against Git, a BSR module, a tarball, a zip file, or a Buf image before merge.
Code generationKeep plugin binaries installed on every machine and encode behavior in long commands.Put plugins, outputs, options, inputs, and managed-mode settings in buf.gen.yaml; use local or remote plugins.
DependenciesCopy .proto files between repositories or vendor them by hand.Declare BSR module dependencies in buf.yaml and pin them in buf.lock.
API consumersSend people your schemas and generation instructions.Publish to the BSR and let consumers install generated SDKs with go get, npm install, Maven, Gradle, pip install, NuGet, Cargo, SwiftPM, CMake, or an archive.
GovernanceReimplement checks in every repository and hope every team keeps them enabled.Enforce breaking-change, uniqueness, and custom policies at the BSR layer.

Core CLI features work without a BSR account. Signing in to the registry adds distribution, remote plugins, generated SDKs, hosted docs, dependency resolution for private modules, and server-side checks when you need them.

Core workflow

Buf treats a directory tree of .proto files as a module, and a project as a workspace. A small buf.yaml is enough to make build, lint, breaking-change detection, generation, dependency resolution, and publishing agree on the same input.

version: v2
modules:
  - path: proto
lint:
  use:
    - STANDARD
breaking:
  use:
    - FILE

From there, the useful commands are deliberately boring:

buf build
buf format -w
buf lint
buf breaking --against '.git#branch=main'
buf generate
buf push

buf build compiles the workspace. buf lint catches API-shape problems while the author is still editing. buf breaking compares the current schema against a previous version and flags source, JSON, or wire-format incompatibilities. buf generate runs protoc plugins from a checked-in template. buf push publishes named modules to the BSR.

Code generation

buf generate is compatible with the normal protoc plugin model, but it moves generation into versioned configuration. This example generates Go Protobuf types and ConnectRPC handlers from proto/ using remote plugins hosted on the BSR:

version: v2
clean: true
managed:
  enabled: true
  override:
    - file_option: go_package_prefix
      value: github.com/acme/weather/gen/go
plugins:
  - remote: buf.build/protocolbuffers/go
    out: gen/go
    opt: paths=source_relative
  - remote: buf.build/connectrpc/gosimple
    out: gen/go
    opt:
      - paths=source_relative
      - simple
inputs:
  - directory: proto

Remote plugins remove the need to install and maintain generator binaries on every developer machine or CI runner. Managed mode lets API producers keep language-specific file options out of .proto files while consumers still get correct generated package names for their target language.

Local plugins work too. If a plugin speaks the standard Protobuf plugin protocol, Buf can run it.

Breaking changes

Protobuf compatibility is not one thing. Renaming a field can break generated source code while preserving the binary wire format; changing a field from int32 to string breaks every existing serialized message. buf breaking makes that distinction explicit with rule categories for FILE, PACKAGE, WIRE_JSON, and WIRE compatibility.

buf breaking --against '.git#branch=main'

--against accepts a Git branch, a BSR module, a tarball, a zip file, a local directory, or a prebuilt Buf image. That matters in real repositories: the same command works on a laptop, in CI, and in release automation.

Buf Schema Registry

Buf Schema Registry is a Protobuf-aware registry. It stores modules, verifies they compile, renders documentation, resolves dependencies, hosts remote plugins, produces generated SDKs, and can enforce schema checks before a breaking change reaches consumers.

buf push

Pushing a module to the BSR gives your organization a source of truth for Protobuf APIs. Consumers can depend on the schema as a BSR module, install generated SDKs from their normal package manager, or use the BSR docs to inspect services, messages, fields, enums, references, and historical commits.

Related projects

Buf is most useful when schemas drive more than code generation. ConnectRPC uses Protobuf schemas to build simple HTTP APIs that support Connect, gRPC, and gRPC-Web without separate service definitions. Protobuf-ES gives JavaScript and TypeScript users a modern Protobuf runtime and generator. Protovalidate puts validation rules in the schema and runs them consistently across languages.

One contract should drive the whole workflow: compile, lint, compatibility checks, generated clients and servers, validation, API calls, package publishing, and governed changes.

Installation

Homebrew installs the buf, protoc-gen-buf-breaking, and protoc-gen-buf-lint binaries, plus shell completion scripts for Bash, Fish, PowerShell, and zsh.

brew install bufbuild/buf/buf

Other supported installation methods include npm, Windows, Docker, binary downloads, tarballs, source builds, and minisign verification. See the installation docs for the full list.

CLI stability

Buf CLI releases do not make breaking changes within a major version. Since buf reached v1.0, you can expect no breaking changes until v2.0. We have no plans to release v2.0.

This policy does not apply to commands behind the buf beta gate. Expect breaking changes for beta commands until they are promoted.

Documentation

Community

For help and discussion around Protobuf, best practices, and Buf, join us on Slack.

For bugs, feature requests, and technical questions, open an issue in this repository or email dev@buf.build. For general inquiries, email info@buf.build.

NPM DownloadsLast 30 Days