Skip to main content

panamap-proto

PyPI version PyPI - Python Version Build Status Coveralls github

Panamap-proto adds protobuf support to panamap object mapper.

Installation

Use the package manager pip to install panamap-proto.

pip install panamap

Usage

Initialize mapper

To enabe protobuf support you must pass ProtoMappingDescriptor in list to custom_descriptors parameter to Mapper constructor:

from panamap import Mapper
from panamap_proto import ProtoMappingDescriptor

mapper = Mapper(custom_descriptors=[ProtoMappingDescriptor])

After that you can set up mapping for protobuf generated classes.

Map classes

To map message Simple:

// messages.proto
syntax = "proto3";

message Simple {
    string value = 1;
}

You should use folowing configuration:

from panamap import Mapper
from panamap_proto import ProtoMappingDescriptor

from messages_pb2 import Simple

mapper = Mapper(custom_descriptors=[ProtoMappingDescriptor])

mapper.mapping(Simple, SimpleData).map_matching().register()

s = mapper.map(SimpleData("abc"), Simple)

print(s.value)
# 'abc'

Map enums

There is many ways to map python enums to protobuf generated enums, but the easiest way is to use values_map utility method:

// messages.proto
enum Lang {
    PYTHON = 0;
    CPP = 1;
    JAVA = 2;
}
from enum import Enum

from panamap import Mapper, values_map
from panamap_proto import ProtoMappingDescriptor

from messages_pb2 import Lang

class PyLang(Enum):
    PYTHON = 1
    CPP = 2
    JAVA = 3

mapper = Mapper(custom_descriptors=[ProtoMappingDescriptor])

pairs = [
    (PyLang.PYTHON, Lang.Value("PYTHON")),
    (PyLang.JAVA, Lang.Value("JAVA")),
    (PyLang.CPP, Lang.Value("CPP")),
]

mapper.mapping(PyLang, Lang) \
    .l_to_r_converter(values_map({py: proto for py, proto in pairs})) \
    .r_to_l_converter(values_map({proto: py for py, proto in pairs})) \
    .register()

Contributing

Contributing described in separate document.

Metadata

Release files for panamap-proto 1.1.1

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

Source distribution (sdist)

Source distribution for panamap-proto 1.1.1
File Size Uploaded Provenance Actions
panamap-proto-1.1.1.tar.gz 3.5 kB Without provenance Details for panamap-proto-1.1.1.tar.gz

Release files / panamap-proto-1.1.1.tar.gz

Download URL panamap-proto-1.1.1.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7558391741b1eaeba09249c34adf2be3a9c7c5b4377847cf5ddf769f9f27e972
BLAKE2b-256 checksum
How to use checksums
4e727301123364307473d38b49101d75767aea0617b26371d0790c976150da48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.1

Security for panamap-proto 1.1.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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