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.
- Host: GitHub
- URL: https://github.com/itsluketwist/jldc
- Owner: itsluketwist
- License: mit
- Created: 2024-01-24T09:36:24.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-25T10:58:47.000Z (about 1 year ago)
- Last Synced: 2024-04-25T11:54:34.044Z (about 1 year ago)
- Topics: dataclasses, dataclasses-json, jsonl, jsonlines
- Language: Python
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.
## *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: intsave_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 installpre-commit autoupdate
pre-commit run --all-files
```## *testing*
Run the test suite using:
```shell
pytest .
```