Generate a Typed Protobuf Client Without protoc (TS, Python, Go, Rust)

You have the .proto and you need a typed client for it, but you are not setting up a build. A teammate wants the shape of a message to type a fetch call, a quick script needs to read a field from a binary without pulling in the whole SDK, and a partner is asking, what do you actually send, in TypeScript or Python, so their team can type the response. The standard answer is protoc plus the language plugin, a codegen step, a build config, and a dependency on a generated file that nobody has reviewed. It is the right answer for a service. It is the wrong answer for the thing you are doing today.

So you hand-write the types. An interface in TypeScript, a dataclass in Python, a struct in Go. For a flat message with a handful of scalar fields it is ten minutes and it is fine. Then the .proto has a repeated field, a map, an enum, a nested message, a Timestamp, and you are doing it again. And the first time the .proto changes, the hand-written type is stale, and nobody knows, until it does not match what is on the wire. That is the failure. Not the writing, the drift. The type stops being a function of the schema and becomes a memory of the schema from three weeks ago.

The Generate tab at proto.datajutsu.com removes the build. Paste the .proto, pick a target, and you get typed code for four languages plus JSON Schema, right in the browser, downloadable as a file. TypeScript as an interface with the field numbers kept as comments, Python as a dataclass, Go as a struct with the right protobuf types and the import line, Rust as a prost struct with the wire attributes and the tag on every field. Enums come out as their real values, repeated fields as the right array types, maps as the right record or HashMap or Dict, and the well-known types resolve to what your language actually uses instead of a raw string you have to convert yourself. You get the same output the codegen step would give, without the step.

The thing that makes it worth using more than once is that the output is a function of the .proto. Run it again when the schema changes and you get the new types, and you can diff them against the last version in a pull request like any other generated code. That closes the loop the hand-written type leaves open: the type is always the schema, never a copy of it. If you do not have the .proto yet and are working from sample data, the same tool drafts one from the JSON and verifies it against your data field for field, which I wrote up in this post on drafting a .proto from JSON.

Everything runs in the browser, nothing you paste is uploaded, and a share link puts your .proto in the URL so you can hand someone the exact schema you are working from. Free, no account, no protoc, no build config. If you also need the schema itself for a partner who validates payloads, that is a post on its own: protobuf to JSON Schema that actually matches the wire.

Subscribe to Data Jutsu

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe