{ "info": { "author": "Hernan E. Grecco", "author_email": "hernan.grecco@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Intended Audience :: End Users/Desktop", "License :: OSI Approved :: BSD License", "Operating System :: MacOS :: MacOS X", "Operating System :: Microsoft :: Windows", "Operating System :: POSIX", "Programming Language :: Python", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Topic :: Software Development :: Libraries" ], "description": "Serialize: A common Python API for multiple serialization formats\r\n=================================================================\r\n\r\nThere are multiple serialization formats out there ...\r\n ... and great packages to use them.\r\n\r\nBut they all have a different API and switching among them is not so simple\r\nas it should be. Serialize helps you to do it, including dealing with custom\r\nclasses. Let's dump a dict using the `pickle` format:\r\n\r\n.. code:: python\r\n\r\n >>> from serialize import dumps, loads\r\n >>> dumps(dict(answer=42), fmt='pickle')\r\n b'\\x80\\x03}q\\x00X\\x06\\x00\\x00\\x00answerq\\x01K*s.'\r\n >>> loads(_, fmt='pickle')\r\n {'answer': 42}\r\n\r\nAnd here comes the cool thing, you can just change the serialization format\r\nwithout having to learn a new API. Let's now dump it using msgpack:\r\n\r\n.. code:: python\r\n\r\n >>> dumps(dict(answer=42), fmt='msgpack')\r\n b'\\x81\\xa6answer*'\r\n >>> loads(_, fmt='msgpack')\r\n {'answer': 42}\r\n\r\nSerialize currently support 8 different formats: `bson`, `dill`, `json`, `msgpack`,\r\n`phpserialize`, `pickle`, `serpent` and `yaml`. Serialize does not implement these\r\nformats but rather relies on established, well tested packages. If they are installed,\r\nserialize will use them.\r\n\r\n ** Serialize allows you to use them all with the same API! **\r\n\r\nYou can also use the `dump` and `load` to write directly to file-like object:\r\n\r\n.. code:: python\r\n\r\n >>> from serialize import dump, load\r\n >>> with open('output.yaml', 'wb') as fp:\r\n ... dump(dict(answer=42), fp, fmt='yaml')\r\n >>> with open('output.yaml', 'rb') as fp:\r\n ... load(fp, fmt='yaml')\r\n {'answer': 42}\r\n\r\nor use directly the filename and the format will be inferred:\r\n\r\n.. code:: python\r\n\r\n >>> dump(dict(answer=42), 'output.yaml')\r\n >>> load('output.yaml')\r\n {'answer': 42}\r\n\r\nA very common case is to dump and load objects from custom classes such as:\r\n\r\n.. code:: python\r\n\r\n >>> class User:\r\n ... def __init__(self, name, age):\r\n ... self.name = name\r\n ... self.age = age\r\n ...\r\n >>> john = User('John Smith', 27)\r\n\r\n\r\nBut some serialization packages do not support this important feature and the\r\nrest usually have very different API between them. Serialize provides\r\nyou a common, simple interface for this. You just need to define a function\r\nthat is able to convert the object to an instance of a builtin type and the\r\nconverse:\r\n\r\n.. code:: python\r\n\r\n >>> from serialize import register_class\r\n >>> def user_to_builtin(u):\r\n ... return (u.name, u.age)\r\n ...\r\n >>> def user_from_builtin(c):\r\n ... return User(c[0], c[1])\r\n ...\r\n\r\n >>> register_class(User, user_to_builtin, user_from_builtin)\r\n\r\n\r\nAnd that's all. You can then use it directly without any hassle:\r\n\r\n.. code:: python\r\n\r\n >>> dumps(john, fmt='bson')\r\n b\"y\\x00\\x00\\x00\\x03__bson_follow__\\x00c\\x00\\x00\\x00\\x04\r\n __dumped_obj__\\x00\\x1e\\x00\\x00\\x00\\x020\\x00\\x0b\\x00\\x00\r\n \\x00John Smith\\x00\\x101\\x00\\x1b\\x00\\x00\\x00\\x00\\x02__class_name__\r\n \\x00\\x1c\\x00\\x00\\x00\\x00\\x00\\x00\"\r\n >>> v = loads(_, fmt='bson')\r\n >>> v.name\r\n 'John Smith'\r\n >>> v.age\r\n 27\r\n\r\n\r\nEnjoy!\r\n\r\n\r\n\r\nSerialize is written and maintained by Hernan E. Grecco .\r\n\r\n\r\nSerialize Changelog\r\n===================\r\n\r\n\r\n0.1 (2016-01-28)\r\n----------------\r\n- Initial Release. Implement a generic dump/dumps and load/loads.\r\n- Added support for registering new serializer/deserializer.\r\n- Added support for registering custom classes.\r\n- Format inference for file extension.\r\n- Added support for bson using https://pypi.python.org/pypi/bson\r\n- Added support for dill using https://pypi.python.org/pypi/dill\r\n- Added support for json using https://docs.python.org/3/library/json.html\r\n- Added support for msgpack using https://pypi.python.org/pypi/msgpack-python\r\n- Added support for phpserialize using https://pypi.python.org/pypi/phpserialize\r\n- Added support for pickle using https://docs.python.org/3/library/pickle.html\r\n- Added support for serpent using https://pypi.python.org/pypi/serpent\r\n- Added support for yaml using https://pypi.python.org/pypi/pyyaml", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/hgrecco/serialize", "keywords": "serialization deserialization packing unpacking", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "Serialize", "package_url": "https://pypi.org/project/Serialize/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/Serialize/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/hgrecco/serialize" }, "release_url": "https://pypi.org/project/Serialize/0.1/", "requires_dist": null, "requires_python": null, "summary": "A common API for multiple serialization formats with support for custom classes", "version": "0.1" }, "last_serial": 1928488, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "a0b2f3da2772a7699d1a668c15290588", "sha256": "b3d6effdd3651067712a6b9d8b21fdee30ef7cd524f1597d8acc26b0250b94ad" }, "downloads": -1, "filename": "Serialize-0.1.tar.gz", "has_sig": false, "md5_digest": "a0b2f3da2772a7699d1a668c15290588", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12222, "upload_time": "2016-01-29T02:56:37", "url": "https://files.pythonhosted.org/packages/7a/63/edc2f11c62301f4b4512367df32217826101d87bb4faa0d0931c11fae8eb/Serialize-0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a0b2f3da2772a7699d1a668c15290588", "sha256": "b3d6effdd3651067712a6b9d8b21fdee30ef7cd524f1597d8acc26b0250b94ad" }, "downloads": -1, "filename": "Serialize-0.1.tar.gz", "has_sig": false, "md5_digest": "a0b2f3da2772a7699d1a668c15290588", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12222, "upload_time": "2016-01-29T02:56:37", "url": "https://files.pythonhosted.org/packages/7a/63/edc2f11c62301f4b4512367df32217826101d87bb4faa0d0931c11fae8eb/Serialize-0.1.tar.gz" } ] }