{ "info": { "author": "Kirill Sibirev", "author_email": "l0kix2@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Software Development :: Libraries" ], "description": "python-dehydrate\n================\n.. image:: https://travis-ci.org/l0kix2/python-dehydrate.png?branch=master\n :target: https://travis-ci.org/l0kix2/python-dehydrate?branch=master\n\n.. image:: https://coveralls.io/repos/l0kix2/python-dehydrate/badge.png?branch=master\n :target: https://coveralls.io/r/l0kix2/python-dehydrate?branch=master\n\nSmall lib for representing python objects as a dicts.\n\n\nMotivation\n==========\nWhy would you need library like this? One of obvious use cases is to convert\ncomplex objects with methods, lots of atributes and so on into dicts for\nserializing (into json/yaml/xml/pickle/whatever). You can control\ndehydration process by describing how to fetch values from object and how to\npresent it in dehydrated structure using simple syntax.\n\n\nExamples\n========\nSimple cases\n------------\nIn simplest of possible cases you just want get object, list wanted attributes\nand get mapping with keys based on attribute names and values from them.\nUse ``dehydrate`` shortcut for this case::\n\n >>> from dehydrate import dehydrate\n >>> from pretend import stub as Person\n >>> iron_man = Person(first_name='Tony', login='iron_man')\n >>> dehydrated = dehydrate(obj=iron_man, specs=('first_name', 'login'))\n >>> sorted(dehydrated.items())\n [('first_name', 'Tony'), ('login', 'iron_man')]\n\nSome notes:\n\n- I use list representation of dict in examples because it has predictable\n order of items in it. It's important, because this pieces of code are tests.\n\nIf requested attribute name resolves to method of object, then result of\ncalling it will be set in dehydrated dict. In ``Person`` class we have method\n``full_name``, so let's try to get its return value::\n\n >>> from dehydrate import dehydrate\n >>> from pretend import stub as Person\n >>> iron_man = Person(full_name=lambda: 'Tony Stark')\n >>> dehydrated = dehydrate(obj=iron_man, specs=('full_name',))\n >>> sorted(dehydrated.items())\n [('full_name', 'Tony Stark')]\n\nBut what if you want put ``first_name`` attribute in ``name`` key of resulted\ndict? Just specify both strings in ``specs`` (*spec* can be one object or\ntwo-tuple)::\n\n >>> from dehydrate import dehydrate\n >>> from pretend import stub as Person\n >>> iron_man = Person(first_name='Tony', login='iron_man')\n >>> dehydrated = dehydrate(obj=iron_man, specs=(\n ... ('first_name', 'name'),\n ... 'login',\n ... ))\n >>> sorted(dehydrated.items())\n [('login', 'iron_man'), ('name', 'Tony')]\n\nSecond argument always be used as a key if exists in spec.\n\n\nMore complex cases\n------------------\nSometimes you will want to add some value in dehydrated dict, which is not\nattribute of dehydrated object. Or you may want not use attribute and add some\nanother handling for this element instead. In our example we creating\nspecial class for this called ``PersonDehydrator`` (inherited from\n``dehydrate.Dehydrator``) and set some methods on it::\n\n >>> from pretend import stub as Person\n >>> from examples import PersonDehydrator\n >>> iron_man = Person(password='iRon42', login='iron_man')\n >>> dehydrated = PersonDehydrator(specs=(\n ... 'password',\n ... ('superhero_status', 'is_superhero'),\n ... )).dehydrate(obj=iron_man)\n >>> sorted(dehydrated.items())\n [('is_superhero', True), ('password', '******')]\n\nIn example you can see, that object has ``password`` attribute, but\n``PersonDehydrator``'s ``get_password`` used for ``password`` spec. Also you can\nmention, that result of calling ``get_superhero_status`` was set in key\n``is_superhero`` because of second item in spec was declared.\nYou can declare ``specs`` using attribute of dehydrator class\nor by passing argument into its ``__init__`` method.\n\nNotes:\n\n- In docs I will refer to ``examples`` package, which you can find in repo.\n\n\nRecursive dehydration\n---------------------\nThe most valuable feature of lib is that you can describe how to recursively\ndehydrate complex fields on object::\n\n >>> from dehydrate import dehydrate, S\n >>> from pretend import stub as Person\n >>> from examples import PersonDehydrator\n >>> octopus = Person(login='octopus')\n >>> spider_man = Person(login='spidey', archenemy=octopus)\n >>> dehydrated = dehydrate(\n ... specs=(\n ... S('login'),\n ... S(target='archenemy', type='nested', specs=(\n ... S('login'),\n ... )),\n ... ),\n ... obj=spider_man\n ... )\n >>> dehydrated['login']\n 'spidey'\n >>> list(dehydrated['archenemy'].items())\n [('login', 'octopus')]\n\nYou can see, that specs for nested elements are described with use of\n``dehydrate.S`` shortcut (And simple specs as well for the sake of sanity).\nAcceptable arguments are for ``type='nested'``:\n\n- ``target`` \u2014 name, that describes how to get value from object (or use hook\n on dehydrator)\n- ``dehydrator`` \u2014 class, which can be used for dehydrating of complex target\n (``dehydrate.Dehydrator`` by default).\n- ``specs`` \u2014 iterable of same structure as described above (it is optional\n in case if you describe specs on dehydrator class, but make good sense,\n if you ant use default ``Dehydrator`` class).\n\n\nInstallation\n============\nSimple::\n\n pip install dehydrate\n\nmust be fine.\n\nRequirements\n------------\n* six (did I mentioned python 3 support? We have one.)\n\n\nPhilosophy\n==========\n* Easy things should be done easily.\n* Complex things must be possible.\n\n\nTesting\n=======\nTest written with use of `pytest`_ library and neat `pytest pep8 plugin`_.\nYou should run ``python setup.py test`` for running full test suite or\n``coverage run --source=dehydrate setup.py test`` for tests with coverage.\nTests automatically runs at `Travis CI`_. Examples in documentation are also\npicked by test command.\n\n.. _pytest: http://pytest.org/\n.. _pytest pep8 plugin: https://pypi.python.org/pypi/pytest-pep8\n.. _Travis CI: https://travis-ci.org/l0kix2/python-dehydrate?branch=master\n\n\nContribution\n============\nAny contribution is welcome. Use fork/pull request mechanism on github.\n\nIf you add some code, you should add some tests, so coverage of master branch\nshould always be 100%. Refer to Testing_ section for more instructions.\n\nLet me speak from my heart :). I will be very glad, if you correct my clumsy\nenglish phrases in docs and docstings or even advise more appropriate names\nfor variables in code.\n\n\nTODO\n====\n* Think about giving opportunity to put results in Ordered dict instead of \n simple dict.\n* Add comprehensive docs about everything.\n* Move complex examples with classes into docs from readme.\n* Write docstrings and auto-generate some additional docs.\n\n\n\nChangelog\n=========\n0.3 (2013-07-07)\n----------------\n* New syntax for nested dehydration\n\n0.2 (2013-06-19)\n----------------\n* fields parameter renamed to specs\n* improved README", "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/l0kix2/python-dehydrate", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "dehydrate", "package_url": "https://pypi.org/project/dehydrate/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/dehydrate/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/l0kix2/python-dehydrate" }, "release_url": "https://pypi.org/project/dehydrate/0.3.7/", "requires_dist": null, "requires_python": null, "summary": "Small lib for representing python objects as a dicts", "version": "0.3.7" }, "last_serial": 939623, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "74af689884b052edb1e80ee933473fcc", "sha256": "8249388cc959f2edc7b9e7fd5cfa25a109ea6a67368c057a9480564acadd7e0e" }, "downloads": -1, "filename": "dehydrate-0.1.tar.gz", "has_sig": false, "md5_digest": "74af689884b052edb1e80ee933473fcc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7334, "upload_time": "2013-06-12T16:48:28", "url": "https://files.pythonhosted.org/packages/bc/e0/9f521bda5a1e80aa2edec4521a36dbe7a3bae4665497f9665ba3f5b94d50/dehydrate-0.1.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "16ed781bcd1c477218b4f1821bac7795", "sha256": "c5ae45acba6f80273d07f40030300975a11ed51eb48a2f172c77a4fe5f90ca64" }, "downloads": -1, "filename": "dehydrate-0.1.1.tar.gz", "has_sig": false, "md5_digest": "16ed781bcd1c477218b4f1821bac7795", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8726, "upload_time": "2013-06-13T20:36:39", "url": "https://files.pythonhosted.org/packages/de/87/904ac3d8cf5adff72790b476498ecc599a3601276fbda99ced257da722ee/dehydrate-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "b655305b3eb9284b420e46b7e76d7f8c", "sha256": "fd5b3bf81775b2460e73374cb2ed4cc8990851377f107173900976672570b5bc" }, "downloads": -1, "filename": "dehydrate-0.1.2.tar.gz", "has_sig": false, "md5_digest": "b655305b3eb9284b420e46b7e76d7f8c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8828, "upload_time": "2013-06-18T18:23:12", "url": "https://files.pythonhosted.org/packages/e8/73/1e1abb273016373e82272bf62127b39e3bbe1f0e02f2a2c820ab80651d74/dehydrate-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "ebb7a120cbb1f0af5a30085398331ff5", "sha256": "d809903b9d9db5978748a949c8aad172452efe2906dd41335884f902efb24c7c" }, "downloads": -1, "filename": "dehydrate-0.1.3.tar.gz", "has_sig": false, "md5_digest": "ebb7a120cbb1f0af5a30085398331ff5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8855, "upload_time": "2013-06-18T18:30:58", "url": "https://files.pythonhosted.org/packages/c7/e6/31b5afab3075f05aaf9dff30e0adb8783de9c6991eb06373b622f641120e/dehydrate-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "b70ee553236c9f9d6d53618823fc0c47", "sha256": "7446e19bd14566237c6088b07dd5cf46dd01970f927338a7682d250ec960cc6a" }, "downloads": -1, "filename": "dehydrate-0.1.4.tar.gz", "has_sig": false, "md5_digest": "b70ee553236c9f9d6d53618823fc0c47", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8859, "upload_time": "2013-06-18T18:48:28", "url": "https://files.pythonhosted.org/packages/a5/27/beb30c9e33584f2643272c01d57b3e4e455575b42caa7c6e51c1e109c919/dehydrate-0.1.4.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "5c263e490010d416fa0e14016547e953", "sha256": "de88acda4eb558999e5689a0c9915b678ed081a9a85eefb451c84475d172fedf" }, "downloads": -1, "filename": "dehydrate-0.2.0.tar.gz", "has_sig": false, "md5_digest": "5c263e490010d416fa0e14016547e953", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6671, "upload_time": "2013-06-19T16:20:18", "url": "https://files.pythonhosted.org/packages/45/d9/2dcce56b142cfe7d2c97f83f7686edc9dcdfe9965602d77ae59312cab0c7/dehydrate-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "bf8dae8db5978c14e90116d6480e35a7", "sha256": "bcf2e8b2c65f17c68e36eef5f44b30f95fc0eea8ca60a3424fbf3ce907a18615" }, "downloads": -1, "filename": "dehydrate-0.2.1.tar.gz", "has_sig": false, "md5_digest": "bf8dae8db5978c14e90116d6480e35a7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6648, "upload_time": "2013-06-20T09:33:11", "url": "https://files.pythonhosted.org/packages/49/aa/7eef8efdcebcd371db26acff64a63c702a8d6613e573c2d87e7c6a11ad6e/dehydrate-0.2.1.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "5056e82499d5516d67b111b588557e82", "sha256": "6f23179edb92cd74610db950ed6cb0a24a501a232bfb176faef36966863e11a6" }, "downloads": -1, "filename": "dehydrate-0.3.0.tar.gz", "has_sig": false, "md5_digest": "5056e82499d5516d67b111b588557e82", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6859, "upload_time": "2013-07-07T16:12:46", "url": "https://files.pythonhosted.org/packages/90/c9/908634117e9721fb72a2a3739da8d3b6eb8a72e24f5d4b01ddaf6cc32c20/dehydrate-0.3.0.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "29928266c0be2b0155de637434027b91", "sha256": "842fee231c436858586f123ac049ffa103342df57703bd6395573f88d83464e3" }, "downloads": -1, "filename": "dehydrate-0.3.1.tar.gz", "has_sig": false, "md5_digest": "29928266c0be2b0155de637434027b91", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6896, "upload_time": "2013-07-07T16:15:35", "url": "https://files.pythonhosted.org/packages/c6/c9/0ca0fe3a090ec6627db2d208c47646ce702a3d030464aadebcd0eae58d37/dehydrate-0.3.1.tar.gz" } ], "0.3.2": [ { "comment_text": "", "digests": { "md5": "59c53710a920023ea9b48700e5a8632d", "sha256": "238f2f0d28a75046843828f0fd67fb3d86c7eefa5ec11b4a382f8916820eb2b2" }, "downloads": -1, "filename": "dehydrate-0.3.2.tar.gz", "has_sig": false, "md5_digest": "59c53710a920023ea9b48700e5a8632d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6911, "upload_time": "2013-07-08T15:14:08", "url": "https://files.pythonhosted.org/packages/da/a3/48ee61b17d5f4d078d315fa949dd828733d4c33901023d9a8507ab714039/dehydrate-0.3.2.tar.gz" } ], "0.3.3": [ { "comment_text": "", "digests": { "md5": "4ec184f1d4fbdcf0786bccf309ea137f", "sha256": "aee81eaa44c880602e748377b033bae43fec12c85fa4f76478eba7ba67a24a5c" }, "downloads": -1, "filename": "dehydrate-0.3.3.tar.gz", "has_sig": false, "md5_digest": "4ec184f1d4fbdcf0786bccf309ea137f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6950, "upload_time": "2013-07-08T18:14:02", "url": "https://files.pythonhosted.org/packages/21/a8/bc4fca324404848cea36214a5fd01b465d3607d63d66f201d9e78910b0e3/dehydrate-0.3.3.tar.gz" } ], "0.3.4": [ { "comment_text": "", "digests": { "md5": "61915a404242a5bd5e9789db19d0c3a4", "sha256": "1e58ad6856a9c9d54403455a0f99e3d8e7ec0ebf682b02b7db6b68d075822090" }, "downloads": -1, "filename": "dehydrate-0.3.4.tar.gz", "has_sig": false, "md5_digest": "61915a404242a5bd5e9789db19d0c3a4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7005, "upload_time": "2013-07-09T06:33:55", "url": "https://files.pythonhosted.org/packages/d0/9a/45bd5f9d241ed35e21de05ca32d323e4ba430d6b448a3f746685becf5ff5/dehydrate-0.3.4.tar.gz" } ], "0.3.5": [ { "comment_text": "", "digests": { "md5": "d1787f32dad975f0bbfe79be887f7d74", "sha256": "cd2df34c3a756391eb7093a1c6c9c6d93e6020be24adfbd16bdf0fea5a308756" }, "downloads": -1, "filename": "dehydrate-0.3.5.tar.gz", "has_sig": false, "md5_digest": "d1787f32dad975f0bbfe79be887f7d74", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6939, "upload_time": "2013-07-09T06:51:42", "url": "https://files.pythonhosted.org/packages/3f/23/9b480665c14cbd45be59c254ba55cee5aab5d42b11330fdf4edf5cc49cd1/dehydrate-0.3.5.tar.gz" } ], "0.3.6": [ { "comment_text": "", "digests": { "md5": "de46723a7635be627ac650cd7f19c30e", "sha256": "6441a1ea86c24ab7360a7cc2ed671b30db7e8030bac106e3978bb3e79a105911" }, "downloads": -1, "filename": "dehydrate-0.3.6.tar.gz", "has_sig": false, "md5_digest": "de46723a7635be627ac650cd7f19c30e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6979, "upload_time": "2013-10-30T11:02:03", "url": "https://files.pythonhosted.org/packages/8a/ca/93a8d3de4150fe4ba4f3ba7952ce61fc802cc31384ee50415646ed063cfc/dehydrate-0.3.6.tar.gz" } ], "0.3.7": [ { "comment_text": "", "digests": { "md5": "cd185c4348b49406850c9f6bdf59bacd", "sha256": "b80785fcc04b695f968888f69bfdeb45a2a97fe91de5cdb06a8742d724b9edfe" }, "downloads": -1, "filename": "dehydrate-0.3.7.tar.gz", "has_sig": false, "md5_digest": "cd185c4348b49406850c9f6bdf59bacd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6995, "upload_time": "2013-12-09T08:27:48", "url": "https://files.pythonhosted.org/packages/8d/b5/f4bf63eea2e563fc91feae07544ea35d987a523d1e9e2cd9cb346da87f17/dehydrate-0.3.7.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "cd185c4348b49406850c9f6bdf59bacd", "sha256": "b80785fcc04b695f968888f69bfdeb45a2a97fe91de5cdb06a8742d724b9edfe" }, "downloads": -1, "filename": "dehydrate-0.3.7.tar.gz", "has_sig": false, "md5_digest": "cd185c4348b49406850c9f6bdf59bacd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6995, "upload_time": "2013-12-09T08:27:48", "url": "https://files.pythonhosted.org/packages/8d/b5/f4bf63eea2e563fc91feae07544ea35d987a523d1e9e2cd9cb346da87f17/dehydrate-0.3.7.tar.gz" } ] }