version 0.1.11
Python DSL to leverage translation of dictionaries and SQLAlchemy into Protobuf objects
What is Mercator ?
Mercator is a Python library that simplifies the following of serializing dictionary data into Protobuf binary data.
Mercator actually supports extracting data from:
dictionaries
SQLAlchemy model instances
Any opaque python objects (e.g.: collections.namedtuple)
When should I use Mercator ?
When migrating custom implementations of RPC to gGRPC.
When migrating in-memory data to Protobuf.
When should I not use Mercator ?
When writing gRPC services from scratch.
When writing anything that uses Protobuf gets called.
Install
pip install mercator
Documentation
Basic Usage
1. Given a protobuf declaration
syntax = "proto3";
package services.social_platform;
import "google/protobuf/timestamp.proto";
message User {
message AuthToken {
string value = 1;
google.protobuf.Timestamp created_at = 2;
google.protobuf.Timestamp expires_at = 3;
}
}
2. Declare Mappings
from mercator import (
ProtoMapping,
ProtoKey,
ProtoList,
SinglePropertyMapping,
)
from google.protobuf.timestamp_pb2 import Timestamp
from google.protobuf.struct_pb2 import Struct
from google.protobuf import struct_pb2
ProtobufTimestamp = SinglePropertyMapping(int, Timestamp, 'seconds')
class UserAuthTokenMapping(ProtoMapping):
__proto__ = domain_pb2.User.AuthToken
value = ProtoKey('data', str)
created_at = ProtoKey('created_at', ProtobufTimestamp)
expires_at = ProtoKey('expires_at', ProtobufTimestamp)
class UserMapping(ProtoMapping):
__proto__ = domain_pb2.User
tokens = ProtoList('tokens', UserAuthTokenMapping)
3. Generate python files
python -m grpc_tools.protoc -I ./ --python_out=./ --grpc_python_out=./ ./*.proto
4. Process data!
info = {
'login': 'Hulk',
'email': 'bruce@avengers.world',
'tokens': [
{
'data': 'this is the token',
'created_at': 1552240433,
'expires_at': 1552240733,
}
],
}
user = UserMapping(info).to_protobuf()
assert isinstance(user, domain_pb2.User)
Contributing
Check the code structure documentation
Write tests
Write code
Send a pull-request
Metadata
Release files for mercator 0.1.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| mercator-0.1.11.tar.gz | 9.6 kB | Without provenance | Details |
Release files / mercator-0.1.11.tar.gz
| Download URL | mercator-0.1.11.tar.gz |
|---|---|
| Size | 9.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7053e6eeccddccbfc0be38a8b74f9e343b1d1c97a5385fac61aa487be49555e1
|
|
BLAKE2b-256 checksum How to use checksums |
18e876e799281f7282543f476bc86d8634f085af545a69c4498766eb4af3a81b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0 requests-toolbelt/0.8.0 tqdm/4.36.1 CPython/3.7.6
|
Security for mercator 0.1.11
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.