NFS-safe persistent dictionary. Atomic file-per-key writes, in-memory read cache.
Project description
nfsdict
NFS-safe persistent dictionary for Python (CPython & PyPy).
One file per key, atomic writes via temp + rename, in-memory read cache so reads never touch NFS after initial load. Corruption of one file loses that key only — never the whole store.
Install
pip install nfsdict
Usage
from nfsdict import NfsDict
# default: pickle serializer, ~/.local/share/nfsdict/default/
d = NfsDict()
# custom name and directory
d = NfsDict("my_cache", base_dir="/shared/nfs/cache")
# json serializer (human-readable, but values must be JSON-serializable)
d = NfsDict("my_cache", serializer="json")
# use it like a normal dict
d["key"] = {"nested": [1, 2, 3]}
print(d["key"])
del d["key"]
print(len(d))
# re-read from disk (if another process may have written)
d.sync()
How it works
- Each key is stored as a separate file, named by its SHA-256 hash, inside a two-character prefix subdirectory for filesystem-friendly sharding.
- Writes are atomic: data is written to a temp file, fsynced, then renamed into place.
- An in-memory cache is populated once at init and updated on every write/delete — so reads are pure dict lookups with zero NFS calls.
- Corrupted files are silently skipped during loading: you lose that one key, not the whole store.
API
NfsDict(name="default", base_dir=None, serializer="pickle")
| Parameter | Description |
|---|---|
name |
Namespace / subdirectory name |
base_dir |
Storage root. Defaults to platformdirs.user_data_dir |
serializer |
"pickle" or "json" |
Supports the full MutableMapping interface: __getitem__, __setitem__, __delitem__, __contains__, __iter__, __len__, plus .sync() to re-read from disk.
License
MIT
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
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 nfsdict-0.1.0.tar.gz.
File metadata
- Download URL: nfsdict-0.1.0.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30eebc58d1e8b2fcf8b3b6911ca54fe5cc159c0aebdf6a188882447ced6ed5d0
|
|
| MD5 |
2a653221fa123074bab688fe3e5e44c4
|
|
| BLAKE2b-256 |
914bfa5884c028d31ac63b9f8a1b0f6702f1b94f2dd9d6792c962cc5475aed37
|
File details
Details for the file nfsdict-0.1.0-py3-none-any.whl.
File metadata
- Download URL: nfsdict-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d1518eeda799f11db805b839d1685708a56f571ce8704d9f3e5c881aad371bd
|
|
| MD5 |
81e0acb87a5d3cc570864ad0e85d9e26
|
|
| BLAKE2b-256 |
953d36498178e40479aa1edaeb0be1a1fb15494b88a87a319da342447283ec1c
|