Skip to main content

iokit

Python library for serialization and file operations. Unifies multiple format codecs (JSON, YAML, Tar, etc.) with a single State interface that combines data, path, and timestamp.

Installation

Base install covers txt, bin, dat, json, gz, zip, tar:

pip install iokit

For all formats and web download support:

pip install iokit[ultra]

Missing formats will tell you what to install:

from iokit import Yaml
Yaml({"key": "value"}, "file")
ModuleNotFoundError: Missing required packages: PyYAML>=6.0.1. Install with: pip install PyYAML

Quick Start

Work with data as States. Each State carries the data, a path, and a timestamp. Load and save without thinking about formats.

JSON file:

from iokit import Json

state = Json({"key": "value"}, path="config.json")
print(state.path)      # config.json
print(state.size)      # 16
print(state.load())    # {'key': 'value'}

Text file:

from iokit import Txt

state = Txt("Hello, World!", "message")
state.save("/tmp/data", parents=True)

Load any file from disk:

from iokit import file

state = file("/path/to/file.txt")
content = state.load()

Common Operations

Chain transformations:

from iokit import Txt

state = Txt("Secret data", "notes")
encrypted = state.encrypt(password="secret")
compressed = encrypted.gzip()
compressed.save("/tmp")

Load compressed:

loaded = encrypted.load(password="secret").load()

Archives:

from iokit import Tar, Txt

file1 = Txt("First", "a")
file2 = Txt("Second", "b")

archive = Tar([file1, file2], "bundle")
states = list(archive.load())

Find states by pattern:

from iokit import filtrate, first

results = filtrate(archive.load(), "*.txt")
first_match = first(archive.load(), "a*")

Download:

from iokit import web

state = web("https://example.com/data.json", Json)
data = state.load()

A data: URL is decoded where it stands, without reaching the network. It carries no name for its payload, so the state is left with the bare extension of its media type:

state = web("data:application/json;base64,eyJhIjogMX0=")
assert state.path == ".json"
assert state.load() == {"a": 1}

Checksum:

state.digest("sha256").base64
state.digest("xxh128").base64url

Payloads of your own, filed under a format that knows nothing of them:

from dataclasses import dataclass
from typing import Any

from iokit import Json


@dataclass
class Person:
    name: str
    age: int


class PersonJson(Json[Person]):
    def dump(self, data: Person) -> dict[str, Any]:
        return {"name": data.name, "age": data.age}

    def parse(self, data: dict[str, Any]) -> Person:
        return Person(data["name"], data["age"])


state = PersonJson(Person("Joe", 32), "joe")
print(state.path)    # joe.json
print(state.load())  # Person(name='Joe', age=32)

The file stays an ordinary joe.json, and state.load() is a Person both at runtime and for the type checker. Every format takes the same pair: Txt, Csv, Npy, and the rest.

Storage

Store and retrieve records by uid:

from iokit.storage import LocalStorage

storage = LocalStorage("/data")
storage.push("records/data.json", data)

loaded = storage.pull("records/data.json")
storage.remove("records/data.json")

for uid in storage.index(prefix="records/"):
    print(uid)

State-aware storage with automatic encoding:

from iokit.storage import StateStorage

storage = StateStorage(
    LocalStorage("/data"),
    compression=6,
    password="secret"
)

storage.push("file.json", {"data": 123})
result = storage.pull("file.json")

Contributing

Found a bug or have an idea? Open an issue or submit a pull request.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iokit-0.5.2.tar.gz (40.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iokit-0.5.2-py3-none-any.whl (56.1 kB view details)

Uploaded Python 3

File details

Details for the file iokit-0.5.2.tar.gz.

File metadata

  • Download URL: iokit-0.5.2.tar.gz
  • Upload date:
  • Size: 40.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for iokit-0.5.2.tar.gz
Algorithm Hash digest
SHA256 6f2e2940873587f4f1fe483410e4e3d01871296f57228d0e725dccf790d9efb4
MD5 4fb5435b08accefbe788ff5924b38617
BLAKE2b-256 1295b194b14584ee83e5f1a887ee96be7cd0bb43806316e75818e9051500086d

See more details on using hashes here.

Provenance

The following attestation bundles were made for iokit-0.5.2.tar.gz:

Publisher: publish.yml on rilshok/iokit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file iokit-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: iokit-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 56.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for iokit-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7cce6ee5bbfac3a5756bc213e60b6f0c5f646e5000f65f1677c22fba9f6f10da
MD5 a2e7ae50c3d4d2976449bfbd5ea5606a
BLAKE2b-256 f7ab9f4334acb7d28c9c1fb330d1644c0e4558defc4a479db82e2cc677720185

See more details on using hashes here.

Provenance

The following attestation bundles were made for iokit-0.5.2-py3-none-any.whl:

Publisher: publish.yml on rilshok/iokit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.5.2 This release

2 files

0.5.1

2 files

0.5.0

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.0

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page