An open API service indexing awesome lists of open source software.

https://github.com/itsluketwist/jldc

Easily read/write JSONLines files that include dataclasses.
https://github.com/itsluketwist/jldc

dataclasses dataclasses-json jsonl jsonlines

Last synced: 2 months ago
JSON representation

Easily read/write JSONLines files that include dataclasses.

Awesome Lists containing this project

README

        

# **jldc**

Simplify using [JSON Lines](https://jsonlines.org/) files alongside
[python dataclass](https://docs.python.org/3/library/dataclasses.html) ([PEP-557](https://peps.python.org/pep-0557/))
objects, with convenient one-line reads/writes.

![check code workflow](https://github.com/itsluketwist/jldc/actions/workflows/check.yaml/badge.svg)
![release workflow](https://github.com/itsluketwist/jldc/actions/workflows/release.yaml/badge.svg)





MIT License


Python 3.10+


JSON Lines

## *usage*

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

```python
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:

```shell
pip install jldc
```

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

```shell
pip install jldc[ml]
```

## *development*

Fork and clone the repository code:

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

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

```shell
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:

```shell
pre-commit install

pre-commit autoupdate

pre-commit run --all-files
```

## *testing*

Run the test suite using:

```shell
pytest .
```