Giter Club home page Giter Club logo

cypb's Introduction

CyPB

What is CyPB?

CyPB is fast and light Protocol Buffers decoder for Python.

  • Lazy Decoding support. Message are decoded on the fly as attributes are accessed for the first time. It is big performance gain (~100x in some cases) if only some parts of message are accessed.

  • Fast. Full decoder is twice faster than Google's new C++ wrapper module in PB 2.4

  • No additional dependencies and libraries. Automatically generated C code compiles to Python module.

Usage and example

Compile your proto file

protoc your_proto_file.proto -o your_proto_file.pb2

Generate C module

python generator.py your_proto_file.pb2

Compile C module as Python extension

make compile

Decode messages in Python

from ctest import PBMsg
from pb_types import MSG_Contact

msg = "CiAKBUF0YXNoGghBdGFtdXJhZCINSGV6cmV0a3VsaXlldioUChJhdGFteXJhdEBnbWFpbC5jb20q\nFAoSYXRhbXVyYWRAY29ubmV4LmlvKhQKEmF0YW11cmFkQGdtYWlsLmNvbTIOCgwrOTkzNjc2NDI2\nNDIyDgoMKzk5MzEyMjcwMjAzYh50aGlzIGlzIG5vdGUgZmllbGQgZm9yIGNvbnRhY3Q=\n".decode("base64")

contact = PBMsg(MSG_Contact, msg)

# Display first name and list of phone numbers
print contact.name.first
for e in contact.phone:
    print " * ", e.display_number

Full Decode Benchmark

For benchmarking, only full decode method is used instead of lazy decoder.

Comparision were done on decoding same message 5000 times. See connexio.proto and run_google.py for test message and structure.

Environment:
 * MacBook Pro 2.66Ghz Intel Core 2 Duo
 * Python version: 2.6.1
 * GCC 4.2.1

Average running time on 10 runs:
 * Google's Python module (2.3): 0.711271 seconds.
 * Google's C++ implementation for Python (2.4): 0.093410
 * CyPB: 0.041584 seconds.

TODO

CyPB is in alpha stage and API is highly likely to change in the future. Below is the list of things to do, patches are welcome.

  • Support all data types: doubles, bytes, etc.
  • Handle unknown fields properly based on wire-type
  • Throw exception if invalid attribute is accessed
  • Merge Lazy and Full decoder into one API.
  • Encoder

About / License

CyPB is developed by connex.io gmbh and licensed under new BSD license.

cypb's People

Contributors

atamurad avatar

Watchers

James Cloos avatar Aleph Archives avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.