Skip to main content

Protobuf to dictionary converter.

Project description

Protobuf to Dictionary (pb2dict)

Utility to convert Protobuf messages to dictionary with optional custom conversions.

Install

pip install pb2dict

Usage

Basic Usage

from message_pb2 import Message
from pb2dict import to_dict, to_message

msg = Message(msg=b"hello")

msg_dict = to_dict(msg)
# {'msg': b'hello'}

msg_original = to_message(Message, msg_dict)
# Message(msg=b'hello')

Custom Conversions

Use fields to specify overrides for particular field types.

import base64
from message_pb2 import Message

from pb2dict import to_dict, to_message, fields

msg = Message(msg=b"hello")

msg_dict = to_dict(
    pb=msg,
    fields={fields.BYTES: lambda raw: base64.b64encode(raw).decode("utf-8")},
)
# {'msg': 'aGVsbG8='}

original_msg = to_message(
    pb=Message,
    data=msg_dict,
    fields={fields.BYTES: lambda txt: base64.b64decode(txt)},
)
# Message(msg=b'hello')

fields Type

class fields:
    DOUBLE
    FLOAT
    INT32
    INT64
    UINT32
    UINT64
    SINT32
    SINT64
    FIXED32
    FIXED64
    SFIXED32
    SFIXED64
    BOOL
    STRING
    BYTES
    ENUM

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

pb2dict-1.0.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

pb2dict-1.0.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file pb2dict-1.0.0.tar.gz.

File metadata

  • Download URL: pb2dict-1.0.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for pb2dict-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8a7da8163f0dc1f98af4109858e912e4a374ea7d2f27e3522bfde2f98e75b959
MD5 6401a07e9c73682c812179ae972aa0b5
BLAKE2b-256 990f5422d1ca8aeab0a24efc6a4e6ff120bd63770b43ada5c24e1acaeb0e6890

See more details on using hashes here.

Provenance

The following attestation bundles were made for pb2dict-1.0.0.tar.gz:

Publisher: release.yaml on qvecs/pb2dict

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pb2dict-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pb2dict-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for pb2dict-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aedf2ef73966a976d003d34acd8648f546b531240ff8e52ed7bb878b96e9f33c
MD5 6c5ff232180600e73ff2255b5b8d0e61
BLAKE2b-256 75ebed7cd225b8fdb6649ffcfde744a1db22dbd30a695e898762b004523a3468

See more details on using hashes here.

Provenance

The following attestation bundles were made for pb2dict-1.0.0-py3-none-any.whl:

Publisher: release.yaml on qvecs/pb2dict

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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