Skip to content

[BUG] Buf registry packages have broken imports #65

Description

@milas

Description

Relative imports are broken when a Buf module has a dependency on another one and you try to import a protobuf type.

Steps to Reproduce

  1. Create two Buf modules
  2. Add a dependency from one to the other
  3. Install the package that has the dependency
  4. Try to import a protobuf type

(You can also depend on a pre-existing module, e.g. protovalidate)

Expected Behavior

Package is installable and types are importable.

Actual Behavior

The Buf registry packages use relative imports that are incorrect and try to recurse too many levels upwards.

Screenshots/Logs

from ...buf.validate import validate_pb
ImportError: attempted relative import beyond top-level package

Environment

  • protobuf-py Version: 0.2.0 / 0.3.0
  • protobuf-py Plugin (protoc-gen-py) Version: Unsure - whatever Buf registry is using
  • Python Version: 3.12
  • Protobuf Compiler & Version: Unsure - whatever Buf registry is using
  • Operating System and Version: macOS 26.6.1 (aarch64)

Possible Solution

Additional Context

See #15

Activity

  1. anuraaga commented on Aug 15, 2026

    @anuraaga
    Collaborator

    Thanks it is worth tracking this as an issue. Unfortunately it's not trivial and we are looking at schemes for it which will probably be broader than this repo. In the meantime, we recommend using include_imports to codegen dependencies instead of using generated SDKs, which are always safe with protobuf-py since we don't have a global singleton registry here. We understand this can bloat gencode in large projects though and will continue to look at this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions