0.1.1
Project description
version 0.1.1
Python DSL to leverage translation of dictionaries and SQLAlchemy into Protobuf objects
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
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
mercator-0.1.1.tar.gz
(9.2 kB
view details)
File details
Details for the file mercator-0.1.1.tar.gz
.
File metadata
- Download URL: mercator-0.1.1.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 816dbae8c03822a34249b7232eb9ee5962f4ddd9a69c29cbeef35a4bc9aa3e7c |
|
MD5 | 90a0dc7725cdff7405f5462c5fa34bb7 |
|
BLAKE2b-256 | 05ac37bb29547af665b976c8f163eb524cb250b1217c4d4b005160fbf10435c2 |