Skip to main content

Crash-recoverable memory-mapped ring buffer for JSON records (SD-card friendly-ish)

Project description

sdsavior

Most likely i have re-invented the wheel here. But i was to lazy to find something like this. So, here you go...

A crash-recoverable, memory-mapped ring buffer for JSON records, designed for SD-card-ish environments (where constant small writes are a fun way to speedrun media death).

Install

pip install sdsavior

Quick Start

from sdsavior import SDSavior

rb = SDSavior(
    data_path="data.ring",
    meta_path="data.meta",
    capacity_bytes=8 * 1024 * 1024,
)

rb.open()
rb.append({"hello": "pi"})
rb.append({"n": 123})

for seq, ts_ns, obj in rb.iter_records():
    print(seq, ts_ns, obj)

rb.close()

Or with a context manager:

from sdsavior import SDSavior

with SDSavior("data.ring", "data.meta", 8 * 1024 * 1024) as rb:
    rb.append({"ok": True})

CLI

Export current contents to a JSONL

sdsavior export --data data.ring --meta data.meta --capacity 8388608 --out out.jsonl

IMPORTANT NOTES

  • Records are stored as JSON lines (\\n appended).
  • Metadata is double-buffered with CRC and a commit counter for crash recovery.
  • Already-encoded JSON can be written with append_json_bytes(...) to skip a decode/encode round trip.
  • group_commit_records=N can batch fsync work while keeping CRC-based crash recovery.
  • By default it does not fsync data pages on every append (to reduce wear); metadata is fsync'd.

TODO

  • fix ci for pypy publishing...
  • smarter fsync strategy
  • indexing / partial recovery scans

Project details


Download files

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

Source Distribution

sdsavior-1.1.0.tar.gz (79.7 kB view details)

Uploaded Source

Built Distribution

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

sdsavior-1.1.0-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file sdsavior-1.1.0.tar.gz.

File metadata

  • Download URL: sdsavior-1.1.0.tar.gz
  • Upload date:
  • Size: 79.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for sdsavior-1.1.0.tar.gz
Algorithm Hash digest
SHA256 5690364af8819eaa6189cef91d09a4c03be6e089ab772382e0627b9bccc873f8
MD5 026e39a9777e0cdf7fbe0558b510dd0d
BLAKE2b-256 8c2fe4dc4f0ce5253327f8f701703aeea433f73333821dd198076dc9f778b726

See more details on using hashes here.

File details

Details for the file sdsavior-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: sdsavior-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for sdsavior-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 18c01ca00bc25e37ffe1e04088b4b092b1f80dfaa9791534e9cbf9ea92a41eb1
MD5 38f0e823f98c053ceacb14d9ded73f93
BLAKE2b-256 a7cfc4a5dd3cb062e39d4b01f1be29977fc67debda8edc5a2ea1e03bd441a15d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page