{ "info": { "author": "Will Stott", "author_email": "willstott101@gmail.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "========\nlazyjson\n========\n|tests| |python|\n\n**Encode existing JSON strings within new JSON documents efficiently...ish**\n\nSometimes you have some existing JSON snippets which you would like to include in a new JSON document or api response. This can be achieved cleanly but inefficiently by decoding the JSON first.\n\n.. code-block:: python\n\n st = os.stat('tests/my.json')\n meta = {\n \"size\": st.st_size,\n \"mtime\": st.st_mtime,\n \"content\": json.load(open('tests/my.json'))\n }\n return json.dumps(meta)\n\nThe goal of this library is to provide an API which allows you to avoid ever decoding the snippet that's being included here.\n\nJSONPassthroughEncoder\n----------------------\n\nThis is a subclass of the standard lib's ``json.JSONEncoder`` and performs the magic enabling ``SafeJSON`` to work.\n\n**WARNING**: **Blindly wrapping untrusted JSON strings could result in JSON injection attacks.** This library is not intended for everyday uses, but rather for complex proxy/file serving use cases where upstream is data you can trust. Please be careful, and only use when you're certain this is the correct tool for the job, and you trust any data you're embedding.\n\n**WARNING**: **This class comes with massive performance penalties for encoding complex JSON structures from primitives.** The way in which this class is forced to work by the standard lib's json API is makes normal encoding inneficient, but the concept is otherwise simple and could be added to an existing C implementation trivially with no performance penalty.\n\n\n*If the performance of this module is preventing you from using it but you have a valid use case please get in contact with me to collaborate on a C implementation.*\n\nSafeJSON\n--------\n\nA wrapper for json-encoded strings which allows them to be output within a\nJSON document by the ``JSONPassthroughEncoder`` without decoding first.\n\nThis is a subclass of ``LazyJSON``.\n\n.. code-block:: python\n\n st = os.stat('my.json')\n doc = {\n \"size\": st.st_size,\n \"mtime\": st.st_mtime,\n \"content\": SafeJSON(open('my.json').read()),\n }\n return JSONPassthroughEncoder().encode(doc)\n\nSafeJSONFile\n------------\n\nLike ``SafeJSON`` but for file-like objects instead of strings. This can be used for streaming extremely large embedded json documents without ever loading them fully into memory.\n\n.. code-block:: python\n\n st = os.stat('my.json')\n doc = {\n \"size\": st.st_size,\n \"mtime\": st.st_mtime,\n \"content\": SafeJSONFile(open('my.json'), chunk_size=5000),\n }\n for t in JSONPassthroughEncoder().iterencode(doc):\n socket.write(t)\n\nLazyJSON\n--------\n\nLike ``SafeJSON`` but **will not** be passed-through by ``JSONPassthroughEncoder`` classes.\n\nThis class can be used for untrusted JSON data for passing around your application and retaining the fact it's JSON-encoded, if you might only want to decode it sometimes.\n\nUse the ``my_lazy_json.parse_json()`` method to parse the JSON.\n\nAfter validation (usually of the parsed data) you can construct a ``SafeJSON`` object from this object to avoid re-encoding ``SafeJSON(my_lazy_json)``.\n\n.. |tests| image:: https://github.com/willstott101/lazyjson/workflows/Tests/badge.svg\n :target: https://github.com/willstott101/lazyjson/actions\n.. |python| image:: https://img.shields.io/badge/python-3.5+-blue.svg\n\n", "description_content_type": "text/x-rst", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/willstott101/lazyjson", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "lazyjson", "package_url": "https://pypi.org/project/lazyjson/", "platform": "", "project_url": "https://pypi.org/project/lazyjson/", "project_urls": { "Homepage": "https://github.com/willstott101/lazyjson", "Source": "https://github.com/willstott101/lazyjson" }, "release_url": "https://pypi.org/project/lazyjson/0.0.1/", "requires_dist": null, "requires_python": ">=3.5", "summary": "Encode existing JSON strings within new JSON documents efficiently...ish", "version": "0.0.1", "yanked": false, "yanked_reason": null }, "last_serial": 6029899, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "592e5bf5ca3adc2c1f1646eebd385f12", "sha256": "2a88322e419569eea1a6dc67db868b91554d174804c1a1f606103cc6ead4e3d8" }, "downloads": -1, "filename": "lazyjson-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "592e5bf5ca3adc2c1f1646eebd385f12", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 5479, "upload_time": "2019-10-25T14:16:26", "upload_time_iso_8601": "2019-10-25T14:16:26.100615Z", "url": "https://files.pythonhosted.org/packages/b0/71/127712328531baccf7671462a72ca6fedc2f8cd9198867a6fa38d73ebc02/lazyjson-0.0.1-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "9fe461913d3aa3b4af4be75b22fa521f", "sha256": "19c55355e0c8381c3d80dfba13d8ab9f2991f59540767f9d9d21a81f163d56f2" }, "downloads": -1, "filename": "lazyjson-0.0.1.tar.gz", "has_sig": false, "md5_digest": "9fe461913d3aa3b4af4be75b22fa521f", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 4348, "upload_time": "2019-10-25T14:16:27", "upload_time_iso_8601": "2019-10-25T14:16:27.916098Z", "url": "https://files.pythonhosted.org/packages/40/6a/2645ca845d960dec41b3e717b2acfe38af292c157eee79f702ba89f6ea10/lazyjson-0.0.1.tar.gz", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "592e5bf5ca3adc2c1f1646eebd385f12", "sha256": "2a88322e419569eea1a6dc67db868b91554d174804c1a1f606103cc6ead4e3d8" }, "downloads": -1, "filename": "lazyjson-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "592e5bf5ca3adc2c1f1646eebd385f12", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 5479, "upload_time": "2019-10-25T14:16:26", "upload_time_iso_8601": "2019-10-25T14:16:26.100615Z", "url": "https://files.pythonhosted.org/packages/b0/71/127712328531baccf7671462a72ca6fedc2f8cd9198867a6fa38d73ebc02/lazyjson-0.0.1-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "9fe461913d3aa3b4af4be75b22fa521f", "sha256": "19c55355e0c8381c3d80dfba13d8ab9f2991f59540767f9d9d21a81f163d56f2" }, "downloads": -1, "filename": "lazyjson-0.0.1.tar.gz", "has_sig": false, "md5_digest": "9fe461913d3aa3b4af4be75b22fa521f", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 4348, "upload_time": "2019-10-25T14:16:27", "upload_time_iso_8601": "2019-10-25T14:16:27.916098Z", "url": "https://files.pythonhosted.org/packages/40/6a/2645ca845d960dec41b3e717b2acfe38af292c157eee79f702ba89f6ea10/lazyjson-0.0.1.tar.gz", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }