{ "info": { "author": "huangyi", "author_email": "yi.codeplayer@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "A minimal fast protobuf implementation with cython.\nBenchmark shows that it's much faster than google official expremental cpp-python implementation.\n\nI've been using it in production since 2013, only tested with python2.7, feedback on other python release is welcome.\n\nBenchmark\n=========\n\n.. code-block:: bash\n\n $ ./setup.py build_ext --inplace\n $ cd benchmark\n $ ./bench.sh\n encode[google official pure python]:\n 10 loops, best of 3: 68.8 msec per loop\n encode[google official cpp python]:\n 100 loops, best of 3: 19.4 msec per loop\n encode[py-protobuf][cprotobuf]:\n 100 loops, best of 3: 3.58 msec per loop\n decode[google official pure python]:\n 10 loops, best of 3: 47.5 msec per loop\n decode[google official cpp python]:\n 100 loops, best of 3: 4.55 msec per loop\n decode[py-protobuf][cprotobuf]:\n 100 loops, best of 3: 3.98 msec per loop\n\nTutorial\n========\n\nUse plugin\n----------\n\nYou write a ``person.proto`` file like this:\n\n.. code-block:: protobuf\n\n package foo;\n\n message Person {\n required int32 id = 1;\n required string name = 2;\n optional string email = 3;\n }\n\nAnd a ``people.proto`` file like this:\n\n.. code-block:: protobuf\n\n package foo;\n import \"person.proto\";\n\n message People {\n repeated Person people = 1;\n }\n\nThen you compile it with provided plugin:\n\n.. code-block:: bash\n\n $ protoc --cprotobuf_out=. person.proto people.proto\n\nIf you have trouble to run a protobuf plugin like on windows, you can directly run ``protoc-gen-cprotobuf`` like this:\n\n.. code-block:: bash\n\n $ protoc -ofoo.pb person.proto people.proto\n $ protoc-gen-cprotobuf foo.pb -d .\n\nThen you get a python module ``foo_pb.py`` , cprotobuf generate a python module for each package rather than each protocol file.\n\nThe generated code is quite readable:\n\n.. code-block:: python\n\n # coding: utf-8\n from cprotobuf import ProtoEntity, Field\n # file: person.proto\n class Person(ProtoEntity):\n id = Field('int32',\t1)\n name = Field('string',\t2)\n email = Field('string',\t3, required=False)\n\n # file: people.proto\n class People(ProtoEntity):\n people = Field(Person,\t1, repeated=True)\n\nActually, if you only use python, you can write this python module, avoid code generation.\n\nThe API\n-------\n\nNow, you have this lovely python module, how to parse and serialize messages?\n\nWhen design this package, We try to minimise the effort of migration, so we keep the names of api akin to protocol buffer's.\n\n.. note::\n \n Since this is no need to reuse a message instance and call ``Clear`` on it in python, It don't provide ``Clear`` api,\n so ``ParseFromString`` is more like ``MergeFromString`` in official implementation, because it don't call ``Clear`` at first.\n\nencode/decode\n~~~~~~~~~~~~~\n\n.. code-block:: python\n\n >>> from foo_pb import Person, People\n >>> msg = People()\n >>> msg.people.add(\n ... id = 1,\n ... name = 'jim',\n ... email = 'jim@gmail.com',\n ... )\n >>> s = msg.SerializeToString()\n >>> msg2 = People()\n >>> msg2.ParseFromString(s)\n >>> len(msg2)\n 1\n >>> msg2.people[0].name\n 'jim'\n\nreflection\n~~~~~~~~~~\n\n.. code-block:: python\n\n >>> from foo_pb import Person, People\n >>> dir(Person._fields[0])\n ['__class__', '__delattr__', '__doc__', '__format__', '__get__', '__getattribute__', '__hash__', '__init__', '__new__', '__pyx_vtable__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'index', 'name', 'packed', 'repeated', 'required', 'wire_type']\n >>> Person._fields[0].name\n 'email'\n >>> Person._fieldsmap\n {1: , 2: , 3: }\n >>> Person._fieldsmap_by_name\n {'email': , 'name': , 'id': }\n\nrepeated container\n~~~~~~~~~~~~~~~~~~\n\nWe use ``RepeatedContainer`` to represent repeated field, ``RepeatedContainer`` is inherited from ``list``, so you can manipulate it like a ``list``, or with apis like google's implementation.\n\n.. code-block:: python\n\n >>> from foo_pb import Person, People\n >>> msg = People()\n >>> msg.people.add(\n ... id = 1,\n ... name = 'jim',\n ... email = 'jim@gmail.com',\n ... )\n >>> p = msg.people.add()\n >>> p.id = 2\n >>> p.name = 'jake'\n >>> p.email = 'jake@gmail.com'\n >>> p2 = Person(id=3, name='lucy', email='lucy@gmail.com')\n >>> msg.people.append(p2)\n >>> msg.people.append({\n ... 'id' : 4,\n ... 'name' : 'lily',\n ... 'email' : 'lily@gmail.com',\n ... })\n\nencode raw data fast\n~~~~~~~~~~~~~~~~~~~~\n\nIf you already have your messages represented as ``list`` and ``dict``, you can encode it without constructing intermidiate objects, getting ride of a lot of overhead:\n\n.. code-block:: python\n\n >>> from cprotobuf import encode_data\n >>> from foo_pb import Person, People\n >>> s = encode_data(People, [\n ... { 'id': 1, 'name': 'tom', 'email': 'tom@gmail.com' }\n ... ])\n >>> msg = People()\n >>> msg.ParseFromString(s)\n >>> msg.people[0].name\n 'tom'\n\nRun Tests\n=========\n\n.. code-block::\n\n $ nosetests", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/yihuang/cprotobuf", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "cprotobuf", "package_url": "https://pypi.org/project/cprotobuf/", "platform": "", "project_url": "https://pypi.org/project/cprotobuf/", "project_urls": { "Homepage": "https://github.com/yihuang/cprotobuf" }, "release_url": "https://pypi.org/project/cprotobuf/0.1.10/", "requires_dist": null, "requires_python": "", "summary": "pythonic and high performance protocol buffer implementation.", "version": "0.1.10" }, "last_serial": 5870117, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "4619b85e1448476b7c89a067b93ccb3d", "sha256": "a28bb808617c82c57e9e6b0daff68fa3be0acfa372e919a946a3b4f0da88efd1" }, "downloads": -1, "filename": "cprotobuf-0.1.tar.gz", "has_sig": false, "md5_digest": "4619b85e1448476b7c89a067b93ccb3d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 71929, "upload_time": "2014-08-01T03:39:27", "url": "https://files.pythonhosted.org/packages/39/33/d3bf52939681809e9c4eb9a2f453a263f93e19e33b0c575cd50de8a1756a/cprotobuf-0.1.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "dd93e2287ef743152a3f522db4245cba", "sha256": "e32180a5d26d29e4775401001e703b593209620d29992770fa9c87ba5c39eb90" }, "downloads": -1, "filename": "cprotobuf-0.1.1.tar.gz", "has_sig": false, "md5_digest": "dd93e2287ef743152a3f522db4245cba", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 73533, "upload_time": "2014-08-01T03:50:24", "url": "https://files.pythonhosted.org/packages/cc/a0/d9ac723f802fa205371b3e1ee8101f24226161aa540c644f295278ae4267/cprotobuf-0.1.1.tar.gz" } ], "0.1.10": [ { "comment_text": "", "digests": { "md5": "75a839ff19be86e2a96bf5ebecc2fd74", "sha256": "d4883212e930dc2c5c548ec4b7282d4be0ea8785f59aefe35b5b71c4c4c9bb76" }, "downloads": -1, "filename": "cprotobuf-0.1.10.tar.gz", "has_sig": false, "md5_digest": "75a839ff19be86e2a96bf5ebecc2fd74", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14009, "upload_time": "2019-09-22T19:41:58", "url": "https://files.pythonhosted.org/packages/f3/e3/2f196b58155d14a09a72b02d4750720d64e09d92dd0e015ffe05d51a8ea9/cprotobuf-0.1.10.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "991a868c4f294cf6d8805661f3c479d5", "sha256": "f98ffc417f67ce86870ffe5b6e3590ac0a7d68925837e13d179d2fce651ed176" }, "downloads": -1, "filename": "cprotobuf-0.1.2.tar.gz", "has_sig": false, "md5_digest": "991a868c4f294cf6d8805661f3c479d5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11269, "upload_time": "2014-11-05T08:14:06", "url": "https://files.pythonhosted.org/packages/95/cd/0432034eda3e8b63aeaa1d988540ae4fc2b6e9a1af501b8c21877b5d60e6/cprotobuf-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "c2bf4083eca57f5eb5a481999ea03755", "sha256": "b3e3d186756c8deddec71c9331c36f788d9a4ba1c0723fe389205357d96b9f83" }, "downloads": -1, "filename": "cprotobuf-0.1.3.tar.gz", "has_sig": false, "md5_digest": "c2bf4083eca57f5eb5a481999ea03755", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13136, "upload_time": "2014-11-05T08:19:33", "url": "https://files.pythonhosted.org/packages/96/ae/23f1ba9ac82e82e32f278421b03804cee7aade06e8f47c0a1a10df058512/cprotobuf-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "8d4654aad8618d8eb06d1c290252723e", "sha256": "00090bc078070654b8ec8ebb626862ca941b3b4a3e4478ccf8a223a927c739d2" }, "downloads": -1, "filename": "cprotobuf-0.1.4.tar.gz", "has_sig": false, "md5_digest": "8d4654aad8618d8eb06d1c290252723e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13296, "upload_time": "2015-03-31T02:24:21", "url": "https://files.pythonhosted.org/packages/1f/e8/4c661217fde58bedb4f04286cdddde513764b839efaa60eddd75bad67127/cprotobuf-0.1.4.tar.gz" } ], "0.1.5": [ { "comment_text": "", "digests": { "md5": "0a9f9d48c374f641854bc9229c579956", "sha256": "0104fa16e25c628fafa23e78386959aeaeeb40fbcf65a64bf5d49b416b90db52" }, "downloads": -1, "filename": "cprotobuf-0.1.5.tar.gz", "has_sig": false, "md5_digest": "0a9f9d48c374f641854bc9229c579956", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13374, "upload_time": "2015-11-30T03:03:08", "url": "https://files.pythonhosted.org/packages/97/08/579bc528696c46711424b75bce413b7df33c3ce21c09fa3bffa9c75fd8bf/cprotobuf-0.1.5.tar.gz" } ], "0.1.6": [ { "comment_text": "", "digests": { "md5": "fe07cc5cbff6240a5b4f7c13acf0263e", "sha256": "105190793e00f92a535edca6d022912678f9edef0b41bdc8920f9b8478ba95aa" }, "downloads": -1, "filename": "cprotobuf-0.1.6.tar.gz", "has_sig": false, "md5_digest": "fe07cc5cbff6240a5b4f7c13acf0263e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 94470, "upload_time": "2017-12-20T13:41:01", "url": "https://files.pythonhosted.org/packages/4c/aa/2f549fb873401deec063a2e010bf54d3a6db42e5312f8f73286a51d346d4/cprotobuf-0.1.6.tar.gz" } ], "0.1.9": [ { "comment_text": "", "digests": { "md5": "de2de2c21cbba36d2ab8546558394691", "sha256": "7013ab19ba58f6ca1ee14fdfa3213be7d580758a51c82d25ac051966424c196b" }, "downloads": -1, "filename": "cprotobuf-0.1.9.tar.gz", "has_sig": false, "md5_digest": "de2de2c21cbba36d2ab8546558394691", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 96783, "upload_time": "2018-01-11T07:08:43", "url": "https://files.pythonhosted.org/packages/2a/63/0b41cb7adeac8ca491e3fb80dc96478d5087bcb1377016cf3613d8fd0ef6/cprotobuf-0.1.9.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "75a839ff19be86e2a96bf5ebecc2fd74", "sha256": "d4883212e930dc2c5c548ec4b7282d4be0ea8785f59aefe35b5b71c4c4c9bb76" }, "downloads": -1, "filename": "cprotobuf-0.1.10.tar.gz", "has_sig": false, "md5_digest": "75a839ff19be86e2a96bf5ebecc2fd74", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14009, "upload_time": "2019-09-22T19:41:58", "url": "https://files.pythonhosted.org/packages/f3/e3/2f196b58155d14a09a72b02d4750720d64e09d92dd0e015ffe05d51a8ea9/cprotobuf-0.1.10.tar.gz" } ] }