{ "info": { "author": "Johan Egneblad", "author_email": "johan@DELETEMEegneblad.se", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": ".. image:: https://travis-ci.org/eblade/jsonobject.svg?branch=master\n :target: https://travis-ci.org/eblade/jsonobject\n\n\nlindh-jsonobject\n================\n\nJSON serializable python3 objects.\n\nIntroduction\n------------\n\nThe purpose with ``lindh.jsonobject`` is to provide a way to serialize and\ndeserialize python3 objects into and from JSON so that they can be communicated\nwith other application and stored into document databases such as CouchDB.\n\nSome code and inspiration comes from the Django project, and the objects behave\nmuch like such. However, while Django objects are meant for relational databases,\nthese are meant to be used with complex objects in document databases.\n\nDependencies\n------------\n\nThere are no dependencies besides core python3.6\n\nInstallation\n------------\n\nThis repository can be installed with ``pip``.\n\n.. code-block:: bash\n\n pip install lindh-jsonobject\n\nExample\n-------\n\n.. code-block:: python\n\n >>> from json import dumps\n >>> from lindh.jsonobject import Property, PropertySet, EnumProperty\n\n >>> class Wheel(PropertySet):\n ... diameter = Property(float, default=1.)\n\n >>> class Rating(EnumProperty):\n ... ok = 'ok'\n ... bad = 'bad'\n ... good = 'good'\n\n >>> class Car(PropertySet):\n ... wheels = Property(type=Wheel, is_list=True)\n ... brand = Property()\n ... model = Property()\n ... rating = Property(enum=Rating, default=Rating.ok)\n\n >>> volvo = Car(brand='Volvo', model='V70', rating=Rating.good)\n >>> print(volvo.to_json())\n {\n \"*schema\": \"Car\",\n \"brand\": \"Volvo\",\n \"model\": \"V70\",\n \"rating\": \"good\",\n \"wheels\": []\n }\n\n >>> volvo.wheels.append(Wheel(diameter=2.))\n >>> print(volvo.to_json())\n {\n \"*schema\": \"Car\",\n \"brand\": \"Volvo\",\n \"model\": \"V70\",\n \"rating\": \"good\",\n \"wheels\": [\n {\n \"*schema\": \"Wheel\",\n \"diameter\": 2.0\n }\n ]\n }\n\n >>> volvo.wheels.append(Wheel(diameter=2.))\n >>> print(volvo.to_json())\n {\n \"*schema\": \"Car\",\n \"brand\": \"Volvo\",\n \"model\": \"V70\",\n \"rating\": \"good\",\n \"wheels\": [\n {\n \"*schema\": \"Wheel\",\n \"diameter\": 2.0\n },\n {\n \"*schema\": \"Wheel\",\n \"diameter\": 2.0\n }\n ]\n }\n\n >>> volvo.wheels.append(Wheel(diameter=2.))\n >>> volvo.wheels.append(Wheel()) # using default value here\n >>> print(volvo.to_json())\n {\n \"*schema\": \"Car\",\n \"brand\": \"Volvo\",\n \"model\": \"V70\",\n \"rating\": \"good\",\n \"wheels\": [\n {\n \"*schema\": \"Wheel\",\n \"diameter\": 2.0\n },\n {\n \"*schema\": \"Wheel\",\n \"diameter\": 2.0\n },\n {\n \"*schema\": \"Wheel\",\n \"diameter\": 2.0\n },\n {\n \"*schema\": \"Wheel\",\n \"diameter\": 1.0\n }\n ]\n }\n\n >>> volvo2 = Car.FromJSON(volvo.to_json())\n >>> print(volvo2.to_json())\n {\n \"*schema\": \"Car\",\n \"brand\": \"Volvo\",\n \"model\": \"V70\",\n \"rating\": \"good\",\n \"wheels\": [\n {\n \"*schema\": \"Wheel\",\n \"diameter\": 2.0\n },\n {\n \"*schema\": \"Wheel\",\n \"diameter\": 2.0\n },\n {\n \"*schema\": \"Wheel\",\n \"diameter\": 2.0\n },\n {\n \"*schema\": \"Wheel\",\n \"diameter\": 1.0\n }\n ]\n }\n\n\nType Hinting\n------------\n\nYou can also specify types for properties with Type Hinting, if available:\n\n.. code-block:: python\n\n >>> from json import dumps\n >>> from typing import List\n >>> from lindh.jsonobject import Property, PropertySet, EnumProperty\n\n >>> class Wheel(PropertySet):\n ... diameter: float = Property(default=1.)\n\n >>> class Rating(EnumProperty):\n ... ok = 'ok'\n ... bad = 'bad'\n ... good = 'good'\n\n >>> class Car(PropertySet):\n ... wheels: List[Wheel] = Property()\n ... brand = Property()\n ... model = Property()\n ... rating: Rating = Property(default=Rating.ok)\n\n >>> volvo = Car(brand='Volvo', model='V90', rating=Rating.good, wheels=[])\n >>> volvo.wheels.append(Wheel(diameter=3.))\n >>> print(volvo.to_json())\n {\n \"*schema\": \"Car\",\n \"brand\": \"Volvo\",\n \"model\": \"V90\",\n \"rating\": \"good\",\n \"wheels\": [\n {\n \"*schema\": \"Wheel\",\n \"diameter\": 3.0\n }\n ]\n }\n\n\nSupported types:\n\n * ``str``\n * ``int``\n * ``float``\n * ``bool``\n * ``dict``\n * ``typing.List[T]`` where ``T`` is a subclass of ``PropertySet``\n * ``T`` where ``T`` is a subclass of EnumProperty\n\n\nSchema-Less\n-----------\n\nThere is also included a \"schema-less\" mode, found under\n``lindh.jsonobject.noschema``. The idea is to provide an easy-to-use read-only\nLINQ-like way of exploring JSON-like files. Here is a small example:\n\n.. code-block:: python\n\n >>> from lindh.jsonobject import Dictionary\n >>> d = Dictionary.load('tests/test.json')\n >>> palle = (d.drivers\n ... .where(lambda x: x.name == \"Palle Kuling\")\n ... .join(d.cars, lambda driver, car: driver.car_brand == car.brand and driver.car_model == car.model)\n ... .single())\n >>> palle.rating\n 'good'\n\n\nYou can also use chained methods like ``select(expr)``, ``first()`` and ``extend(**items)``.\n\n\nAuthor\n------\n\n``lindh.jsonobject`` is written and maintained by Johan Egneblad .\n\n\n", "description_content_type": "text/x-rst", "docs_url": null, "download_url": "https://github.com/eblade/jsonobject/archive/v1.3.3.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/eblade/jsonobject", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "lindh-jsonobject", "package_url": "https://pypi.org/project/lindh-jsonobject/", "platform": "", "project_url": "https://pypi.org/project/lindh-jsonobject/", "project_urls": { "Download": "https://github.com/eblade/jsonobject/archive/v1.3.3.tar.gz", "Homepage": "https://github.com/eblade/jsonobject" }, "release_url": "https://pypi.org/project/lindh-jsonobject/1.3.3/", "requires_dist": null, "requires_python": "", "summary": "JSON serializable objects", "version": "1.3.3" }, "last_serial": 5596573, "releases": { "1.3.3": [ { "comment_text": "", "digests": { "md5": "c3f0a7a3bfde20180a788cd89be142e4", "sha256": "4b435ad1c89c4891fd14d1b2f6a43c866f1bac96d640d25a1a2db342d1247e1b" }, "downloads": -1, "filename": "lindh_jsonobject-1.3.3-py3-none-any.whl", "has_sig": false, "md5_digest": "c3f0a7a3bfde20180a788cd89be142e4", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8430, "upload_time": "2019-07-28T20:02:15", "url": "https://files.pythonhosted.org/packages/76/23/8f58214f26b1678320fbd92458e9e21f3f88bfe05b0018579bb0c490df38/lindh_jsonobject-1.3.3-py3-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "c3f0a7a3bfde20180a788cd89be142e4", "sha256": "4b435ad1c89c4891fd14d1b2f6a43c866f1bac96d640d25a1a2db342d1247e1b" }, "downloads": -1, "filename": "lindh_jsonobject-1.3.3-py3-none-any.whl", "has_sig": false, "md5_digest": "c3f0a7a3bfde20180a788cd89be142e4", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8430, "upload_time": "2019-07-28T20:02:15", "url": "https://files.pythonhosted.org/packages/76/23/8f58214f26b1678320fbd92458e9e21f3f88bfe05b0018579bb0c490df38/lindh_jsonobject-1.3.3-py3-none-any.whl" } ] }