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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file orjsonl-0.1.0.tar.gz
.
File metadata
- Download URL: orjsonl-0.1.0.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d763701524aa5495208d418977dfec82e5ac662a4814df29e5b8f7c82e74eec |
|
MD5 | 6d5084d4d8f8e4eae555dd6cbdfb9005 |
|
BLAKE2b-256 | bc9d7a6e01b638d2b5aca2004d53f5a41f3b6c78845e991624d4783fc2451b0a |
File details
Details for the file orjsonl-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: orjsonl-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9df5aa734e650bd05f525e0e84f3070a5ae6cde2d8476b40afae5291008ea09f |
|
MD5 | 50f273ea76b1d4b766b0b486c2b90a87 |
|
BLAKE2b-256 | 93055923929a13ef891edd21ec1746564b5a6c337554352c8dd1d236317aeb0a |