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(forIjsonFileStore)
Project details
Release history Release notifications | RSS feed
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7c2a977c324443802903ef82e0c3adc625c417afd3cdd53f1dc682b323dbc76
|
|
| MD5 |
5174a086526ad3c19e5bb325f0ad3938
|
|
| BLAKE2b-256 |
8bd94a676b2fef4498717272ca5f989fa0a56262f327a870b991483654559695
|
Provenance
The following attestation bundles were made for oj_persistence-0.0.1.tar.gz:
Publisher:
publish.yml on ownjoo-org/persistence
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
oj_persistence-0.0.1.tar.gz -
Subject digest:
e7c2a977c324443802903ef82e0c3adc625c417afd3cdd53f1dc682b323dbc76 - Sigstore transparency entry: 1243012608
- Sigstore integration time:
-
Permalink:
ownjoo-org/persistence@430afb16191a55ba0d388959f686ef6e0913bd2a -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/ownjoo-org
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@430afb16191a55ba0d388959f686ef6e0913bd2a -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc8923e4e616c7a2bc15711bbc57a89750c1c6b336834ff25165c5371809629b
|
|
| MD5 |
041880361287f99a770c9113e9ab4d55
|
|
| BLAKE2b-256 |
2ae4520cd00efe046e327e890a0882883a0bbd0f2cebc30dc509c3d1d7e1ac2c
|
Provenance
The following attestation bundles were made for oj_persistence-0.0.1-py3-none-any.whl:
Publisher:
publish.yml on ownjoo-org/persistence
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
oj_persistence-0.0.1-py3-none-any.whl -
Subject digest:
fc8923e4e616c7a2bc15711bbc57a89750c1c6b336834ff25165c5371809629b - Sigstore transparency entry: 1243012614
- Sigstore integration time:
-
Permalink:
ownjoo-org/persistence@430afb16191a55ba0d388959f686ef6e0913bd2a -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/ownjoo-org
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@430afb16191a55ba0d388959f686ef6e0913bd2a -
Trigger Event:
release
-
Statement type: