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: a unit of data that carries a path and a timestamp, and that can be loaded, saved, or transformed. Every state stands for a valid file, whether it is held in memory or read from disk on demand.
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.
Installation
You can install the IOkit library using pip:
pip install iokit
The base install carries no third-party backends, and covers txt, bin, dat, json, gz, zip, and tar. Every other format, along with downloading over web, rests on an optional dependency, all of which come with the ultra extra:
pip install "iokit[ultra]"
Without it, a format tells you what it wants:
from iokit import Yaml
Yaml({"key": "value"}, "single")
ModuleNotFoundError: Missing required packages: PyYAML>=6.0.1. Install with: pip install PyYAML
Usage
Here are some examples of how to use the I/O Kit library:
Text File Handling
from iokit import Txt
text = "Hello, World!"
state = Txt(text, "text")
print(state)
print(state.load())
text.txt (13B)
Hello, World!
The first argument is the payload, the second the stem: the name with the extension left off. A whole path may be given instead, extension included.
from iokit import Json
state = Json({"key": "value"}, path="reports/summary.json")
print(state.path, state.name, state.stem, state.suffix, state.size)
reports/summary.json summary.json summary .json 16
JSON
from iokit import Json
data = {"key": "value"}
state = Json(data, "single")
print(state)
print(state.load())
single.json (16B)
{'key': 'value'}
YAML
from iokit import Yaml
data = {"key": "value"}
state = Yaml(data, "single")
print(state)
print(state.load())
single.yaml (11B)
{'key': 'value'}
GZip Compression
Compressing a state appends .gz to its path, and loading the result gives the original state back.
from iokit import Txt
state = Txt("Hello, World! " * 1000, "data").gzip()
print(state)
print(len(state.load().load()))
data.txt.gz (133B)
14000
Tar Archive
Archives load lazily, yielding their members one at a time.
from iokit import Tar, Txt
state1 = Txt("First file", "text1")
state2 = Txt("Second file", "text2")
archive = Tar([state1, state2], "archive")
states = list(archive.load())
print(states)
print(states[0].load())
print(states[1].load())
[text1.txt (10B), text2.txt (11B)]
First file
Second file
Finding States
first picks the one state matching a glob pattern, filtrate yields every match.
from iokit import Tar, Txt, filtrate, first
state1 = Txt("First file", "text1")
state2 = Txt("Second file", "text2")
archive = Tar([state1, state2], "archive")
print(first(archive.load(), "?e*2.txt").load())
print([state.path for state in filtrate(archive.load(), "*.txt")])
Second file
['text1.txt', 'text2.txt']
Byte input handling
LoadedState holds bytes already encoded, and the path decides how they are read.
from iokit import LoadedState
state = LoadedState(b'{"first": 1, "second": 2}', path="data.json")
print(state)
print(state.load())
data.json (25B)
{'first': 1, 'second': 2}
Files on Disk
file takes a path as a state, reading from it only when asked. Naming the expected format checks the extension and types the payload.
from iokit import Txt, file
state = Txt("on disk", "note")
saved = state.save("/tmp/example", parents=True)
print(saved)
print(file(saved.path, Txt).load())
/tmp/example/note.txt (7B)
on disk
save_temp writes to a temporary directory that is removed on leaving the context.
from iokit import Json
with Json({"key": "value"}, "config").save_temp() as saved:
print(saved.name, saved.load())
config.json {'key': 'value'}
Downloading
web fetches a url into a state, pathed after the url and timestamped after Last-Modified when the server sends it.
from iokit import web
state = web("https://raw.githubusercontent.com/rilshok/iokit/main/LICENSE")
print(state.name)
print("MIT License" in state.data.decode("utf-8"))
LICENSE
True
Naming a format, as in web(url, Json), checks the extension of the url and types the payload, the way file does.
Encryption
Encrypting appends .enc to the path; the password is given again on loading.
from iokit import Txt
secret = Txt("classified", "notes").encrypt(password="hunter2")
print(secret)
print(secret.load(password="hunter2").load())
notes.txt.enc (32B)
classified
Checksums
from iokit import Txt
state = Txt("Hello, World!", "text")
print(state.digest("sha256").base64)
print(state.digest("xxh128").base64url)
3/1gIbsr1bCvZ2KQgJ7DpTGR3YHH9wpLKGiKNiGCmG8=
Ux3yhERH3VB32wOELNdTlQ
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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file iokit-0.4.0.tar.gz.
File metadata
- Download URL: iokit-0.4.0.tar.gz
- Upload date:
- Size: 25.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9de9c553cb68c48bba22804bb396e168082ae2f7bd5dca157d0d6846285b5d82
|
|
| MD5 |
3da7a57bc97084543441b09c7a52c369
|
|
| BLAKE2b-256 |
4f7aea1defa9d9a2d4fa6e9a48bc0750a4110c4b826565271eea8b354cce152b
|
Provenance
The following attestation bundles were made for iokit-0.4.0.tar.gz:
Publisher:
publish.yml on rilshok/iokit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
iokit-0.4.0.tar.gz -
Subject digest:
9de9c553cb68c48bba22804bb396e168082ae2f7bd5dca157d0d6846285b5d82 - Sigstore transparency entry: 2358902276
- Sigstore integration time:
-
Permalink:
rilshok/iokit@4d03aac33cba01a9d732748bdc847e833a43b7b8 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/rilshok
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4d03aac33cba01a9d732748bdc847e833a43b7b8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file iokit-0.4.0-py3-none-any.whl.
File metadata
- Download URL: iokit-0.4.0-py3-none-any.whl
- Upload date:
- Size: 36.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8706da02845b43b02147df33c2ce4b80187bda59786cb167cf4e3b318c267e20
|
|
| MD5 |
cc2c1ddd420abb05fc4a9bd8ad4ccb40
|
|
| BLAKE2b-256 |
82c2d31dda046ebd10e898af0af538d346dec918364a9245096034b2e1e3a030
|
Provenance
The following attestation bundles were made for iokit-0.4.0-py3-none-any.whl:
Publisher:
publish.yml on rilshok/iokit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
iokit-0.4.0-py3-none-any.whl -
Subject digest:
8706da02845b43b02147df33c2ce4b80187bda59786cb167cf4e3b318c267e20 - Sigstore transparency entry: 2358902553
- Sigstore integration time:
-
Permalink:
rilshok/iokit@4d03aac33cba01a9d732748bdc847e833a43b7b8 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/rilshok
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4d03aac33cba01a9d732748bdc847e833a43b7b8 -
Trigger Event:
push
-
Statement type: