How do packages and imports work in Protocol Buffer definitions?

Last updated 8 July 2026

A package declaration namespaces the types in a .proto file to avoid name collisions, and import pulls in definitions from another file so you can reference its types.

  • package scoping: Types are referenced as package.TypeName; the package also influences generated code namespaces (unless overridden by options like java_package or go_package).

  • import: Takes a path relative to the proto include roots (the -I/proto_path), not a filesystem-relative path.

  • import public: Re-exports the imported file's types so consumers of your file can use them transitively, useful when refactoring a file into pieces.

  • No transitive visibility by default: A plain import only exposes that file's own types to you, not what it imports; import each file whose types you use directly.

[lang:protobuf] syntax = "proto3"; package myapp.orders; import "myapp/common/money.proto"; message Order { myapp.common.Money total = 1; }

  • https://protobuf.dev/programming-guides/proto3/
  • https://blog.devgenius.io/a-guided-tour-of-grpc-with-protocol-buffers-a8400b1ab361
  • https://buf.build/docs/reference/protobuf-files-and-packages/
  • https://buf.build/docs/best-practices/style-guide/
All gRPC interview questions