jsonstreams


Namejsonstreams JSON
Version 0.6.0 PyPI version JSON
download
home_pagehttps://github.com/dcbaker/jsonstreams
SummaryA JSON streaming writer
upload_time2021-03-16 17:47:27
maintainer
docs_urlNone
authorDylan Baker
requires_python>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*
licenseMIT
keywords json stream
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            JSONStreams
===========

.. image:: https://github.com/dcbaker/jsonstreams/workflows/lint/badge.svg
    :alt: Python Linting status

.. image:: https://github.com/dcbaker/jsonstreams/workflows/Unit%20tests/badge.svg
    :alt: Linux test status

.. image:: https://badge.fury.io/py/jsonstreams.svg
    :target: https://badge.fury.io/py/jsonstreams

.. image:: https://ci.appveyor.com/api/projects/status/ocrt9nol8kn3pm1t/branch/main?svg=true
    :target: https://ci.appveyor.com/project/dcbaker/jsonstreams
    :alt: Appveyor CI Status

.. image:: https://readthedocs.org/projects/jsonstreams/badge/?version=latest
    :target: http://jsonstreams.readthedocs.io/en/stable/?badge=latest
    :alt: Documentation Status


Source code is available at `github <https://github.com/dcbaker/jsonstreams>`_.

The code is licensed MIT. See the included LICENSE file for the exact terms.


Description
###########


JSONstreams is a package that attempts to making writing JSON in a streaming
format easier. In contrast to the core json module, this package doesn't
require building a complete tree of dicts and lists before writing, instead it
provides a straightforward way to to write a JSON document **without** building
the whole data structure ahead of time.

JSONstreams considers there to be two basic types, the JSON array and the JSON
object, which correspond to Python's list and dict respectively, and can encode
any types that the json.JSONEncoder can, or can use an subclass to handle
additional types.

The interface is designed to be context manger centric. The Stream class, and
the Array and Object classes returned by the subarray and subobject methods
(respectively), can be used as context managers or not, but use as context
managers are recommended to ensure that each container is closed properly.


Basic Usage
###########

A simple example looks like this

.. code-block:: python

    import jsonstreams

    with jsonstreams.Stream(jsonstreams.Type.OBJECT, filename='foo') as s:
        s.write('foo', 'bar')
        with s.subobject('a') as a:
            a.write('foo', 1)
            a.write('bar', 2)
        s.write('bar', 'foo')

Writing into a closed group will raise an exception, which should not be
handled, this exception is always an error in programming and should be
corrected.

It is possible to write any value that the encoder (json.JSONEncoder by
default) can encode, so iterating over lists or dictionaries to write them in
is unnecessary:

.. code-block:: python

    import jsonstreams

    mylist = list(range(10))
    mydict = {a: b for a in range(10) for b in 'abcdefghij'}

    with jsonstreams.Stream(jsonstreams.Type.OBJECT, filename='foo') as s:
        s.write('list', mylist)
        s.write('dict', mydict)



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/dcbaker/jsonstreams",
    "name": "jsonstreams",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*",
    "maintainer_email": "",
    "keywords": "JSON stream",
    "author": "Dylan Baker",
    "author_email": "dylan@pnwbakers.com",
    "download_url": "https://files.pythonhosted.org/packages/85/8c/01333839805428590015bb4cbc3b730876609e536954eb1140d24b410bd0/jsonstreams-0.6.0.tar.gz",
    "platform": "",
    "description": "JSONStreams\n===========\n\n.. image:: https://github.com/dcbaker/jsonstreams/workflows/lint/badge.svg\n    :alt: Python Linting status\n\n.. image:: https://github.com/dcbaker/jsonstreams/workflows/Unit%20tests/badge.svg\n    :alt: Linux test status\n\n.. image:: https://badge.fury.io/py/jsonstreams.svg\n    :target: https://badge.fury.io/py/jsonstreams\n\n.. image:: https://ci.appveyor.com/api/projects/status/ocrt9nol8kn3pm1t/branch/main?svg=true\n    :target: https://ci.appveyor.com/project/dcbaker/jsonstreams\n    :alt: Appveyor CI Status\n\n.. image:: https://readthedocs.org/projects/jsonstreams/badge/?version=latest\n    :target: http://jsonstreams.readthedocs.io/en/stable/?badge=latest\n    :alt: Documentation Status\n\n\nSource code is available at `github <https://github.com/dcbaker/jsonstreams>`_.\n\nThe code is licensed MIT. See the included LICENSE file for the exact terms.\n\n\nDescription\n###########\n\n\nJSONstreams is a package that attempts to making writing JSON in a streaming\nformat easier. In contrast to the core json module, this package doesn't\nrequire building a complete tree of dicts and lists before writing, instead it\nprovides a straightforward way to to write a JSON document **without** building\nthe whole data structure ahead of time.\n\nJSONstreams considers there to be two basic types, the JSON array and the JSON\nobject, which correspond to Python's list and dict respectively, and can encode\nany types that the json.JSONEncoder can, or can use an subclass to handle\nadditional types.\n\nThe interface is designed to be context manger centric. The Stream class, and\nthe Array and Object classes returned by the subarray and subobject methods\n(respectively), can be used as context managers or not, but use as context\nmanagers are recommended to ensure that each container is closed properly.\n\n\nBasic Usage\n###########\n\nA simple example looks like this\n\n.. code-block:: python\n\n    import jsonstreams\n\n    with jsonstreams.Stream(jsonstreams.Type.OBJECT, filename='foo') as s:\n        s.write('foo', 'bar')\n        with s.subobject('a') as a:\n            a.write('foo', 1)\n            a.write('bar', 2)\n        s.write('bar', 'foo')\n\nWriting into a closed group will raise an exception, which should not be\nhandled, this exception is always an error in programming and should be\ncorrected.\n\nIt is possible to write any value that the encoder (json.JSONEncoder by\ndefault) can encode, so iterating over lists or dictionaries to write them in\nis unnecessary:\n\n.. code-block:: python\n\n    import jsonstreams\n\n    mylist = list(range(10))\n    mydict = {a: b for a in range(10) for b in 'abcdefghij'}\n\n    with jsonstreams.Stream(jsonstreams.Type.OBJECT, filename='foo') as s:\n        s.write('list', mylist)\n        s.write('dict', mydict)\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A JSON streaming writer",
    "version": "0.6.0",
    "split_keywords": [
        "json",
        "stream"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "db41682f5cb55033ba6400f08003a87a",
                "sha256": "b2e609c2bc17eec77fe26dae4d32556ba59dafbbff30c9a4909f2e19fa5bb000"
            },
            "downloads": -1,
            "filename": "jsonstreams-0.6.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "db41682f5cb55033ba6400f08003a87a",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*",
            "size": 10617,
            "upload_time": "2021-03-16T17:47:25",
            "upload_time_iso_8601": "2021-03-16T17:47:25.700302Z",
            "url": "https://files.pythonhosted.org/packages/af/be/233b55906cc033b890c2e4593077bc10c7e09257c46f5253dd9b2850f3f4/jsonstreams-0.6.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "f3a40174a4f54e0ecbf803cf92ead38a",
                "sha256": "721cda7391e9415b7b15cebd6cf92fc7f8788ca211eda7d64162a066ee45a72e"
            },
            "downloads": -1,
            "filename": "jsonstreams-0.6.0.tar.gz",
            "has_sig": false,
            "md5_digest": "f3a40174a4f54e0ecbf803cf92ead38a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*",
            "size": 33544,
            "upload_time": "2021-03-16T17:47:27",
            "upload_time_iso_8601": "2021-03-16T17:47:27.188747Z",
            "url": "https://files.pythonhosted.org/packages/85/8c/01333839805428590015bb4cbc3b730876609e536954eb1140d24b410bd0/jsonstreams-0.6.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-03-16 17:47:27",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "dcbaker",
    "github_project": "jsonstreams",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "appveyor": true,
    "tox": true,
    "lcname": "jsonstreams"
}
        
Elapsed time: 0.02696s