{ "info": { "author": "Sean Gillies", "author_email": "sean.gillies@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "# jsonseq\n\n[RFC 7464 JSON Text Sequences](https://tools.ietf.org/html/rfc7464) encoding and decoding for Python.\n\n[![Build\nStatus](https://travis-ci.com/sgillies/jsonseq.svg?branch=master)](https://travis-ci.com/sgillies/jsonseq)\n[![Coverage\nStatus](https://coveralls.io/repos/github/sgillies/jsonseq/badge.svg?branch=master)](https://coveralls.io/github/sgillies/jsonseq?branch=master)\n[![Documentation Status](https://readthedocs.org/projects/jsonseq/badge/?version=latest)](https://jsonseq.readthedocs.io/en/latest/?badge=latest)\n\n## Usage\n\nThe `jsonseq.encode.JSONSeqEncoder` class takes streams of JSON-serializable\nPython objects and yields for each object its JSON representation sandwiched\nbetween an optional ASCII record separator (RS, `\\x1e`) and a newline (`\\n`).\n\n```python\n>>> from jsonseq.encode import JSONSeqEncoder\n>>> for chunk in JSONSeqEncoder().encode(({\"a\": i, \"b\": i} for i in range(3))):\n... print(repr(chunk))\n...\n'{\"a\": 0, \"b\": 0}\\n'\n'{\"a\": 1, \"b\": 1}\\n'\n'{\"a\": 2, \"b\": 2}\\n'\n```\n\nThe RS allows pretty-printed JSON to be streamed out in sequences that can be\ndecoded again.\n\n```python\n>>> for chunk in JSONSeqEncoder(with_rs=True, indent=2).encode(({\"a\": i, \"b\": i} for i in range(3))):\n... print(repr(chunk))\n...\n'\\x1e{\\n \"a\": 0,\\n \"b\": 0\\n}\\n'\n'\\x1e{\\n \"a\": 1,\\n \"b\": 1\\n}\\n'\n'\\x1e{\\n \"a\": 2,\\n \"b\": 2\\n}\\n'\n```\n\nYou can also get small chunks of the JSON sequences as they are encoded with\nthe `iterencode()` method.\n\n```python\n>>> for chunk in JSONSeqEncoder(with_rs=True).iterencode(({\"a\": i} for i in range(3))):\n... print(repr(chunk))\n...\n'\\x1e'\n'{'\n'\"a\"'\n': '\n'0'\n'}'\n'\\n'\n'\\x1e'\n'{'\n'\"a\"'\n': '\n'1'\n'}'\n'\\n'\n'\\x1e'\n'{'\n'\"a\"'\n': '\n'2'\n'}'\n'\\n'\n```\n\nYou can use either `encode()` or `iterencode()` to copy JSON text sequences to a file.\n\n```python\nwith open(\"/tmp/example.jsons\", \"w\") as f:\n for chunk in JSONSeqEncoder(with_rs=True, indent=2).iterencode(({\"a\": i, \"b\": i} for i in range(3))):\n f.write(chunk)\n```\n\nThere is no need to add a newline when calling the file's `write()` method.\nJSONSeqEncoder ensures that it's already there where it needs to be.\n\nThe `jsonseq.decode.JSONSeqDecoder` class takes streams of JSON texts\nsandwiched between the optional ASCII record separator (RS, `\\x1e`) and\na newline (`\\n`) and yields decoded Python objects.\n\n```python\n>>> stream = ['\\x1e', '{', '\"a\"', ': ', '0', '}', '\\n', '\\x1e', '{', '\"a\"', ': ', '1', '}', '\\n', '\\x1e', '{', '\"a\"', ': ', '2', '}', '\\n']\n>>> for obj in JSONSeqDecoder().decode(stream):\n... print(repr(obj))\n...\n{'a': 0}\n{'a': 1}\n{'a': 2}\n```\n\nObjects can be read from a file in the same way.\n\n```python\n>>> with open(\"/tmp/example.jsons\") as f:\n... for obj in JSONSeqDecoder().decode(f):\n... print(repr(obj))\n...\n{'a': 0, 'b': 0}\n{'a': 1, 'b': 1}\n{'a': 2, 'b': 2}\n````\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/sgillies/jsonseq", "keywords": "json rfc7464", "license": "", "maintainer": "", "maintainer_email": "", "name": "jsonseq", "package_url": "https://pypi.org/project/jsonseq/", "platform": "", "project_url": "https://pypi.org/project/jsonseq/", "project_urls": { "Homepage": "https://github.com/sgillies/jsonseq" }, "release_url": "https://pypi.org/project/jsonseq/1.0.0/", "requires_dist": [ "check-manifest ; extra == 'dev'", "pytest ; extra == 'test'", "pytest-cover ; extra == 'test'" ], "requires_python": "", "summary": "Python support for RFC 7464 JSON text sequences", "version": "1.0.0" }, "last_serial": 5615319, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "fe0d4b73ba04ada7f53a079d0caa46a0", "sha256": "d4add916420fc02796a503e59ce4d8008152830fd1625cc70692b1f980a32231" }, "downloads": -1, "filename": "jsonseq-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "fe0d4b73ba04ada7f53a079d0caa46a0", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4567, "upload_time": "2019-07-31T19:47:33", "url": "https://files.pythonhosted.org/packages/04/f5/367876253306f752190203917a51670682780179665b38fc713629e0be71/jsonseq-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8ecd561fa318378f3df49f7c0497799f", "sha256": "238f51aa741132d2a41d1fb89e58eb8d43c6da9d34845c9499dd882a4cd0253a" }, "downloads": -1, "filename": "jsonseq-1.0.0.tar.gz", "has_sig": false, "md5_digest": "8ecd561fa318378f3df49f7c0497799f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3341, "upload_time": "2019-07-31T19:47:34", "url": "https://files.pythonhosted.org/packages/63/70/faca1f522bc03f92ac75da1eb29fe045bf89246a8e8ed04ccbd563540520/jsonseq-1.0.0.tar.gz" } ], "1.0a1": [ { "comment_text": "", "digests": { "md5": "d2580ff6caef0529cb1f656965c7dec8", "sha256": "3a612110dc6f8b09bc2920987f40debb26318a30d0e34d354376bbae4ac45bdf" }, "downloads": -1, "filename": "jsonseq-1.0a1-py3-none-any.whl", "has_sig": false, "md5_digest": "d2580ff6caef0529cb1f656965c7dec8", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 3757, "upload_time": "2018-09-20T21:19:36", "url": "https://files.pythonhosted.org/packages/39/d0/71e02687d2738d31a36b58e9752fc27ee95b0a68fd30c633e4f8b5f3205f/jsonseq-1.0a1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b1c40edbfdb28112fff73c5dbc1dc071", "sha256": "08e78b6f05a30b9f3f09622332dbc9831ff68016065324dd97a9ab1ff9a32580" }, "downloads": -1, "filename": "jsonseq-1.0a1.tar.gz", "has_sig": false, "md5_digest": "b1c40edbfdb28112fff73c5dbc1dc071", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3298, "upload_time": "2018-09-20T21:19:37", "url": "https://files.pythonhosted.org/packages/6d/5a/14d9b1a69aed17d1d6d09b9104fb6521aa89b50e389fb83c206d66a31e25/jsonseq-1.0a1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "fe0d4b73ba04ada7f53a079d0caa46a0", "sha256": "d4add916420fc02796a503e59ce4d8008152830fd1625cc70692b1f980a32231" }, "downloads": -1, "filename": "jsonseq-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "fe0d4b73ba04ada7f53a079d0caa46a0", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4567, "upload_time": "2019-07-31T19:47:33", "url": "https://files.pythonhosted.org/packages/04/f5/367876253306f752190203917a51670682780179665b38fc713629e0be71/jsonseq-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8ecd561fa318378f3df49f7c0497799f", "sha256": "238f51aa741132d2a41d1fb89e58eb8d43c6da9d34845c9499dd882a4cd0253a" }, "downloads": -1, "filename": "jsonseq-1.0.0.tar.gz", "has_sig": false, "md5_digest": "8ecd561fa318378f3df49f7c0497799f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3341, "upload_time": "2019-07-31T19:47:34", "url": "https://files.pythonhosted.org/packages/63/70/faca1f522bc03f92ac75da1eb29fe045bf89246a8e8ed04ccbd563540520/jsonseq-1.0.0.tar.gz" } ] }