{"id":18244287,"url":"https://github.com/stackb/protoc-gen-starlark","last_synced_at":"2026-03-19T03:29:29.558Z","repository":{"id":173557083,"uuid":"650926263","full_name":"stackb/protoc-gen-starlark","owner":"stackb","description":"Scriptable protoc plugins","archived":false,"fork":false,"pushed_at":"2023-06-10T23:00:41.000Z","size":55,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-08T18:40:31.039Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Starlark","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stackb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2023-06-08T05:41:16.000Z","updated_at":"2023-11-22T17:03:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"8a38b605-87ee-42f1-a5ad-faf25ab5ade9","html_url":"https://github.com/stackb/protoc-gen-starlark","commit_stats":null,"previous_names":["stackb/protoc-gen-starlark"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/stackb/protoc-gen-starlark","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackb%2Fprotoc-gen-starlark","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackb%2Fprotoc-gen-starlark/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackb%2Fprotoc-gen-starlark/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackb%2Fprotoc-gen-starlark/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stackb","download_url":"https://codeload.github.com/stackb/protoc-gen-starlark/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackb%2Fprotoc-gen-starlark/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28603767,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T12:01:53.233Z","status":"ssl_error","status_checked_at":"2026-01-20T12:01:46.545Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":"2024-11-05T09:16:00.992Z","updated_at":"2026-01-20T13:33:14.337Z","avatar_url":"https://github.com/stackb.png","language":"Starlark","readme":"[![CI](https://github.com/stackb/protoc-gen-starlark/actions/workflows/ci.yaml/badge.svg)](https://github.com/stackb/protoc-gen-starlark/actions/workflows/ci.yaml)\n\n# protoc-gen-starlark\n\n\u003ctable border=\"0\"\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cimg src=\"https://user-images.githubusercontent.com/50580/141900696-bfb2d42d-5d2c-46f8-bd9f-06515969f6a2.png\" height=\"120\"/\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cimg src=\"https://static.vecteezy.com/system/resources/previews/007/038/145/non_2x/nightingale-singing-tune-song-bird-musical-notes-music-concept-icon-in-circle-round-black-color-illustration-flat-style-image-vector.jpg\" height=\"120\"/\u003e\u003c/td\u003e\n    \u003c!-- image credit: https://www.vecteezy.com/vector-art/7038145-nightingale-singing-tune-song-bird-musical-notes-music-concept-icon-in-circle-round-black-color-vector-illustration-flat-style-image --\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eprotobuf\u003c/td\u003e\n    \u003ctd\u003estarlark\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n`protoc-gen-starlark` is a scriptable protocol buffer plugin.  It might just be\nthe the easiest way to write a protoc plugin! 😍\n\n## Installation\n\nDownload a binary from the [releases\npage](https://github.com/stackb/protoc-gen-starlark/releases), or install from source:\n\n```sh\ngo install github.com/stackb/protoc-gen-starlark/cmd/protoc-gen-starlark@latest\n```\n\n## Usage\n\n`protoc-gen-starlark` works like any other typical protoc plugin: it reads an\nencoded `CodeGeneratorRequest` from stdin and writes an encoded\n`CodeGeneratorResponse` to stdout.\n\nThe logic of generating a response is performed within a starlark script that\nyou must write.  The simplest such script looks something like:\n\n```py\npb = proto.package(\"google.protobuf.compiler\")\n\ndef generate(request):\n    \"\"\"generate prepares the response.\n\n    Args:\n      request: the pb.CodeGeneratorRequest that was read from stdin.\n    Returns:\n      a pb.CodeGeneratorResponse\n    \"\"\"\n    return pb.CodeGeneratorResponse(\n        error = \"not implemented\",\n    )\n\ndef main(ctx):\n    \"\"\"main is the entrypoint function.\n\n    Args:\n      ctx: the script context.  It has a struct member named\n      'vars' which is a StringDict of variables injected into\n      the entrypoint.  vars is guaranteed to have an entry named\n      \"request\" that is the pb.CodeGeneratorRequest read from stdin.\n    Returns:\n      A single pb.CodeGeneratorResponse.  Per skycfg semantics,\n      the return value from `main` must be a list however so it\n      is wrapped accordingly.\n\n    \"\"\"\n    return [generate(ctx.vars[\"request\"])]\n```\n\nAlthough starlark is an interpreted language, the protobuf message types are stongly typed: it is an error to set/get fields that are not part of the message definition.  See [stackb/grpc-starlark](https://github.com/stackb/grpc-starlark) and [stripe/skycfg](https://github.com/stripe/skycfg) for more details about this.\n\n\u003e `protoc-gen-starlark` is built using\n\u003e [stackb/grpc-starlark](https://github.com/stackb/grpc-starlark) and shares the\n\u003e same command line flags.\n\nA sample protoc invocation might look something like:\n\n```sh\n$ export PROTOC_GEN_STARLARK_SCRIPT=foo.star\n$ protoc \\\n  --foo_out=./gendir \\\n  --plugin=protoc-gen-foo=/usr/bin/protoc-gen-starlark\n```\n\nIn this case `protoc-gen-starlark` discovers which script to evaluate using the\n`PROTOC_GEN_STARLARK_SCRIPT` environment variable.\n\nAnother strategy is to copy/rename `protoc-gen-starlark` and the script to a\ncommon name.  If a file named `$0.star` exists where `$0` is the name of the\nexecutable itself, this will be loaded.  For example:\n\n```sh\n$ ln -s /usr/bin/protoc-gen-starlark tools/protoc-gen-foo\n$ mv foo.plugin.star                 tools/protoc-gen-foo.star\n$ ln -s /usr/bin/protoc-gen-starlark tools/protoc-gen-bar\n$ mv bar.plugin.star                 tools/protoc-gen-bar.star\n\n$ protoc \\\n  --foo_out=./gendir \\\n  --plugin=protoc-gen-foo=./tools/protoc-gen-foo\n  --bar_out=./gendir \\\n  --plugin=protoc-gen-bar=./tools/protoc-gen-bar\n```\n\nAlternatively, a shell script can be used to wrap the invocation of the plugin:\n\n```sh\n#!/bin/bash\n\n# protoc-gen-foo.sh wraps protoc-gen-starlark and sets\n# the file argument explicitly.\n\nset -euox pipefail\n\n/usr/bin/protoc-gen-starlark \\\n    -file ./tools/protoc-gen-foo.star\n```\n\n```sh\n$ protoc \\\n  --foo_out=./gendir \\\n  --plugin=protoc-gen-foo=./tools/protoc-gen-foo.sh\n```\n\nBy default, the message types from\n[plugin.proto](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/compiler/plugin.proto)\nare pre-loaded.  You can make additional types available to `proto.package`\nusing the `--protoset=/path/to/a/descriptor_set_out.pb` flag.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackb%2Fprotoc-gen-starlark","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstackb%2Fprotoc-gen-starlark","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackb%2Fprotoc-gen-starlark/lists"}