Skip to main content

Thread-safe persistence management with pluggable storage backends

Project description

oj-persistence

Thread-safe persistence management with pluggable storage backends.

Installation

pip install oj-persistence

Overview

oj-persistence provides a singleton PersistenceManager that acts as the single I/O interface for all data operations. Callers register named stores with the manager and interact exclusively through it — stores are never touched directly for data operations.

Designed for use with multi-threaded applications and async pipelines (e.g. io_chains).

Quick start

from oj_persistence import PersistenceManager, InMemoryStore, NdjsonFileStore

pm = PersistenceManager()

# Register stores by name
pm.get_or_create('cache', lambda: InMemoryStore())
pm.get_or_create('events', lambda: NdjsonFileStore('events.ndjson'))

# All data ops go through the manager
pm.create('cache', 'user:1', {'name': 'Alice'})
pm.upsert('events', 'evt:1', {'type': 'login', 'user': 'user:1'})

value = pm.read('cache', 'user:1')   # {'name': 'Alice'}
pm.update('cache', 'user:1', {'name': 'Alice', 'role': 'admin'})
pm.delete('cache', 'user:1')

results = pm.list('cache', predicate=lambda v: v.get('role') == 'admin')

CRUDL semantics

Method Behaviour
create Raises KeyError if key already exists
read Returns None if key is missing
update Raises KeyError if key does not exist
upsert Creates or overwrites — never raises
delete No-op if key is missing
list Returns all values, optionally filtered

Relational joins

ON = lambda user, order: user['id'] == order['user_id']

results = pm.join('users', 'orders', on=ON, how='left',
                  where=lambda u, o: o['total'] > 100)
# returns list of (left, right) tuples; unmatched rows have None on the missing side

Supported how values: inner (default), left, right, outer.

Storage backends

Class Format Notes
InMemoryStore In-process dict Fastest; not persistent
FlatFileStore JSON (full load/save) Simple; loads entire file per op
NdjsonFileStore NDJSON (one obj/line) Append-only creates; O(1) writes
IjsonFileStore Standard JSON (streaming) Streaming reads via ijson
CsvFileStore CSV Fieldnames inferred or pre-specified

All file-backed stores are thread-safe via a writer-preferring ReadWriteLock.

Custom stores

Implement AbstractStore:

from oj_persistence.store.base import AbstractStore

class MyStore(AbstractStore):
    def create(self, key, value): ...
    def read(self, key): ...
    def update(self, key, value): ...
    def upsert(self, key, value): ...
    def delete(self, key): ...
    def list(self, predicate=None): ...

pm.register('custom', MyStore())

Requirements

  • Python >= 3.11
  • ijson (for IjsonFileStore)

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

oj_persistence-0.0.1.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

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

oj_persistence-0.0.1-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file oj_persistence-0.0.1.tar.gz.

File metadata

  • Download URL: oj_persistence-0.0.1.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for oj_persistence-0.0.1.tar.gz
Algorithm Hash digest
SHA256 e7c2a977c324443802903ef82e0c3adc625c417afd3cdd53f1dc682b323dbc76
MD5 5174a086526ad3c19e5bb325f0ad3938
BLAKE2b-256 8bd94a676b2fef4498717272ca5f989fa0a56262f327a870b991483654559695

See more details on using hashes here.

Provenance

The following attestation bundles were made for oj_persistence-0.0.1.tar.gz:

Publisher: publish.yml on ownjoo-org/persistence

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

File details

Details for the file oj_persistence-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: oj_persistence-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for oj_persistence-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fc8923e4e616c7a2bc15711bbc57a89750c1c6b336834ff25165c5371809629b
MD5 041880361287f99a770c9113e9ab4d55
BLAKE2b-256 2ae4520cd00efe046e327e890a0882883a0bbd0f2cebc30dc509c3d1d7e1ac2c

See more details on using hashes here.

Provenance

The following attestation bundles were made for oj_persistence-0.0.1-py3-none-any.whl:

Publisher: publish.yml on ownjoo-org/persistence

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

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