Skip to main content

Python Package made by Mhadhbi Issam .

Project description

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 , ....)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

proto2obj-1.0.2.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

proto2obj-1.0.2-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file proto2obj-1.0.2.tar.gz.

File metadata

  • Download URL: proto2obj-1.0.2.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for proto2obj-1.0.2.tar.gz
Algorithm Hash digest
SHA256 8a5a0a1ac7f3f7bd4b91d8dd1b70bc3645f215ed9069efb946c57fe74d04928a
MD5 8ad1ff39b2ce8b0e8f14f8165291a45c
BLAKE2b-256 889f2c39b349fa3467001f3471e014a6cae816063a20987b76eb05efa6b5c63e

See more details on using hashes here.

File details

Details for the file proto2obj-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: proto2obj-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for proto2obj-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5151c4cb218ec42b5862cbcfebaa43d3f6ea89d1ea230100ff42b57b7349a0ec
MD5 8fec23d4b6fe258e464ad678c20120a5
BLAKE2b-256 0b222b63502287a9a4fd7792a56814c374ef5392fd32dd949a9cb9765f1fdafb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page