Skip to main content

Python Protobuf Package

Project description

Install

pip install python-protobuf

Example

from pyproto import Protobuf

print("Test the conversion between protobuf and bytes")
bs = bytes.fromhex("12001a0022020801") # A section of bytes data of protobuf
print("src:", bs.hex())
proto = ProtoBuf(bs)  # Convert bytes to protobuf objects
proto.dump()  # print proto object
bs2 = proto.toBuf()  # Convert the proto object to bytes
print(bs2 == bs, bs2.hex())

print("Mutual conversion between proto object and dict object")
# A complex dict object

d = {
    6: {
        1: {
            1: "eyJhbGciOiJIUzI1NiJ9.ODYxODAyNjMyNjcwMA.KGj7v_WjlntNODpPNe4fVbJA5sPhLjZbQidBLhcrGVM"
        },
        3: "5******7@*****.com",
        4: {1: 6},
        5: {1: 1},
        6: {2: "", 3: "", 4: {1: 1}},
    }
}

# An unassigned dict object template

d2 = {6: {1: {1: ""}, 3: "", 4: {1: 0}, 5: {1: 0}, 6: {2: "", 3: "", 4: {1: 0}}}}
print("src:", d)
pb = ProtoBuf(d)  # Convert dict object to protobuf object

pb.dump()

d3 = pb.toDict(d2)  # Convert protobuf object to dict object

print("d3 == d2 ->", d3 == d2, d3 is d2, d3)
print("d3 == d  ->", d3 == d, d3 is d)

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

python-protobuf-0.0.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_protobuf-0.0.1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file python-protobuf-0.0.1.tar.gz.

File metadata

  • Download URL: python-protobuf-0.0.1.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for python-protobuf-0.0.1.tar.gz
Algorithm Hash digest
SHA256 a959a40e33d3718fbf3189ec6b1645d9919006d6fac9600965e26263d0f3a8f7
MD5 7d2e079cf29454893352f47c610bd604
BLAKE2b-256 45655991e502fc4d1e499c2537e7a6f593600ef5b093439ae0fcdba041e992a2

See more details on using hashes here.

File details

Details for the file python_protobuf-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for python_protobuf-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8d9d1685f0d8b8dfd614709737126583bfce05ca2626e3a5ed1f9e059745dc72
MD5 815315ed9c422badc277d32104215ee5
BLAKE2b-256 2c68bd55b1c771cc7a3124d2ea6e54c6c8b42aa03baa3aaac695fb554da43185

See more details on using hashes here.

Supported by

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