Skip to main content

StreamJSON

PyPI - Python Version PyPI PyPI - License

tests

Write objects or arrays to a JSON file using a stream. Useful for when you don't want to read large amounts of data in memory, for example when you need to save large amounts of data from a database to a single JSON file.

Read objects from a JSON file using a stream. Does not require loading the whole JSON file in memory.

Install

pip install streamjson

How to write to JSON file

Fetch data from a database or anywhere else and send to a JSON file. The send function takes in a dictionary or a list. A new file with the given name will be created, the root of the JSON file is an array by default.

from streamjson import StreamJSONWriter

persons = [{'id': '0001', 'first_name': 'John', 'last_name': 'Doe'},
           {'id': '0002', 'first_name': 'Jane', 'last_name': 'Doe'}]

with StreamJSONWriter('persons.json', indent=2) as writer:
    for person in persons:
        writer.send(person)

persons.json:

[
  {
    "id": "0001",
    "first_name": "John",
    "last_name": "Doe"
  },
  {
    "id": "0002",
    "first_name": "Jane",
    "last_name": "Doe"
  }
]

How to read from JSON file

The reader will stream each object from the JSON file.

from streamjson import StreamJSONReader

with StreamJSONReader('persons.json') as reader:
    for obj in reader.find():
        print(obj)

Metadata

Release files for streamjson 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for streamjson 1.0.3
File Size Uploaded
streamjson-1.0.3.tar.gz 5.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for streamjson 1.0.3
File Interpreter ABI Platform
streamjson-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 12.2 kB

Release files / streamjson-1.0.3.tar.gz

Download URL streamjson-1.0.3.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5ef1a606319bb18df5447d693d5b0680b226e719c4a6d4c627f2295c8f608d60
BLAKE2b-256 checksum
How to use checksums
ef68495d0879b70a5799ced172bac0f9cc106989cfc557193c5887e1bbefff31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / streamjson-1.0.3-py3-none-any.whl

Download URL streamjson-1.0.3-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c299638ac2baa0b8ede898b588a3d6b06fc1139aeb7f8af021b49f2951c1fade
BLAKE2b-256 checksum
How to use checksums
d204c49dde533053a494ec02bb13bafd07d7ea185daa8938dcf746a474488274
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release history Release notifications | RSS feed

1.0.4

2 release files

This release

1.0.3 This release

2 release files

1.0.2

1 release file

1.0.0

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page