{"id":20839249,"url":"https://github.com/arachnys/protostub","last_synced_at":"2025-08-12T18:13:53.440Z","repository":{"id":57539384,"uuid":"122982842","full_name":"arachnys/protostub","owner":"arachnys","description":"A tool for generating Mypy type stubs from a Protocol Buffer definition.","archived":false,"fork":false,"pushed_at":"2018-12-02T18:23:42.000Z","size":279,"stargazers_count":22,"open_issues_count":3,"forks_count":2,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-05-08T21:42:33.815Z","etag":null,"topics":["mypy","protobuf","type","type-annotations","type-checking"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arachnys.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}},"created_at":"2018-02-26T14:40:47.000Z","updated_at":"2023-07-30T15:44:36.000Z","dependencies_parsed_at":"2022-09-21T06:45:42.618Z","dependency_job_id":null,"html_url":"https://github.com/arachnys/protostub","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/arachnys/protostub","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arachnys%2Fprotostub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arachnys%2Fprotostub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arachnys%2Fprotostub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arachnys%2Fprotostub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arachnys","download_url":"https://codeload.github.com/arachnys/protostub/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arachnys%2Fprotostub/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270110182,"owners_count":24529004,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-12T02:00:09.011Z","response_time":80,"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":["mypy","protobuf","type","type-annotations","type-checking"],"created_at":"2024-11-18T01:13:02.114Z","updated_at":"2025-08-12T18:13:53.383Z","avatar_url":"https://github.com/arachnys.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# protostub [![](https://travis-ci.org/arachnys/protostub.svg?branch=master)](https://travis-ci.org/arachnys/protostub) [![](https://img.shields.io/badge/godoc-reference-5272B4.svg)](https://godoc.org/github.com/arachnys/protostub)\n\nA tool for generating Mypy type stubs from a Protocol Buffer definition.\n\n## Usage\nYou can download a binary from the\n[releases](https://github.com/arachnys/protostub/releases) page, or you can use \n[Docker](https://github.com/arachnys/protostub#docker).\n\nAssuming that you have a `.proto` file called `foo.proto` and you want to \ngenerate a `.pyi` file from it, usage is as such:\n\n```\nprotostub generate --proto foo.proto\n```\n\nIn this case, protostub assumes you want to call your stub `foo_pb2.pyi`. If \nthis is not the case, or perhaps you want to specify a different directory, the \noutput can be specified like so:\n\n```\nprotostub generate --proto foo.proto --mypy bar.pyi\n```\n\nHelp is included in the tool:\n\n```\nGenerate Mypy type stubs from Protobuf definitions\n\nUsage:\n  protostub [command]\n\nAvailable Commands:\n  generate    Generate a stub from a given proto file\n  help        Help about any command\n\nFlags:\n  -h, --help   help for protostub\n\nUse \"protostub [command] --help\" for more information about a command.\n```\n\n### Using the stubs\nIf you've tried using mypy in your project, you've probably noticed that it does\nnot do anything for protobuf types. This is because the generated python contains\nnothing that Mypy can use - classes are not defined in the \"normal\" way.\n\nWe currently use a script to generate a list of files for Mypy to check. If the \n`.py` file has a corresponding `.pyi` file, then the `.py` is ignored. Otherwise\nit is used. This allows us to override any Python with a type stub, meaning we\ncan override Python generated by `protoc` with something generated by `protostub`,\nand get functioning type checks!\n\nAn alternative would be to invoke Mypy on a module rather than on files, and \nprovide the stubs in `MYPYPATH`. However, I have not tested this, so I don't know\nhow well it works.\n\n\n### Docker\nA docker image is also provided! The easiest way for you to use this is as follows \n(assuming there is a file called foo.proto in the current directory):\n\n```\ndocker run -v $(pwd):/protostub protostub:latest generate -p foo.proto\n```\n\nAfter doing this, you should see the help text.\n\n## Building\n\n### Requirements\n- Go\n- make (optional)\n\n\n### With go get\nIf you already have Go all setup in your `PATH`, then it is as simple as:\n\n```\ngo get github.com/arachnys/protostub/cmd/protostub\n```\n\n### With Make\nThis approach might be best if you're less familiar with Go, and want it to \n*just work*. It requires no messing with `$GOPATH`.\n\n```\ngit clone https://github.com/arachnys/protostub\ncd protostub\nmake\n```\n\nThe protostub binary should be in the `bin` folder.\n\n## How is this different to `mypy-protobuf`\nProtostub was created and used internally at Arachnys before mypy-protobuf was\nreleased as an open source project. We use it as part of our CI to try and catch\nissues before they make it into production. As such, it's very important that\neverything is dockerized - hence it's on Docker hub, so there's no dependency on\nPython or protoc.\n\nWe also have out of the box Python 3 support, as that is what our codebase\nrequired.\n\nOur version is also completely standalone, and does not function as a plugin for\nprotoc. While this means you only need one binary (statically linked with no\ndependencies), it does mean that it may not be quite as \"correct\" in terms of\nparsing protobuffers, or generating python code.\n\n## License\n```\nThe MIT License (MIT)\nCopyright © 2018 Arachnys Information Services Ltd and individual contributors.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the “Software”), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farachnys%2Fprotostub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farachnys%2Fprotostub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farachnys%2Fprotostub/lists"}