Metadata-Version: 2.4
Name: iokit
Version: 0.3.2
Summary: Input Output Kit
Author-email: "Vladislav A. Proskurov" <rilshok@pm.me>
License: MIT
Project-URL: Homepage, https://github.com/rilshok/iokit
Project-URL: Repository, https://github.com/rilshok/iokit.git
Project-URL: Issues, https://github.com/rilshok/iokit/issues
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: humanize>=4.9.0
Requires-Dist: jsonlines>=4.0.0
Requires-Dist: python-dateutil>=2.8.2
Requires-Dist: python-dotenv>=1.0.1
Requires-Dist: PyYAML>=6.0.1
Requires-Dist: pytz>=2024.1
Requires-Dist: requests>=2.32.3
Requires-Dist: typing-extensions>=4.8.0
Requires-Dist: cryptography>=41.0.7
Requires-Dist: numpy>=1.21.1
Requires-Dist: soundfile>=0.12.1
Requires-Dist: pandas>=1.5.3
Requires-Dist: Pillow>=10.4.0
Requires-Dist: xxhash>=3.4.1
Provides-Extra: dev
Requires-Dist: iokit[lint,test]; extra == "dev"
Provides-Extra: lint
Requires-Dist: mypy>=1.7.1; extra == "lint"
Requires-Dist: ruff>=0.6.3; extra == "lint"
Requires-Dist: types-pytz>=2024.1; extra == "lint"
Requires-Dist: types-requests>=2.31.0; extra == "lint"
Requires-Dist: types-PyYAML>=6.0.12; extra == "lint"
Requires-Dist: types-python-dateutil>=2.8.19; extra == "lint"
Provides-Extra: test
Requires-Dist: pytest>=8.2.2; extra == "test"
Requires-Dist: pytest-cov==6.0.0; extra == "test"
Requires-Dist: pytest-xdist>=3.6.1; extra == "test"
Dynamic: license-file

# I/O Kit Python Library

IOKit is a Python library that offers a suite of utilities for managing a wide range of input/output operations. Central to its design is the concept of a `State`, where each state signifies a unit of data that can be loaded, saved, or transformed. Each state corresponds to a valid file state, represented as a bytes-like object.

IOKit abstracts and unifies serialization and deserialization operations from various libraries into a single, cohesive interface. This allows for direct manipulation of the file's state in memory, eliminating the need for disk interaction. Consequently, it facilitates the (de)serialization of data in multiple formats, such as `json`, `yaml`, `txt`, `tar`, `gzip`, among others. This abstraction not only simplifies data handling but also enhances efficiency by reducing disk I/O operations.

## Installation

You can install the IOkit library using pip:

```bash
pip install iokit
```

## Usage

Here are some examples of how to use the I/O Kit library:

### Text File Handling

```python
from iokit import Txt

text = "Hello, World!"
state = Txt(text, name="text")
print(state)
print(state.load())
```

```plain-text
text.txt (13B)
Hello, World!
```

### JSON

```python
from iokit import Json

data = {"key": "value"}
state = Json(data, name="single")
print(state)
print(state.load())
```

```plain-text
single.json (16B)
{'key': 'value'}
```

### YAML

```python
from iokit import Yaml

data = {"key": "value"}
state = Yaml(data, name="single")
print(state)
print(state.load())
```

```plain-text
single.yaml (11B)
{'key': 'value'}
```

### GZip Compression

```python
from iokit import Txt, Gzip

data = "Hello, World! "* 1000
state = Gzip(Txt(data, name="data"))
print(state)
print(len(state.load().load()))
```

```plain-text
data.txt.gz (133B)
14000
```

### Tar Archive

```python
from iokit import Tar, Txt

state1 = Txt("First file", name="text1")
state2 = Txt("Second file", name="text2")
archive = Tar([state1, state2], name="archive")
states = archive.load()
print(states)
print(states[0].load())
print(states[1].load())
```

```plain-text
[text1.txt (10B), text2.txt (11B)]
First file
Second file
```

### Find State

```python
from iokit import Tar, find_state

state1 = Txt("First file", name="text1")
state2 = Txt("Second file", name="text2")
archive = Tar([state1, state2], name="archive")

state = find_state(archive.load(), "?e*2.txt")
print(state.load())
```

```plain-text
Second file
```

### Byte input handling

```python
from iokit import State

state = State(b"{\"first\": 1, \"second\": 2}", name="data.json")
print(state.load())
```

```plain-text
{'first': 1, 'second': 2}
```


## Contributing

Contributions to the IOkit library are welcome. Please feel free to submit a pull request or open an issue on the GitHub repository.

## License

The IOkit library is licensed under the MIT License. You can use it for commercial and non-commercial projects without any restrictions.
