A simple Python library for handling jsonlines files.
Project description
jsonl
About
jsonl is a library that includes useful tools for working with jsonlines data as described: https://jsonlines.org/
Features:
- 🌎 Offers an API similar to Python's standard
json
module. - 🚀 Supports custom serialization/deserialization callbacks. By default, it uses the standard
json
module. - 🗜️ Enables compression using
gzip
,bzip2
, andxz
formats. - 🔧 Load files containing broken lines, skipping any malformed lines.
- 📦 Provides a simple API for incremental writing to multiple files.
Installation (via pip)
pip install py-jsonl
Getting Started
Dump an iterable to a JSON Lines file.
import jsonl
data = [
{"name": "Gilbert", "wins": [["straight", "7♣"], ["one pair", "10♥"]]},
{"name": "May", "wins": []},
]
jsonl.dump(data, "file.jsonl")
Load a JSON Lines file into an iterable of objects.
import jsonl
path = "file.jsonl"
data = [
{"name": "Gilbert", "wins": [["straight", "7♣"], ["one pair", "10♥"]]},
{"name": "May", "wins": []},
]
jsonl.dump(data, path)
iterable = jsonl.load(path)
print(tuple(iterable))
Documentation
See project documentation for more details and examples.
Development
Unit tests
(env)$ pip install -r requirements-dev.txt # Ignore this command if it has already been executed
(env)$ pytest tests/
(env)$ pytest --cov jsonl # Tests with coverge
Build documentation
(env)$ pip install -r requirements-docs.txt # Ignore this command if it has already been executed
(env)$ mkdocs serve # Start the live-reloading docs server
(env)$ mkdocs build # Build the documentation site
License
This project is licensed under the terms of 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
py_jsonl-1.3.8.tar.gz
(7.5 kB
view hashes)