{"id":15077738,"url":"https://github.com/sergey0xff/protox","last_synced_at":"2025-10-05T11:31:50.125Z","repository":{"id":53783216,"uuid":"229341772","full_name":"sergey0xff/protox","owner":"sergey0xff","description":"Python protobuf (protocol buffers) implementation for humans","archived":true,"fork":false,"pushed_at":"2021-07-19T08:57:49.000Z","size":222,"stargazers_count":10,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-20T06:26:10.392Z","etag":null,"topics":["grpc","grpclib","protobuf","protobuf-compiler","protobuf-python","protoc","protocol-buffers","protox","python3","serialization"],"latest_commit_sha":null,"homepage":"","language":"Python","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/sergey0xff.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":"2019-12-20T21:54:21.000Z","updated_at":"2024-01-22T09:07:23.000Z","dependencies_parsed_at":"2022-08-30T08:22:14.896Z","dependency_job_id":null,"html_url":"https://github.com/sergey0xff/protox","commit_stats":null,"previous_names":["sergey-tikhonov/protox"],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergey0xff%2Fprotox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergey0xff%2Fprotox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergey0xff%2Fprotox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergey0xff%2Fprotox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sergey0xff","download_url":"https://codeload.github.com/sergey0xff/protox/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235393591,"owners_count":18982818,"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","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":["grpc","grpclib","protobuf","protobuf-compiler","protobuf-python","protoc","protocol-buffers","protox","python3","serialization"],"created_at":"2024-09-25T04:31:23.117Z","updated_at":"2025-10-05T11:31:44.870Z","avatar_url":"https://github.com/sergey0xff.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Protox\nProtocol buffers implementation for Python 3 that generates human-readable code with type hinting support\n\n## Quick example\n```python\nfrom enum import IntEnum\nfrom protox import Message\nfrom protox import UInt32, String, EnumField\n\n\nclass User(Message):\n    class Role(IntEnum):\n        USER = 1\n        ADMIN = 2\n\n    id: int = UInt32(number=1, required=True)\n    email: str = String(number=2, required=True)\n    role: Role = EnumField(Role, number=3, required=True, default=Role.USER)\n\n\nuser = User(id=1, email=\"john@doe.com\", role=User.Role.USER)\nuser_data = user.to_bytes()\n\nprint(User.from_bytes(user_data))\n# Outputs:\n# message User\n#     id = 1\n#     email = 'john@doe.com'\n#     role = Role.USER\n```\n\n## More examples \n* [EXAMPLES.md](EXAMPLES.md)\n* [Grpclib example](grpclib_example)\n\n## Code generation\nCode generator implemented as a protoc plugin so you have to install it first:\n\n#### Install protoc (Ubuntu)\n```bash\nsudo apt install protobuf-compiler\n```\n\n#### Install protoc (Mac OS)\n```bash\nbrew install protobuf\n```\n\n#### Install protox\n```bash\npython3 -m pip install protox\n````\n\n#### Generate messages\n```bash\nprotoc \\\n    --proto_path=protobuf_src \\\n    --protox_out=. \\\n    ./protobuf_src/user.proto\n```\n\n#### Generate grpclib service with all required dependencies \nThe following code generates service `ping_pong.proto` from the `protobuf_src` directory into `{$PROJECT_ROOT}/app/protobuf`.\n\nThe protox plugin supports 3 options:\n* --base-package=path/to/protobuf/out \n* --grpclib  # generates grpclib services \n* --with-dependencies  # generates dependencies for the given protobuf file\n\nThe options to the plugin are passed using the `--protox_opt=\"{plugin options here}\"` command \n```bash\nprotoc \\\n    --proto_path=protobuf_src \\\n    --protox_out=. \\\n    --protox_opt=\"--base-package=app/protobuf --grpclib --with-dependencies\" \\\n    ./protobuf_src/ping_pong.proto\n```\n\n\n## Core concepts \n* Human-readable python3.6+ generated code with type hinting\n* Support protobuf 2 and 3 at the same time\n* `None` values instead of zero values in fields for both proto2 and proto3\n* `Message.has_field()` in both proto2 and proto3\n* Protocols are easy to describe without code generation \n* Messages implemented in more pythonic way: to_bytes() instead of SerializeToString()\n* Enums are just enums python int enums\n\n## Features\n- [x] Messages\n- [x] Enums\n- [x] Nested messages\n- [x] Maps\n- [x] Well-known types\n- [x] Repeated fields\n- [x] Repeated messages\n- [x] Repeated enums\n- [x] Custom Message.to_python() / from_python() functions\n- [ ] Group fields (Deprecated by protobuf)\n\n\n## Code generator features\n- [x] Protobuf\n- [x] [Grpclib](https://github.com/vmagamedov/grpclib/)\n- [ ] [Grpc.io](https://github.com/grpc/grpc/tree/master/src/python/grpcio)\n- [x] Custom python package for protobuf out messages\n- [x] Compile protobuf file with dependencies\n- [x] Names mangling to avoid reserved names collisions\n- [x] Recursive messages/enums support\n- [x] Field names to_snake_case support\n\n## Difference with google's protobuf implementation\nBinary protocol works exactly as google's implementation does.\n\nThe difference is in the way messages behave:\n* Fields that were not explicitly set are None rather than zero-values\n* Methods like SerializeToString() were changed to more pythonic alternatives like to_bytes() / from_bytes()\n* Enums are just python int enums\n\n## Generated code example\n[Grpclib service example](grpclib_example/app/protobuf/service_grpclib.py)\n\n```python\nfrom enum import IntEnum\n\nimport protox\n\n\nclass User(protox.Message):\n    class Status(IntEnum):\n        USER = 1\n        ADMIN = 2\n\n    id: int\n    email: str\n    status: 'User.Status'\n\n    def __init__(\n        self,\n        *,\n        id: int = None,\n        email: str = None,\n        status: 'User.Status' = None,\n    ):\n        super().__init__(\n            id=id,\n            email=email,\n            status=status,\n        )\n\n\nprotox.define_fields(\n    User,\n    id=protox.Int32(\n        number=1, required=True\n    ),\n    email=protox.String(\n        number=2, required=True\n    ),\n    status=protox.EnumField(\n        number=3, py_enum=User.Status, default=User.Status.USER, required=True\n    ),\n)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsergey0xff%2Fprotox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsergey0xff%2Fprotox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsergey0xff%2Fprotox/lists"}