proto2obj
This Python library converts Protocol Buffers (Protobuf) messages into Python classes, mapping each message member to a class property. The main purpose of this library is to enable inheritance from Protobuf messages. Instead of inheriting directly from the Protobuf message (which is impossible), it inherits from a proxy class that shares the same data structure and can be converted back to Protobuf message data.
Installation
pip install proto2obj
Example of usage :
Example 1 :
from proto2obj import Proto2Obj
# msg is a protobuff message type
fake_msg_type = Proto2Obj(msg).convert()
#def convert(self,base = tuple() , attrs = dict()) :
# base = baseclasses , to generate the new type as drived from base classes
# attrs = extra static memebers assigned to new generated type
# get fields :
print(f"Message fields : {instance.__fields__}")
# get enums
print(f"Message enums : {instance.__enums__}")
# get nested types , they are converted also
print(f"Message nested types : {instance.__nested_types__}")
# the original protobuff message which is converted from
print(f"Message original protobuff message : {instance.__protobuf__}")
## create instance
instance = fake_msg_type(var = value , ....)
# assigne memebers like normal python object
instance.var = value2
# convert back to protobuff instance
msg_instance = instance.proto()
Example 2 :
from proto2obj import Proto2Obj
# msg is a protobuff message type
fake_msg_type = Proto2Obj(msg).convert()
class DrivedType(fake_msg_type) :
pass
instance = DrivedType(var = value , ....)
Metadata
Release files for proto2obj 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| proto2obj-1.0.2.tar.gz | 4.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| proto2obj-1.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.5 kB
Release files / proto2obj-1.0.2.tar.gz
| Download URL | proto2obj-1.0.2.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8a5a0a1ac7f3f7bd4b91d8dd1b70bc3645f215ed9069efb946c57fe74d04928a
|
|
BLAKE2b-256 checksum How to use checksums |
889f2c39b349fa3467001f3471e014a6cae816063a20987b76eb05efa6b5c63e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.12
|
Release files / proto2obj-1.0.2-py3-none-any.whl
| Download URL | proto2obj-1.0.2-py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5151c4cb218ec42b5862cbcfebaa43d3f6ea89d1ea230100ff42b57b7349a0ec
|
|
BLAKE2b-256 checksum How to use checksums |
0b222b63502287a9a4fd7792a56814c374ef5392fd32dd949a9cb9765f1fdafb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.12
|