Skip to main content

A simple, fast and lightweight Python library for loading, saving, streaming and appending jsonl (also known as JSON Lines) files.

Project description

orjsonl

orjsonl is a simple, fast and lightweight Python library for loading, saving, streaming and appending jsonl (also known as JSON Lines) files. It is powered by orjson, the quickest and most correct json serializer currently available for Python.

Installation

orjsonl may be installed with pip:

pip install orjsonl

Usage

This code snippet demonstrates how jsonl files can be loaded, saved, appended and streamed with the load(), save(), append() and stream() functions, respectively:

>>> import orjsonl
>>> data = [
    {'hello' : 'world'},
    [1.1, 2.2, 3.3],
    42,
    True,
    None
]
>>> orjsonl.save(path='test.jsonl', data=data)
>>> orjsonl.load(path='test.jsonl')
[{'hello': 'world'}, [1.1, 2.2, 3.3], 42, True, None]
>>> orjsonl.append(path='test.jsonl', data=[('a', 'b', 'c')])
>>> [object_ for object_ in orjsonl.stream(path='test.jsonl')]
[{'hello': 'world'}, [1.1, 2.2, 3.3], 42, True, None, ['a', 'b', 'c']]

Load

def load(
    path: str | bytes | int | os.PathLike
) -> list[dict | list | int | float | str | bool | None]: ...

load() deserializes a UTF-8-encoded jsonl file to a list of Python objects.

The only argument taken by this function is path, a path-like object giving the pathname (absolute or relative to the current working directory), or an integer file descriptor, of the jsonl file to be deserialized.

This function returns a list object comprised of deserialized dict, list, int, float, str, bool or None objects.

Stream

def stream(
    path: str | bytes | int | os.PathLike
) -> map: ...

stream() creates a map object that deserializes a UTF-8-encoded jsonl file to Python objects.

The only argument taken by this function is path, a path-like object giving the pathname (absolute or relative to the current working directory), or an integer file descriptor, of the jsonl file to be deserialized by the map object.

This function returns a map object that deserializes the jsonl file to dict, list, int, float, str, bool or None objects.

Save

def save(
    path: str | bytes | int | os.PathLike,
    data: Iterable
) -> None: ...

save() serializes an iterable of Python objects to a UTF-8-encoded jsonl file.

The first argument taken by this function is path, a path-like object giving the pathname (absolute or relative to the current working directory), or an integer file descriptor, of the jsonl file to be saved.

The second argument taken by this function is data, an iterable of Python objects to be serialized to the jsonl file.

Append

def append(
    path: str | bytes | int | os.PathLike,
    data: Iterable,
    newline: bool = True
) -> None: ...

append() serializes and appends an iterable of Python objects to a UTF-8-encoded jsonl file.

The first argument taken by this function is path, a path-like object giving the pathname (absolute or relative to the current working directory), or an integer file descriptor, of the jsonl file to be appended.

The second argument taken by this function is data, an iterable of Python objects to be serialized and appended to the jsonl file.

The third argument taken by this function is newline, an optional Boolean flag that, if set to False, indicates that the jsonl file does not end with a newline and should, therefore, have one added before data is appended.

License

This library is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

orjsonl-0.1.1.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

orjsonl-0.1.1-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file orjsonl-0.1.1.tar.gz.

File metadata

  • Download URL: orjsonl-0.1.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.0

File hashes

Hashes for orjsonl-0.1.1.tar.gz
Algorithm Hash digest
SHA256 533a6beac19115b34ddb55f9c9776c991d648186116436ea019ec56f74b77f70
MD5 0da755f480ade50809f934ff5ccd2234
BLAKE2b-256 02f98d8d4ccf2b4c233f920ca15c8fadffd66bc82680851c920e8eb7d8afbeca

See more details on using hashes here.

File details

Details for the file orjsonl-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: orjsonl-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.0

File hashes

Hashes for orjsonl-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e03de7bd9e0cba24881753a6e1e23801f401aa81ba2c089f64940399908bdffe
MD5 0c69534b3038f67813212e7bab4dea85
BLAKE2b-256 644e8decaa235645ae0488d91d27e45f61323056f9036faecc1b32fb4e15621f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page