Utilities for working with newline delimited JSON (NDJSON) files, aka JSON Lines.
Latest release 20250528: New dump_ndjson and dumps_ndjson for transcribing obj as NDJSON (includes the trailing newline).
Short summary:
append_ndjson: Append an iterable of objects to a file as newline delimited JSON.dump_ndjson: Writeobjas a single line of JSON, including the trailing newline.dumps_ndjson: Returnobjas a single line of JSON, including the trailing newline.scan_ndjson: Read a newline delimited JSON file, yield instances ofdictclass(defaultdict, otherwise a class which can be instantiated bydictclass(a_dict)).UUIDNDJSONMapping: A subclass ofIndexedSetMixinwhich maintains records from a newline delimited JSON file.write_ndjson: Transcribe an iterable of objects to a file as newline delimited JSON.
Module contents:
-
append_ndjson(f, objs): Append an iterable of objects to a file as newline delimited JSON. -
dump_ndjson(obj, f): Writeobjas a single line of JSON, including the trailing newline. -
dumps_ndjson(obj): Returnobjas a single line of JSON, including the trailing newline. -
scan_ndjson(f, dictclass=<class 'dict'>, error_list=None): Read a newline delimited JSON file, yield instances ofdictclass(defaultdict, otherwise a class which can be instantiated bydictclass(a_dict)).error_listis an optional list to accrue(lineno,exception)tuples for errors encountered during the scan. -
ClassUUIDNDJSONMapping(cs.obj.SingletonMixin, cs.mappings.IndexedSetMixin)``: A subclass ofIndexedSetMixinwhich maintains records from a newline delimited JSON file.
UUIDNDJSONMapping.__init__(self, filename, dictclass=<class 'cs.mappings.UUIDedDict'>, create=False):
Initialise the mapping.
Parameters:
filename: the file containing the newline delimited JSON data; this need not yet existdictclass: a optionaldictsubclass to hold each record, defaultUUIDedDictcreate: if true, ensure the file exists by transiently opening it for append if it is missing; defaultFalse
UUIDNDJSONMapping.add_backend(self, record):
Append record to the backing file.
UUIDNDJSONMapping.rewrite_backend(self):
Rewrite the backing file.
Because the record updates are normally written in append mode, a rewrite will be required every so often.
UUIDNDJSONMapping.scan(self):
Scan the backing file, yield records.
Release Log
Release 20250528: New dump_ndjson and dumps_ndjson for transcribing obj as NDJSON (includes the trailing newline).
Release 20211208: Initial PyPI release.
Metadata
Release files for cs-ndjson 20250528
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cs_ndjson-20250528.tar.gz | 3.3 kB | Without provenance | Details for cs_ndjson-20250528.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cs_ndjson-20250528-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for cs_ndjson-20250528-py2.py3-none-any.whl |
Total release size: 7.4 kB
Release files / cs_ndjson-20250528.tar.gz
| Download URL | cs_ndjson-20250528.tar.gz |
|---|---|
| Size | 3.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
351683cab8634c5ffa0b09bc90e2ce405f363d7f9589ac2d17a34782fead007a
|
|
BLAKE2b-256 checksum How to use checksums |
19265d2ef26fcff1cd195a969c4bcac1639cba42c827ea91ed52b939ec2d3226
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / cs_ndjson-20250528-py2.py3-none-any.whl
| Download URL | cs_ndjson-20250528-py2.py3-none-any.whl |
|---|---|
| Size | 4.1 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
ab46e55c156b1d89509794212511c8527bd9a2cb8f47d6f8fd26181c8908e01a
|
|
BLAKE2b-256 checksum How to use checksums |
56ed4df507cb6a53d1d38a0d520fae7ac1f6be058ba9310bc613d9ebc8a78555
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Security for cs-ndjson 20250528
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.