Stubs

Getting started

Already using buf?

Keep using buf

The buf CLI works with Stubs, and we test it on every change. Sign in with it as usual:

buf registry login stubs.dev --token-stdin

Then buf push, buf dep update, buf generate and the rest work as they do with any registry.

Or switch to stubs

In your project's directory, run:

stubs config migrate

It writes stubs.yaml from your buf.yaml and stubs.gen.yaml from your buf.gen.yaml, and says what it changed. buf.build's plugins and well-known types become Stubs's, at the same versions (see the table below); everything else is kept as written, comments included. Dependencies on other buf.build modules stay on buf.build, where they still resolve. Your buf files are left as they are, and an existing stubs file is never replaced. Older (v1) buf files are upgraded to v2 on the way.

You don't have to remember: in a project with buf files and no stubs files, stubs offers to do this before a command that uses them, and remembers if you say no. Without a terminal, as in CI, it prints a one-line reminder instead; STUBS_MIGRATION_HINT=off turns that off.

Then pin your dependencies. stubs keeps them in stubs.lock and doesn't read buf.lock:

stubs dep update

This resolves each dependency again, to its latest commit, so it may pick newer versions than your buf.lock has. Check the new stubs.lock before you commit it. To stay on an older version, name its label or commit in the dependency, as in stubs.dev/acme/common:v1.

Lint and breaking rules, ignore comments and command options are the same, so nothing else changes. If you'd rather not migrate, stubs reads buf.yaml as it is, and stubs generate --template buf.gen.yaml uses a buf.gen.yaml. stubs never writes or changes a buf-named file, so a project can be used with both tools while you switch.

Plugin names

Stubs's plugins are named after their projects, under stubs. stubs config migrate renames them for you; if you'd rather edit your generation config by hand, change the names as well as the host (versions are the same):

On buf.buildOn Stubs
bufbuild/esstubs/protobuf-es
connectrpc/esstubs/connect-es
protocolbuffers/gostubs/protobuf-go
connectrpc/gostubs/connect-go
grpc/gostubs/grpc-go
protocolbuffers/javastubs/protobuf-java
grpc/javastubs/grpc-java
protocolbuffers/kotlinstubs/protobuf-kotlin
connectrpc/kotlinstubs/connect-kotlin
protocolbuffers/pythonstubs/protobuf-python
protocolbuffers/pyistubs/protobuf-pyi
grpc/pythonstubs/grpc-python

The well-known types (google/protobuf/*.proto) need no dependency: stubs and buf both have them built in.

Other registries

stubs signs in and pushes only to Stubs registries. Keep using buf to push to another registry. Dependencies on modules there, and remote plugins, still resolve with stubs.