{ "info": { "author": "L\u00e9o Flaventin Hauchecorne", "author_email": "hl037.prog@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3 :: Only", "Topic :: Communications", "Topic :: Internet" ], "description": "lightprotobuf\n=======================\n\nIntroduction\n------------\n\nlightprotobuf is a full Python 3 implementation of the Protocol Buffers as described by Google.\n\nDocumentation\n=============\n\nThe main class to use is lightprotobuf.Message\n\nIt must be the base class of every messages you define. The rest follows the .proto design:\n\nThis message::\n\n enum FooEnum {\n FIELD = 5;\n FIELD2 = 6;\n }\n \n message FooMsg {\n required int32 foo_field = 1;\n optional FooEnum foo_enum = 2;\n enum BarEnum {\n FIELD = 5;\n BAR = 6;\n }\n required BarEnum bar_enum = 3;\n repeated string foo_rep = 4;\n repeated int32 foo_pak = 5 [packed=true];\n }\n \n message BarMsg {\n required FooMsg.BarEnum bar_enum = 1;\n }\n\n\nIs translated in python to::\n\n from enum import IntEnum\n from lightprotobuf import *\n class FooEnum(IntEnum):\n \tFIELD = 5\n \tFIELD2 = 6\n \n class FooMsg(Message):\n \tclass BarEnum(IntEnum):\n \t\tFIELD = 5\n \t\tBAR = 6\n \tfoo_field = Field(1, Int32, Field.REQUIRED, **{})\n \tbar_enum = Field(3, BarEnum, Field.REQUIRED, **{})\n \tfoo_enum = Field(2, FooEnum, Field.OPTIONAL, **{})\n \n class BarMsg(Message):\n \tbar_enum = Field(1, FooMsg.BarEnum, Field.REQUIRED, **{})\n\n\nAs you can see, the fields follow this template ::\n\n = Field(, , Field., **{}\n\nEnums are python's ``enum.IntEnum``\n\nNested types are real python nested types referenced just like in .proto\n\nAPI\n---\n\nThe fields are actually transformed as attributes via descriptors. So you can access fields easily::\n\n m = FooMsg()\n m.foo_field = 5\n m.foo_field # returns 5\n m.foo_enum = 5 # Error because it expects a FooEnum object\n m.foo_enum = FooEnum.FIELD # OK\n m.bar_enum = FooMsg.BarEnum.BAR # OK\n\nRepeated fields atc like a list::\n\n m.foo_rep = [\"a string\", \"another\"] # OK\n li = m.foo_rep # Get a reference to the list\n li.append(\"a string\") # OK, append the string\n li.append(b'a bytes') # TypeError because there is a check to avoid mistakes\n\n\nNote : packed fields are able to decode either data packed either multiple occurence of the field e.g. the test case::\n\n\t\tclass Repeated(Message):\n\t\t\tr = Field(1, Int32, Field.REPEATED, packed=\"True\")\n\t\tnb = [1,150,1,2,3,150]\n\t\tb = io.BytesIO(b'\\x0C\\x08\\x01\\x08\\x96\\x01\\x0A\\x05\\x01\\x02\\x03\\x96\\x01')\n\t\tm = Repeated.from_stream(b)\n\t\tself.assertEqual(list(m.r), nb)\n\t\t# 0C (12) bytes following\n\t\t# 08 = 1 << 3 | 0\n\t\t# varints etc.\n\t\t# 0A = 1 << 3 | 2\n\t\t# 05 bytes following\n\t\t# concatened varints etc.\n\n\nTo encode a message, lightprotobuf uses stream objects : each DataType has a ``to_stream`` and ``from_stream`` class method. Just to call it from a message to encode/decode a message::\n\n import io\n s = io.BytesIO()\n Message.to_stream(s, m)\n s.getvalue() # b'\\x06\\x08\\x05\\x10\\x05\\x18\\x06'\n\n m = FooMsg()\n s = io.BytesIO(b'\\x06\\x08\\x05\\x10\\x05\\x18\\x06')\n m = Message.from_stream(s)\n \n_Note_ : if required field is missing, it raises a FieldNotOptional exception\n\nRelease Notes\n=============\n\n1.0.b3\n------\n\n- WARNING : module moved at top-level. Use `import lightprotobuf` rather than `from lightprotobuf import lightprotobuf`\n- Add support for repeated fields, packed and not packed\n\n1.0.b2\n------\n\n- Remove DESCRIPTION.rst because duplicate of README.rst", "description_content_type": null, "docs_url": null, "download_url": null, "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/hl037/lightprotobuf", "keywords": "protobuf protocol buffers communication", "license": "LGPL3", "maintainer": null, "maintainer_email": null, "name": "lightprotobuf", "package_url": "https://pypi.org/project/lightprotobuf/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/lightprotobuf/", "project_urls": { "Homepage": "https://github.com/hl037/lightprotobuf" }, "release_url": "https://pypi.org/project/lightprotobuf/1.0b5/", "requires_dist": null, "requires_python": null, "summary": "A light full Python3 Protocol Buffers implementation", "version": "1.0b5" }, "last_serial": 1530070, "releases": { "1.0b0": [], "1.0b1": [ { "comment_text": "", "digests": { "md5": "a872044e56cafddec4fbe38a34f1914d", "sha256": "e069c1ff40e065e6f561892f5740fa919bd8f53dc7ddd86b2ae4604e29cad919" }, "downloads": -1, "filename": "lightprotobuf-1.0b1-py3-none-any.whl", "has_sig": false, "md5_digest": "a872044e56cafddec4fbe38a34f1914d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8262, "upload_time": "2015-03-03T21:27:30", "url": "https://files.pythonhosted.org/packages/80/8d/09af3650b16b0cf8d22d1c232ba3970061daeb16cf6549241e8f8fe766d2/lightprotobuf-1.0b1-py3-none-any.whl" } ], "1.0b3": [ { "comment_text": "", "digests": { "md5": "bcdf6becd5d296c68549afd0cb66c215", "sha256": "87f33b3638bc812adbf92a0c8fd1969580627f8e42488a3b58dde7ccb00e30c8" }, "downloads": -1, "filename": "lightprotobuf-1.0b3.tar.gz", "has_sig": false, "md5_digest": "bcdf6becd5d296c68549afd0cb66c215", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4021, "upload_time": "2015-04-13T00:24:50", "url": "https://files.pythonhosted.org/packages/ae/c6/4564cbc332e84eb5c336abd1fbedeff195f9c6af8abc87e7b4566e17feb9/lightprotobuf-1.0b3.tar.gz" } ], "1.0b4": [ { "comment_text": "", "digests": { "md5": "9047a161a0efa962c9a582e5ce1e7acf", "sha256": "4463da10fc2a17e2371e87182af43fb4935e08564d2519fb965c00aa03e3cdd7" }, "downloads": -1, "filename": "lightprotobuf-1.0b4.tar.gz", "has_sig": false, "md5_digest": "9047a161a0efa962c9a582e5ce1e7acf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7398, "upload_time": "2015-05-02T01:56:23", "url": "https://files.pythonhosted.org/packages/f8/4a/958055cca167f95a248a24fdc57425f8417326f1c34b6d457f2bee6cebe3/lightprotobuf-1.0b4.tar.gz" } ], "1.0b5": [ { "comment_text": "", "digests": { "md5": "ab167dfe7303f24f5820cc6a8c8becb3", "sha256": "cf15f097cb471b8b510ef3890bb32ae3a9bc18b777c091013b8b5822fd019a35" }, "downloads": -1, "filename": "lightprotobuf-1.0b5.tar.gz", "has_sig": false, "md5_digest": "ab167dfe7303f24f5820cc6a8c8becb3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7389, "upload_time": "2015-05-02T02:00:00", "url": "https://files.pythonhosted.org/packages/bd/12/043a8d2f33bca80173e08030059eb10fd189e2c08e2af5cfee3fa7469d03/lightprotobuf-1.0b5.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "ab167dfe7303f24f5820cc6a8c8becb3", "sha256": "cf15f097cb471b8b510ef3890bb32ae3a9bc18b777c091013b8b5822fd019a35" }, "downloads": -1, "filename": "lightprotobuf-1.0b5.tar.gz", "has_sig": false, "md5_digest": "ab167dfe7303f24f5820cc6a8c8becb3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7389, "upload_time": "2015-05-02T02:00:00", "url": "https://files.pythonhosted.org/packages/bd/12/043a8d2f33bca80173e08030059eb10fd189e2c08e2af5cfee3fa7469d03/lightprotobuf-1.0b5.tar.gz" } ] }