{ "info": { "author": "Sebastian Heimann", "author_email": "sebastian.heimann@gfz-potsdam.de", "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", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "\nGuts\n====\n \nLightweight declarative YAML and XML data binding for Python\n\nGuts is written by Sebastian Heimann . It is\nreleased under the MIT license. See the file LICENSE for more details.\n\nPrerequisites\n-------------\n\n * PyYAML: Download it from http://pyyaml.org/wiki/PyYAML and follow the given\n installation instructions or install it through your system's package\n manager (e.g. the `python-yaml` package on Debian based Linuxes).\n\nUsage\n-----\n\nA file `playlist.py` might look like:\n\n```python\nfrom guts import *\n\nclass Song(Object):\n name = String.T()\n album = String.T(default='')\n artist = String.T(default='')\n year = Int.T(optional=True)\n\nclass Playlist(Object):\n xmltagname = 'playlist'\n name = String.T(default='Untitled Playlist')\n comment = String.T(optional=True)\n song_list = List.T(Song.T())\n```\n\nThese classes come with automatic `__init__`:\n\n```pycon\n>>> from playlist import *\n>>> song1 = Song(name='Metropolis', artist='Kraftwerk')\n>>> song2 = Song(name='I Robot', artist='The Alan Parsons Project', album='I Robot')\n>>> playlist = Playlist(song_list=[song1,song2])\n```\n\nThey serialize to YAML:\n\n```pycon\n>>> print song1.dump()\n--- !playlist.Song\nname: Metropolis\nartist: Kraftwerk\n```\n\nThey also serialize to XML:\n\n```pycon\n>>> print playlist.dump_xml()\n\n Untitled Playlist\n \n Metropolis\n Kraftwerk\n \n \n I Robot\n I Robot\n The Alan Parsons Project\n \n\n```\n\nObjects can validate themselves:\n\n```pycon\n>>> song1.validate()\n>>> song2.year = 1977\n>>> song2.validate()\n>>> song2.year = 'abc'\n>>> song2.validate()\nTraceback (most recent call last):\n...\nguts.ValidationError: year: \"abc\" is not of type int\n```\n\nObjects can regularize themselves:\n\n```pycon\n>>> song2.year = '1977'\n>>> song2.regularize()\n>>> song2.year\n1977\n>>> type(song2.year)\n\n```\n\nThey also deserialize from YAML and XML:\n\n```pycon\n>>> playlist2 = load_string(playlist.dump())\n>>> playlist3 = load_xml_string(playlist.dump_xml())\n```\n\nIncremental loading of large YAML or XML files is supported with the\n`guts.iload_all()` and `guts.iload_all_xml()` functions, which are buildt to\nreturn generators yielding Guts objects.\n\nThis module comes with a rudimentary code generator `xmlschema-to-guts` to turn\n(some) XML Schema definitions (XSD) into Python modules containing Guts class\nhierarchies. \n\nHere is an example using the first example in the W3C XML Schema Primer. The\nSchema shall be defined in `po.xsd`:\n\n```xml\n\n\n \n \n Purchase order schema for Example.com.\n Copyright 2000 Example.com. All rights reserved.\n \n \n\n \n\n \n\n \n \n \n \n \n \n \n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n \n \n \n \n \n \n\n\n```\n\nA corresponding XML file `po.xml` might look like this:\n\n```xml\n\n\n \n Alice Smith\n 123 Maple Street\n Mill Valley\n CA\n 90952\n \n \n Robert Smith\n 8 Oak Avenue\n Old Town\n PA\n 95819\n \n Hurry, my lawn is going wild\n \n \n Lawnmower\n 1\n 148.95\n Confirm this is electric\n \n \n Baby Monitor\n 1\n 39.98\n 1999-05-21\n \n \n\n```\n\nUsing the Guts code generator \n\n```bash\n$ xmlschema-to-guts po.xsd > po.py\n```\n\nwill produce a Python module `po.py`:\n\n```python\nfrom guts import *\n\nclass SKU(StringPattern):\n pattern = '\\\\d{3}-[A-Z]{2}'\n\n\nclass Comment(String):\n xmltagname = 'comment'\n\n\nclass Quantity(Int):\n pass\n\n\nclass USAddress(Object):\n country = String.T(default='US', optional=True, xmlstyle='attribute')\n name = String.T()\n street = String.T()\n city = String.T()\n state = String.T()\n zip = Float.T()\n\n\nclass Item(Object):\n part_num = SKU.T(xmlstyle='attribute')\n product_name = String.T()\n quantity = Quantity.T()\n us_price = Float.T(xmltagname='USPrice')\n comment = Comment.T(optional=True)\n ship_date = DateTimestamp.T(optional=True)\n\n\nclass Items(Object):\n item_list = List.T(Item.T())\n\n\nclass PurchaseOrderType(Object):\n order_date = DateTimestamp.T(optional=True, xmlstyle='attribute')\n ship_to = USAddress.T()\n bill_to = USAddress.T()\n comment = Comment.T(optional=True)\n items = Items.T()\n\n\nclass PurchaseOrder(PurchaseOrderType):\n xmltagname = 'purchaseOrder'\n```\n\nAnd we can use it e.g. to parse the example XML file `po.xml` from above:\n\n```pycon\n>>> from po import *\n>>> order = load_xml(filename='po.xml')\n>>> print order # dumps YAML\n--- !po.PurchaseOrder\norder_date: '1999-10-20'\nship_to: !po.USAddress\n name: Alice Smith\n street: 123 Maple Street\n city: Mill Valley\n state: CA\n zip: 90952.0\nbill_to: !po.USAddress\n name: Robert Smith\n street: 8 Oak Avenue\n city: Old Town\n state: PA\n zip: 95819.0\ncomment: Hurry, my lawn is going wild\nitems: !po.Items\n item_list:\n - !po.Item\n part_num: 872-AA\n product_name: Lawnmower\n quantity: 1\n us_price: 148.95\n comment: Confirm this is electric\n - !po.Item\n part_num: 926-AA\n product_name: Baby Monitor\n quantity: 1\n us_price: 39.98\n ship_date: '1999-05-21'\n```\n\n", "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/emolch/guts/", "keywords": "data-binding,xml,yaml", "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "guts", "package_url": "https://pypi.org/project/guts/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/guts/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/emolch/guts/" }, "release_url": "https://pypi.org/project/guts/0.2/", "requires_dist": null, "requires_python": null, "summary": "Lightweight declarative YAML and XML data binding for Python.", "version": "0.2" }, "last_serial": 907309, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "9efb14498cb68c53b526ba8b9e82fa19", "sha256": "4f4ede13a5f540cb6377fa282764e3d4ab69821ca7d6b83ad70a8053efb53509" }, "downloads": -1, "filename": "guts-0.1.tar.gz", "has_sig": false, "md5_digest": "9efb14498cb68c53b526ba8b9e82fa19", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18292, "upload_time": "2013-01-31T15:07:09", "url": "https://files.pythonhosted.org/packages/d6/0e/8f81252315dbb932784e65f68d93eee91876213a827270aa536d7d0f4527/guts-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "dc93209f3036a62172c79eb4de2ecd6a", "sha256": "9ed5bb05989e5805ccbcccf66fb10808d38d409fc504ea281d6174de0b0fc058" }, "downloads": -1, "filename": "guts-0.2.tar.gz", "has_sig": false, "md5_digest": "dc93209f3036a62172c79eb4de2ecd6a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19634, "upload_time": "2013-10-30T13:08:00", "url": "https://files.pythonhosted.org/packages/a8/9c/5f82b18693fbf05b887a447022163e044e8cf66c4f8ce5699cce28bf4433/guts-0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "dc93209f3036a62172c79eb4de2ecd6a", "sha256": "9ed5bb05989e5805ccbcccf66fb10808d38d409fc504ea281d6174de0b0fc058" }, "downloads": -1, "filename": "guts-0.2.tar.gz", "has_sig": false, "md5_digest": "dc93209f3036a62172c79eb4de2ecd6a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19634, "upload_time": "2013-10-30T13:08:00", "url": "https://files.pythonhosted.org/packages/a8/9c/5f82b18693fbf05b887a447022163e044e8cf66c4f8ce5699cce28bf4433/guts-0.2.tar.gz" } ] }