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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a7da8163f0dc1f98af4109858e912e4a374ea7d2f27e3522bfde2f98e75b959
|
|
| MD5 |
6401a07e9c73682c812179ae972aa0b5
|
|
| BLAKE2b-256 |
990f5422d1ca8aeab0a24efc6a4e6ff120bd63770b43ada5c24e1acaeb0e6890
|
Provenance
The following attestation bundles were made for pb2dict-1.0.0.tar.gz:
Publisher:
release.yaml on qvecs/pb2dict
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pb2dict-1.0.0.tar.gz -
Subject digest:
8a7da8163f0dc1f98af4109858e912e4a374ea7d2f27e3522bfde2f98e75b959 - Sigstore transparency entry: 161703073
- Sigstore integration time:
-
Permalink:
qvecs/pb2dict@c0ed9a5ac3fbdc1c8e015fb7363a29466af1c078 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/qvecs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@c0ed9a5ac3fbdc1c8e015fb7363a29466af1c078 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aedf2ef73966a976d003d34acd8648f546b531240ff8e52ed7bb878b96e9f33c
|
|
| MD5 |
6c5ff232180600e73ff2255b5b8d0e61
|
|
| BLAKE2b-256 |
75ebed7cd225b8fdb6649ffcfde744a1db22dbd30a695e898762b004523a3468
|
Provenance
The following attestation bundles were made for pb2dict-1.0.0-py3-none-any.whl:
Publisher:
release.yaml on qvecs/pb2dict
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pb2dict-1.0.0-py3-none-any.whl -
Subject digest:
aedf2ef73966a976d003d34acd8648f546b531240ff8e52ed7bb878b96e9f33c - Sigstore transparency entry: 161703074
- Sigstore integration time:
-
Permalink:
qvecs/pb2dict@c0ed9a5ac3fbdc1c8e015fb7363a29466af1c078 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/qvecs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@c0ed9a5ac3fbdc1c8e015fb7363a29466af1c078 -
Trigger Event:
push
-
Statement type: