Skip to content

Easily read/write JSONLines files that include dataclasses.

License

Notifications You must be signed in to change notification settings

itsluketwist/jldc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jldc

Simplify using JSON Lines files alongside python dataclass (PEP-557) objects, with convenient one-line reads/writes.

check code workflow release workflow

usage

Import the library and save/load lists of dataclasses or dictionaries with a single line.

from jldc.core import load_jsonl, save_jsonl
from dataclasses import dataclass


@dataclass
class Person:
    name: str
    age: int


save_jsonl("people.jsonl", [Person("Alice", 24), Person("Bob", 32)])

data = load_jsonl("people.jsonl", [Person])

print(data)

installation

Install directly from PyPI using pip:

pip install jldc

Use the ml extra to encode/decode the numpy.ndarray type:

pip install jldc[ml]

development

Fork and clone the repository code:

git clone https://github.com/itsluketwist/jldc.git

Once cloned, install the package locally in a virtual environment:

python -m venv venv

. venv/bin/activate

pip install -e ".[dev,ml]"

Install and use pre-commit to ensure code is in a good state:

pre-commit install

pre-commit autoupdate

pre-commit run --all-files

testing

Run the test suite using:

pytest .