Protobuf to Python Converter
Paste a .proto schema. Get Python dataclasses with type hints, IntEnum classes for enums, and proper defaults for repeated and map fields.
Input (.proto schema)
Output (Python)
What this tool does
A Python worker consumes messages described in a Protocol Buffers file, and you would like real type hints for them. Running protoc --python_out (walked through in the official Python tutorial) gives you _pb2 modules built from descriptors at import time, which your editor cannot autocomplete well and which read badly in a pull request. Paste the schema here instead and you get ordinary dataclasses you can read top to bottom, construct in a test with keyword arguments, and fill from a JSON body.
Type mapping is what you would write by hand. string/bytes become str/bytes, bool becomes bool, every integer width (int32 through sfixed64) becomes int, and double/float become float. repeated T becomes list[T] with field(default_factory=list), map<K, V> becomes dict[K, V] with field(default_factory=dict), and singular message references become Optional[Msg] defaulting to None so circular references and forward references just work.
Each proto enum becomes an IntEnum, so OrderStatus.ORDER_STATUS_PAID == 2 holds and the wire numbers survive. The module opens with from __future__ import annotations, and with postponed evaluation a message can reference one declared further down without quoting the name. Nested messages are pulled out to module level, which keeps imports short: from types_gen import LineItem rather than reaching through a parent class. Well-known types are kept simple too; a google.protobuf.Timestamp field is typed as str, ready for the RFC 3339 string proto3 JSON uses.
How to use it
Three steps. The output is ready to drop into a .py file.
Paste your .proto schema
Paste the .proto on the left or open one with Upload; the Python on the right is rewritten shortly after each change. Comments, package and option lines can stay where they are. import lines are not followed, so a message defined in another file is annotated by its bare name and will raise a NameError the first time something evaluates the hint, until you paste its definition in too.
Field names stay as-is: order_id in .proto stays order_id in Python. Snake_case is already Pythonic. Class names also stay PascalCase, matching PEP 8 conventions.
Read the output
The right panel shows Python with one @dataclass per message and one IntEnum subclass per enum. Enums come first, then messages in dependency order (children before parents). Add the file to your project, import the dataclasses you need, and you are done.
Use the dataclasses
Construct instances with keyword arguments, mutate them like normal objects, serialise with dataclasses.asdict() or json.dumps for HTTP transport. If you need full Protobuf wire-format encoding, plug the dataclasses into protobuf-python or use them as a typed shim in front of your gRPC client.
When this actually saves time
Sketching types for a new gRPC Python service
You are starting a new service that consumes an existing Protobuf API. You want clean dataclasses for the request/response shapes without running protoc yet. Paste the schema, drop the output into proto_models.py (not types.py, which would shadow the standard library module), write your business logic against the dataclasses, hook up gRPC Python later when you are ready.
Mocking Protobuf data in pytest
Generated Protobuf message classes are painful to construct in tests because every field has its own setter, and the constructors do not accept all fields as kwargs. Hand-rolled dataclasses do: Order(order_id="ORD-42", customer_name="Ava Chen", total_amount=99.50) just works. Use this output as fixtures and mocks while keeping the real Protobuf classes for wire-format serialisation.
Reviewing a Protobuf API change
A backend teammate added fields to Order and a new OrderStatus value. You want to know what your Python client code needs to handle without running the full build. Paste the new .proto, diff the dataclass output against your current types, leave a focused review comment.
Quick scripts and one-off ETL jobs
You are writing a 50-line script to backfill data from a JSON dump that follows a Protobuf schema. Setting up protoc for a one-shot script is overkill. Grab the dataclasses from here, parse the JSON into them, run the script, throw it away. No build step, no toolchain, no leftover generated files in the repo.
Common questions
Is my schema sent anywhere?
No. The proto text is parsed and the Python module assembled by script that runs inside this page, and no request carries the schema off it. Worth knowing when the file names internal topics, queues or package paths.
Why dataclasses instead of the official protobuf-python message classes?
The generated classes from protoc work, but they are verbose, hard to mock in tests, and noisy in code review. Dataclasses give you typed kwargs, equality comparison, and clean repr for free. If you need wire-format encoding, you can map between the dataclasses and the official message types in a thin adapter layer: most teams find that a better split than typing everything against the generated classes.
Why IntEnum and not str-valued enums?
Protobuf enums are int-valued at the wire level: every value has a tag number. IntEnum matches that exactly: OrderStatus.ORDER_STATUS_PAID is both a named member and the integer 2, which round-trips cleanly through JSON or wire format. If you want a StrEnum (Python 3.11+) for the JSON encoding instead, find-replace IntEnum in the output.
Why are message fields Optional[Msg] instead of just Msg?
In proto3 a singular message field can be unset (the absence is meaningful, unlike scalars where the default is the zero value). Defaulting to None matches that semantics and keeps circular references compiling, if Order embeds an Address and the address embeds back, neither dataclass needs the other to be defined first. from __future__ import annotations at the top of the file makes the forward refs resolve at runtime via PEP 563.
How does it handle map<K, V>?
Renders as dict[K, V] with field(default_factory=dict) as the default. Protobuf maps with non-string keys (map<int32, string>) become dict[int, str]. JSON only has string keys, so when you serialise the dict to JSON the int keys become strings: that is a quirk of the proto3 JSON spec, not the converter.
Does it handle oneof?
Each member of a oneof becomes its own dataclass field with a zero default, and the group name is gone. oneof destination { string email = 3; string webhook_url = 4; } gives you email: str = '' and webhook_url: str = '' side by side. If the exclusivity matters, type them as Optional[str] = None and add a __post_init__ that raises when more than one is set.
Related tools
With the dataclasses written, these pages cover the steps around them: validate the .proto, see the JSON a message serialises to, or go from a Python dict or JSON sample in the other direction.