{"id":25596885,"url":"https://github.com/nanoporetech/hatch-protobuf","last_synced_at":"2026-06-16T23:31:45.684Z","repository":{"id":234156147,"uuid":"788343686","full_name":"nanoporetech/hatch-protobuf","owner":"nanoporetech","description":"Hatch plugin for generating Python files from Protocol Buffers .proto files","archived":false,"fork":false,"pushed_at":"2026-05-25T20:05:30.000Z","size":83,"stargazers_count":14,"open_issues_count":2,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2026-05-25T22:09:35.700Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nanoporetech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-04-18T08:28:14.000Z","updated_at":"2026-05-12T10:45:21.000Z","dependencies_parsed_at":"2024-04-18T11:07:47.096Z","dependency_job_id":"6da6989e-41ea-4a57-80f4-79f4c38fd57e","html_url":"https://github.com/nanoporetech/hatch-protobuf","commit_stats":null,"previous_names":["nanoporetech/hatch-protobuf"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/nanoporetech/hatch-protobuf","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoporetech%2Fhatch-protobuf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoporetech%2Fhatch-protobuf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoporetech%2Fhatch-protobuf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoporetech%2Fhatch-protobuf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nanoporetech","download_url":"https://codeload.github.com/nanoporetech/hatch-protobuf/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoporetech%2Fhatch-protobuf/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34428196,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-16T02:00:06.860Z","response_time":126,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-21T12:35:07.264Z","updated_at":"2026-06-16T23:31:45.676Z","avatar_url":"https://github.com/nanoporetech.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hatch Protocol Buffers Generator\n\nThis Hatch plugin uses grpcio to generate Python files from Protocol Buffers `.proto` files.\n\n\n## Usage\n\nYou will need to add `hatch-protobuf` to your project's `pyproject.toml`:\n\n```\n[tool.hatch.build.hooks.protobuf]\ndependencies = [\"hatch-protobuf\"]\n```\n\nThere are a few options that can be set in the `[tool.hatch.build.hooks.protobuf]`\nsection:\n\n| Key | Default | Description |\n| --- | ------- | ----------- |\n| `generate_grpc` | `true` | Whether to generate gRPC output files. |\n| `generate_pyi` | `true` | Whether to generate .pyi output files. Note that these are not generated for the gRPC output. You may want to use mypy-protobuf instead. |\n| `import_site_packages` | `false` | Adds your Python `site-packages` directory to `--proto_path`, so you can [`import` `.proto` files from installed Python packages](#import-proto-files-from-site-packages). This *does not* add individual `.proto` files in `site-packages` as arguments to `protoc`. |\n| `proto_paths` | `[\".\"]` or `[\"src\"]` | An array of paths to search for `.proto` files. Also passed as `--proto_path` arguments to `protoc`. This does not follow symlinks. |\n| `output_path` | `\".\"` or `\"src\"` | The default output directory. This can be overridden on a per-generator basis for custom generators. |\n| `library_paths` | `[]` | Similar to `proto_paths`, but **without** building the `_pb2.py` files, allowing imports from `.proto`s not included in the Python `site-packages` directory. |\n\nHatch-protobuf will guess whether to use \"src\" as the default input/output directory in\na similar way to the [wheel builder][wheel-builder-defaults]. If\n`src/\u003cNAME\u003e/__init__.py` exists, but `\u003cNAME\u003e/__init__.py` does not, it will use \"src\" as\nthe default for `proto_paths` and `output_path`. Otherwise it will use \".\" as the\ndefault for both.\n\n[wheel-builder-defaults]: https://hatch.pypa.io/latest/plugins/builder/wheel/#default-file-selection\n\n### Custom generators\n\nIf you want to use custom generators (not just the python, gRPC and pyi ones built in to\nthe version of protoc that ships with grpcio-tools), you can add them in\n`[[tool.hatch.build.hooks.protobuf.generators]]` sections. You will also need to add the\nplugin to the list of dependencies.\n\nOptions that can be set in generator sections:\n\n| Key | Default | Description |\n| --- | ------- | ----------- |\n| `name` | required | The name of the plugin. The argument passed to protoc will be `--\u003cname\u003e_out`. |\n| `outputs` | required | A list of paths (relative to `output_path`). See below for more information. |\n| `output_path` | same as `output_path` from the main `protobuf` config section | Where to write generated files to. This is the value passed to the `--\u003cname\u003e_out` argument. |\n| `protoc_plugin` | `None` | The protoc plugin to use for this generator, if any. Will be passed as --plugin to protoc. This is useful for plugins that are not installed in the Python environment. |\n| `options` | `[]` | Extra parameters to be passed to the protoc plugin using [the `--\u003cname\u003e_opt` argument.][protobuf-pull-2284] |\n\nEach entry in the `outputs` field is a template that depends on the `.proto` file being\nprocessed. The string `{proto_name}` will be replaced with the base filename of each input .proto\nfile, and `{proto_path}` will be replaced with the path (relative to the proto_paths) of\nthe input proto files. For example, if `proto_paths` is set to `[\"src\"]`, for the\ninput file `src/foo/bar/test.proto` \"{proto_name}\" will expand to \"test\" and\n\"{proto_path}\" will expand to \"foo/bar\".\n\nHere is an example using the TypeScript generator:\n\n```\n[[tool.hatch.build.hooks.protobuf.generators]]\nname = \"ts\"\noutputs = [\"{proto_path}/{proto_name}.ts\"]\noutput_path = \"./frontend/src\"\nprotoc_plugin = \"./frontend/node_modules/.bin/protoc-gen-ts_proto\"\n```\n\n[protobuf-pull-2284]: https://github.com/protocolbuffers/protobuf/pull/2284\n\n### Mypy output\n\nThe [mypy-protobuf](https://pypi.org/project/mypy-protobuf/) package provides mypy stub\nfiles with comments copied from the input `.proto` files. Here is an example of how to\nuse it in your `pyproject.toml`:\n\n```\n[tool.hatch.build.hooks.protobuf]\ndependencies = [\n    \"hatch-protobuf\",\n    \"mypy-protobuf~=3.0\",\n]\ngenerate_pyi = false  # we'll let mypy-protobuf do this\n\n[[tool.hatch.build.hooks.protobuf.generators]]\nname = \"mypy\"\noutputs = [\"{proto_path}/{proto_name}_pb2.pyi\"]\n\n[[tool.hatch.build.hooks.protobuf.generators]]\nname = \"mypy_grpc\"\noutputs = [\"{proto_path}/{proto_name}_pb2_grpc.pyi\"]\n```\n\n### Import `.proto` files from `site-packages`\n\nSetting `import_site_packages = true` causes the plugin to add your current\n`site-packages` directory as a `--proto_path` when running `protoc`, *without*\ntrying to build a `_pb2.py` for *every* `.proto` file.\n\nThis allows your package to consume Protocol Buffer definitions from published\nPython packages which include both `.proto` and `_pb2.py` files.\n\nAs an example, consider a gRPC service definition which includes a Protocol\nBuffer message definiton from\n[Google API common protos](https://github.com/googleapis/googleapis/tree/master/google/api):\n\n```proto\n// proto/example/v1/example.proto\nsyntax = \"proto3\";\n\npackage example.v1;\n\nimport \"google/api/annotations.proto\";\n\n// The greeting service definition.\nservice Greeter {\n  // Sends a greeting\n  rpc SayHello(HelloRequest) returns (HelloReply) {\n    option (google.api.http) = {\n      get: \"/say\"\n    };\n  }\n}\n\n// The request message containing the user's name.\nmessage HelloRequest {\n  string name = 1;\n}\n\n// The response message containing the greetings\nmessage HelloReply {\n  string message = 1;\n}\n```\n\nIn this case, the\n[`googleapis-common-protos` package](https://pypi.org/project/googleapis-common-protos/)\ncontains `annotations.proto` and a pre-built version of `annotations_pb2.py`,\nwhich is normally installed in a directory tree layout which can be used by\n*both* Python and `protoc`:\n\n```\nsite-packages/google/api/\n├── annotations_pb2.py\n├── annotations.proto\n├── auth_pb2.py\n├── auth.proto\n...\n```\n\nSetting `import_site_packages = true` makes your generated code contain imports\nthat reference the already-built bindings, and not rebuild them:\n\n```python\n# example/v1/example_pb2.py\nfrom google.api import annotations_pb2 as google_dot_api_dot_annotations__pb2\n```\n\nIf you had added the directory containing `google/api/annotations.proto` to this\nplugin's `proto_paths` option, this would cause it to re-build Python files for\n*all* `.proto` files in that directory, not just the things used for your\npackage, and stomp all over your `site-packages` directory.\n\n\u003e [!NOTE]\n\u003e You can only `import` Protocol Buffer definitions in `.proto` files from\n\u003e *non-editable* dependencies (ie: from ordinary packages published on PyPI or\n\u003e private registries).\n\u003e\n\u003e *Editable* dependencies (eg: installed with `pip install -e` or using\n\u003e [`uv` workspaces](https://docs.astral.sh/uv/concepts/projects/dependencies/#editable-dependencies))\n\u003e use a different directory layout which can't be imported from by `protoc`.\n\nTo consume Protocol Buffer definitions from published Python packages which\ninclude only `_pb2.py` files, `library_paths` can be set to the directory\ncontaining the `.proto` files.\nFor example, You can add [opentelemetry-proto](https://github.com/open-telemetry/opentelemetry-proto)\nas a submodule in a project, and you will be able to import files from it after\nincluding the following config:\n\n```\n[tool.hatch.build.hooks.protobuf]\nlibrary_paths = [\"./libs/opentelemetry-proto\"]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnanoporetech%2Fhatch-protobuf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnanoporetech%2Fhatch-protobuf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnanoporetech%2Fhatch-protobuf/lists"}