Metadata-Version: 2.1
Name: jldc
Version: 0.0.5
Summary: Simplify using JSONLines files alongside dataclasses.
Author-email: Lukas Twist <itsluketwist@gmail.com>
License: MIT License
        
        Copyright (c) 2023 Luke Twist
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/itsluketwist/jldc
Keywords: jldc,jsonlines,dataclasses
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: dacite ~=1.8.1
Provides-Extra: dev
Requires-Dist: pre-commit ; extra == 'dev'
Requires-Dist: pytest ; extra == 'dev'
Provides-Extra: ml
Requires-Dist: numpy ~=1.26.0 ; extra == 'ml'

# **jldc**

Simplify using [JSON Lines](https://jsonlines.org/) files alongside 
[python dataclass](https://docs.python.org/3/library/dataclasses.html) ([PEP-557][pep-557]) 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)


<div>
    <!-- badges from : https://shields.io/ -->
    <!-- logos available : https://simpleicons.org/ -->
    <a href="https://opensource.org/licenses/MIT">
        <img alt="MIT License" src="https://img.shields.io/badge/Licence-MIT-yellow?style=for-the-badge&logo=docs&logoColor=white" />
    </a>
    <a href="https://www.python.org/">
        <img alt="Python 3.10+" src="https://img.shields.io/badge/Python_3.10+-blue?style=for-the-badge&logo=python&logoColor=white" />
    </a>
    <a href="https://jsonlines.org/">
        <img alt="JSON Lines" src="https://img.shields.io/badge/JSON Lines-black?style=for-the-badge&logo=JSON&logoColor=white" />
    </a>
</div>


## *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 GitHub, using pip:

```shell
pip install 'git+https://github.com/itsluketwist/jldc'
```

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

```shell
pip install 'jldc[ml]@git+https://github.com/itsluketwist/jldc'
```

## *development*

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 .
```
