Skip to main content

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

Metadata

Release files for pb2dict 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pb2dict 1.0.0
File Size Uploaded
pb2dict-1.0.0.tar.gz 6.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pb2dict 1.0.0
File Interpreter ABI Platform
pb2dict-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.5 kB

Release files / pb2dict-1.0.0.tar.gz

Download URL pb2dict-1.0.0.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8a7da8163f0dc1f98af4109858e912e4a374ea7d2f27e3522bfde2f98e75b959
BLAKE2b-256 checksum
How to use checksums
990f5422d1ca8aeab0a24efc6a4e6ff120bd63770b43ada5c24e1acaeb0e6890
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 11, 2025.

Transparency log

Release files / pb2dict-1.0.0-py3-none-any.whl

Download URL pb2dict-1.0.0-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aedf2ef73966a976d003d34acd8648f546b531240ff8e52ed7bb878b96e9f33c
BLAKE2b-256 checksum
How to use checksums
75ebed7cd225b8fdb6649ffcfde744a1db22dbd30a695e898762b004523a3468
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 11, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page