{ "info": { "author": "Tim-Luca Lagm\u00f6ller", "author_email": "hello@lagmoellertim.de", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# Pyon\n

\n \n

\n\n## Introduction\n**Pyon** (Pythonic JSON) is a Python library which allows you to **easily convert native objects into JSON objects**.\n\nIt also supports **filesystem-like path-structure**, \nwhich allows you to easily construct you JSON objects just the way you like it.\n\nAdditionally, it uses recursion in order to also **convert every connected object** into a usable form.\n\n## Prerequisites\n\n- Python >= 3.2\n\n## Installation\nThe installation via pip is as easy as typing\n```sh\npip install pyon-lib\n```\nIf you want to install the newest version manually, you can also do this:\n```sh\ngit clone https://github.com/lagmoellertim/pyon.git\n\ncd pyon\n\npython3 setup.py install\n```\n\n## Build\n\n```sh\ngit clone https://github.com/lagmoellertim/pyon.git\n\ncd pyon\n\npython3 setup.py sdist bdist_wheel\n```\n\n## Usage\n\n### Import Pyon\n\n```python3\nfrom pyon import PyonObject\n```\n\n### Create a basic Object\n\n```python3\nclass Test(PyonObject):\n def __init__(self):\n self.var1 = \"Variable 1\"\n self.var2 = 5.5\n```\n\n### Convert an object into JSON\n\n```python3\ntest = Test()\njson = test.dump()\n```\nAnd this is the output:\n```python3\n{'var1': 'Variable 1', 'var2': 5.5}\n```\n\n### Write the JSON object to a file\n\n```python3\ntest = Test()\njson = test.generate_json(file_object=open(\"test.json\",\"w+\"))\n```\n\n### Hide certain variables\nLet's say your Test-Class only needs the variable var2 for it's own calculation, but you don't want it to\nend up in your final JSON object. You can avoid this by adding the prefix \"_\"\n\n```python3\nclass Test(PyonObject):\n def __init__(self):\n self.var1 = \"Variable 1\"\n self._var2 = 5.5\n\ntest = Test()\njson = test.dump()\n```\nAnd this is the output:\n```python3\n{'var1': 'Variable 1'}\n```\n\n### Use multiple objects / classes\nAs an example, I use the concept of a store with products\n\n```python3\nclass Store(PyonObject):\n def __init__(self, store_name):\n self.store_name = store_name\n self.products = [\n Product(0, \"Smartphone\"),\n Product(1, \"Laptop\")\n ]\n\nclass Product(PyonObject):\n def __init__(self, article_id, name):\n self.article_id = article_id\n self.name = name\n\nstore = Store(\"Generic Store\")\njson = store.dump()\n```\nAnd this is the output:\n\n```python3\n{\n 'store_name': 'Generic Store',\n 'products': \n [\n {'article_id': 0, 'name': 'Smartphone'},\n {'article_id': 1, 'name': 'Laptop'}\n ]\n}\n```\n\n### Specifying object paths\nThis time, the JSON structure should not be based on the class structure, but rather on the path string\nthat we supply.\n\nPath Strings are very similar to your filesystem paths. You can navigate inside the JSON object using\nthese Path Strings.\n\nHere are some example:\n\n```python3\npath1 = \"/store/\"\n\npath2 = \"/test/../store/./\" # Identical to path1 since ../ means one layer up and ./ can be ignored\n\npath3 = \"/store/products/*\" #The star symbol tells pyon to create a list instead of a dict in this location\n```\nLet's modify our Store / Products Class in order for it to use custom paths\n\n```python3\nclass Store(PyonObject):\n def __init__(self, store_name):\n super().__init__(\"/stores/*\")\n self.store_name = store_name\n self.products = [\n Product(0, \"Smartphone\"),\n Product(1, \"Laptop\")\n ]\n\nclass Product(PyonObject):\n def __init__(self, article_id, name):\n super().__init__(\"products/*\")\n self.article_id = article_id\n self.name = name\n\nstore = Store(\"Generic Store\")\njson = store.dump()\n```\nAnd this is the output:\n```python3\n{\n 'stores':\n [\n {'store_name': 'Generic Store', 'products': \n [\n {'article_id': 0, 'name': 'Smartphone'},\n {'article_id': 1, 'name': 'Laptop'}\n ]\n }\n ]\n}\n\n```\nAs you can see in the example above, relative paths are also possible as long as the object has a parent.\n\n### Use object variables for the Path String\nTo use object variables inside of you Path String, simply specify them in the String using brackets like\nthis: {var1}\n\nThe value of {var1} is self.var1 , so you just leave the 'self.' away.\n\n```python3\nclass Test(PyonObject):\n def __init__(self):\n super().__init__(\"/test/{var1}-{_var2}/\")\n self.var1 = \"Variable 1\"\n self._var2 = 5.5\n\ntest = Test()\njson = test.dump()\n```\nAnd this is the output:\n```python3\n{\n 'test':\n {\n 'Variable 1-5.5': {'var1': 'Variable 1'}\n }\n}\n```\n### Different dump methods\nPyon supports different methods for dumping the PyonObject. You can use the normal python dictionary ('json'), 'xml' or\n'yaml'.\nHere are some usage examples:\n```python3\njson = test.dump(output_format=\"json\") # JSON is default, so you can also leave it empty\n\nxml = test.dump(output_format=\"xml\")\n\nyaml = test.dump(output_format=\"yaml\")\n```\n\n### Allow Overwrite\nFinally, there is Overwrite Protection. Since Paths allow you to freely choose the location where the\nobject should end up, it is possible for them to overlap. To allow / stop overwriting, you can do this:\n\n```python3\njson = test.dump(allow_overwrite=True)\n```\nThe default value for allow_overwrite is False\n\n\n## Documentation\n\nIf you get stuck at some point while trying to use the API, take a look the code. It is fully commented and well-labeled,\nwhich should help you understand what's going on.\n\n## Contributing\n\nIf you are missing a feature or have new idea, go for it! That is what open-source is for!\n\n## Author\n\n**Tim-Luca Lagm\u00f6ller** ([@lagmoellertim](https://github.com/lagmoellertim))\n\n## Donate\n\nYou can also contribute by [buying me a coffee](https://www.buymeacoffee.com/lagmoellertim).\n\n## License\n\n[MIT License](https://github.com/lagmoellertim/pyon/blob/master/LICENSE)\n\nCopyright \u00a9 2019-present, [Tim-Luca Lagm\u00f6ller](https://en.lagmoellertim.de)\n\n## Have fun :tada:\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/lagmoellertim/pyon", "keywords": "", "license": "MIT License", "maintainer": "", "maintainer_email": "", "name": "pyon-lib", "package_url": "https://pypi.org/project/pyon-lib/", "platform": "", "project_url": "https://pypi.org/project/pyon-lib/", "project_urls": { "Homepage": "https://github.com/lagmoellertim/pyon" }, "release_url": "https://pypi.org/project/pyon-lib/0.1.3/", "requires_dist": [ "pyyaml (==5.1.1)", "dicttoxml (==1.7.4)" ], "requires_python": "", "summary": "Pythonic Object Notation - with native objects and path support", "version": "0.1.3" }, "last_serial": 5563737, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "8c9e148b5edcf50dd1a1ed600fc55c0b", "sha256": "de2ab448df74628bc0720d26d3396656bcdbe92c01c448e69d0028580ed7b966" }, "downloads": -1, "filename": "pyon_lib-0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "8c9e148b5edcf50dd1a1ed600fc55c0b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8724, "upload_time": "2019-07-21T10:36:27", "url": "https://files.pythonhosted.org/packages/7e/f0/e55cdc6d6bd9c81905b7b1854589474d79c06854b0467192013866b8378c/pyon_lib-0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8be113708aab2f0a890056c2b76d40f8", "sha256": "74ac6d764f78da30ea8494f0581e48f59f51acbe8b3e19f957052821c516736d" }, "downloads": -1, "filename": "pyon-lib-0.1.tar.gz", "has_sig": false, "md5_digest": "8be113708aab2f0a890056c2b76d40f8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7232, "upload_time": "2019-07-21T10:36:30", "url": "https://files.pythonhosted.org/packages/16/62/6f59e7f5961022df8f9f5357c93b129f51e054295ccc86b9fd75c40ad39b/pyon-lib-0.1.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "09c76b8569c5b1fc287386e644cda0fe", "sha256": "49abee125db266656dabe4ef130121ef61663ee505d9d1f201c3cddb383816b0" }, "downloads": -1, "filename": "pyon_lib-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "09c76b8569c5b1fc287386e644cda0fe", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8811, "upload_time": "2019-07-21T10:45:27", "url": "https://files.pythonhosted.org/packages/a8/36/05d466acab45ee0eee5e18d63f795f77ab71e42a305db6b552fb2224c856/pyon_lib-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "abadc10f7991f8204a07b3c71f8051c3", "sha256": "b86236711376638fde6335f25190d8353dc9b38551ac69fe3b482c5c7b7b240a" }, "downloads": -1, "filename": "pyon-lib-0.1.1.tar.gz", "has_sig": false, "md5_digest": "abadc10f7991f8204a07b3c71f8051c3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7335, "upload_time": "2019-07-21T10:45:28", "url": "https://files.pythonhosted.org/packages/07/33/a8f46e2dd002a0ae98d573dc4de538986bdbab8beebc6a9ca0c4029de6ba/pyon-lib-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "d7da7c4c61070c7d63d2dd91243c3c4f", "sha256": "1c7d51159646f7db6a6e4d7705eb31588e667aa2383dbcb6f4a38c0a29047eaa" }, "downloads": -1, "filename": "pyon_lib-0.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "d7da7c4c61070c7d63d2dd91243c3c4f", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8811, "upload_time": "2019-07-21T13:00:37", "url": "https://files.pythonhosted.org/packages/e7/ca/6eca5b6833f3ce437e989b188ad6a8643cae0d0e7cbf4e0f8404e8adb78e/pyon_lib-0.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9a27c87fb2d925454c5778c39c55ffab", "sha256": "d7e47637f1bfbce1b765c74da25fb9c7138d12f8d9d94b78d799e352e092ec98" }, "downloads": -1, "filename": "pyon-lib-0.1.2.tar.gz", "has_sig": false, "md5_digest": "9a27c87fb2d925454c5778c39c55ffab", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7332, "upload_time": "2019-07-21T13:00:39", "url": "https://files.pythonhosted.org/packages/ac/b7/eec2acba85ceb2e5b08c6460d58a4e0b7f42d01b62391a2b3482fa1eb8c4/pyon-lib-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "489a1a24d51a3371c41434a67842cc19", "sha256": "000e852eb9b1dbdf7c0478fbc9ed78a9e8a1ec83731c422db2054fe54a32550d" }, "downloads": -1, "filename": "pyon_lib-0.1.3-py3-none-any.whl", "has_sig": false, "md5_digest": "489a1a24d51a3371c41434a67842cc19", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9125, "upload_time": "2019-07-21T15:44:12", "url": "https://files.pythonhosted.org/packages/27/cd/639116079dc1ce27c8db7181296587bbb1ce884f2324269c37daae0f6dd7/pyon_lib-0.1.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "31c8e75fd6dc882819e802bc493a06b7", "sha256": "233167f0f00ed7fd25d3b24a89d260be6212a668b98df422e249c99f76866200" }, "downloads": -1, "filename": "pyon-lib-0.1.3.tar.gz", "has_sig": false, "md5_digest": "31c8e75fd6dc882819e802bc493a06b7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7759, "upload_time": "2019-07-21T15:44:14", "url": "https://files.pythonhosted.org/packages/db/1c/326a7b5a1b72398d83f41a5ac55665cf6dc68a647e9f8f3f925fa35ae867/pyon-lib-0.1.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "489a1a24d51a3371c41434a67842cc19", "sha256": "000e852eb9b1dbdf7c0478fbc9ed78a9e8a1ec83731c422db2054fe54a32550d" }, "downloads": -1, "filename": "pyon_lib-0.1.3-py3-none-any.whl", "has_sig": false, "md5_digest": "489a1a24d51a3371c41434a67842cc19", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9125, "upload_time": "2019-07-21T15:44:12", "url": "https://files.pythonhosted.org/packages/27/cd/639116079dc1ce27c8db7181296587bbb1ce884f2324269c37daae0f6dd7/pyon_lib-0.1.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "31c8e75fd6dc882819e802bc493a06b7", "sha256": "233167f0f00ed7fd25d3b24a89d260be6212a668b98df422e249c99f76866200" }, "downloads": -1, "filename": "pyon-lib-0.1.3.tar.gz", "has_sig": false, "md5_digest": "31c8e75fd6dc882819e802bc493a06b7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7759, "upload_time": "2019-07-21T15:44:14", "url": "https://files.pythonhosted.org/packages/db/1c/326a7b5a1b72398d83f41a5ac55665cf6dc68a647e9f8f3f925fa35ae867/pyon-lib-0.1.3.tar.gz" } ] }