A tool to dynamically create protobuf message classes from JSON Typedef
Project description
JTD To Proto
This library holds utilities for converting JSON Typedef to Protobuf.
Why?
The protobuf langauge is a powerful tool for defining language-agnostic, composable datastructures. JSON Typedef (JTD) is also a powerful tool to accomplish the same task. Both have advantages and disadvantages that make each fit better for certain use cases. For example:
Protobuf:- Advantages
- Compact serialization
- Auto-generated
grpcclient and service libraries - Client libraries can be used from different programming languages
- Disadvantages
- Learning curve to understand the full ecosystem
- Not a familiar tool outside of service engineering
- Static compilation step required to use in code
- Advantages
JTD:- Advantages
- Can be learned in 5 minutes
- Can be written inline in the programming language of choice (e.g. as a
dictinpython)
- Disadvantages
- No optimized serialization beyond
json - No automated service implementations
- Static
jtd-codegenstep needed to generate native structures
- No optimized serialization beyond
- Advantages
This project aims to bring them together so that a given project can take advantage of the best of both:
- Define your structures in
JTDfor simplicity - Dynamically create
google.protobuf.Descriptorobjects to allow forprotobufserialization and deserialization - Reverse render a
.protofile from the generatedDescriptorso that stubs can be generated in other languages - No static compiliation needed!
Usage
The usage of this library can be best understood with a simple example:
import jtd_to_proto
# Declare the Foo protobuf message class
Foo = jtd_to_proto.descriptor_to_message_class(
jtd_to_proto.jtd_to_proto(
name="Foo",
package="foobar",
jtd_def={
"properties": {
# Bool field
"foo": {
"type": "boolean",
},
# Array of nested enum values
"bar": {
"elements": {
"enum": ["EXAM", "JOKE_SETTING"],
}
}
}
},
)
)
def write_foo_proto(filename: str):
"""Write out the .proto file for Foo to the given filename"""
with open(filename, "w") as handle:
handle.write(Foo.to_proto_file())
Similar Projects
There are a number of similar projects in this space that offer slightly diferent value:
jtd-codegen: This project focuses on statically generating language-native code (includingpython) to represent the JTD schema.py-json-to-proto: This project aims to deduce a schema from an instance of ajsonobject.pure-protobuf: This project has a very similar aim tojtd-to-proto, but it skips the intermediatedescriptorrepresentation and thus is not able to produce nativemessage.Messageclasses.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jtd_to_proto-0.1.0-py310-none-any.whl.
File metadata
- Download URL: jtd_to_proto-0.1.0-py310-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3.10
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d050ec6604cc5e9b1000ea5a888326e5b2dacc3a140a4bda2cd43e1eccbaf42f
|
|
| MD5 |
eadb269015663a63eeaf2578a6704626
|
|
| BLAKE2b-256 |
082de192e1b8b09f4633d8dc733cd18e3eeb13c49f063da88faf66c67a6cbfac
|
File details
Details for the file jtd_to_proto-0.1.0-py39-none-any.whl.
File metadata
- Download URL: jtd_to_proto-0.1.0-py39-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3.9
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e40d285e21df745edd733f082db221138456a3d27fda2750ba244877c026680e
|
|
| MD5 |
b796f86b3d4c3c749c8de6be003502bf
|
|
| BLAKE2b-256 |
a4cafa08d6a266f13a103e0e4271ce4911bf4c171fcaab7749ef2fccbbc6bbf4
|
File details
Details for the file jtd_to_proto-0.1.0-py38-none-any.whl.
File metadata
- Download URL: jtd_to_proto-0.1.0-py38-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3.8
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ca530a5ca1eeffdb3dffbca35488dcd071c059fdf7e2aba8cfe7838331fa1f7
|
|
| MD5 |
16d85de77439178827a9c661935b705e
|
|
| BLAKE2b-256 |
7428e6724d1b79e8880780c9d8dee0994aa60ef366df332e8aa3270c91959de3
|
File details
Details for the file jtd_to_proto-0.1.0-py37-none-any.whl.
File metadata
- Download URL: jtd_to_proto-0.1.0-py37-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3.7
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4a1647b2ed3797beb59f1739e02b68d3b25a0e2c23f4f6e676db540c41ef782
|
|
| MD5 |
975d4501af77d1f0d839c698b9d8300b
|
|
| BLAKE2b-256 |
ed77cbad1ca7e879f065c8874631b050f626957614f1b9989f04b88f3c118abf
|