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.
A best-effort key index speeds up init by avoiding expensive directory scans. The index is advisory — exact lookups always fall back to disk, so keys written by other processes are never lost.
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")
# lazy loading: only keys are loaded at init, values fetched on first access
d = NfsDict("my_cache", lazy=True)
# 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 (full scan, call if another process may have written)
d.sync()
# context manager flushes index on exit
with NfsDict("my_cache") as d:
d["key"] = "value"
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
os.replaced 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.
- If a key is not in the cache,
__getitem__falls back to reading its file directly from disk (covers keys written by other processes). - A best-effort key index avoids the expensive
rglobdirectory scan on startup. If the index is missing or corrupted, a full scan runs automatically and rebuilds it. - Corrupted value files are silently skipped during loading: you lose that one key, not the whole store.
API
NfsDict(name="default", base_dir=None, serializer="pickle", lazy=False)
| Parameter | Description |
|---|---|
name |
Namespace / subdirectory name |
base_dir |
Storage root. Defaults to platformdirs.user_data_dir |
serializer |
"pickle" or "json" |
lazy |
If True, values are loaded on first access, not at init |
Supports the full MutableMapping interface: __getitem__, __setitem__, __delitem__, __contains__, __iter__, __len__, plus:
.sync()— full re-read from disk.close()— flush the key index to disk- Context manager (
with NfsDict(...) as d:)
License
MIT
Metadata
Release files for nfsdict 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nfsdict-0.2.2.tar.gz | 5.9 kB | Without provenance | Details for nfsdict-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nfsdict-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for nfsdict-0.2.2-py3-none-any.whl |
Total release size: 12.1 kB
Release files / nfsdict-0.2.2.tar.gz
| Download URL | nfsdict-0.2.2.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8c9bfb7b4877bbdc0eda37ff7ae345a48485c8fe399eeabeb28bc722c3fd5145
|
|
BLAKE2b-256 checksum How to use checksums |
43cf26a567016af75dd15b6a706c4456fc5bfa456200bda96cb423e0cff1af56
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.10
|
Release files / nfsdict-0.2.2-py3-none-any.whl
| Download URL | nfsdict-0.2.2-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1c0687389108a645c7789146fbca52fd863495bc5073393ceb9d0d5f0aed0fde
|
|
BLAKE2b-256 checksum How to use checksums |
fe88522e5ef860dd019d8ad632671221f7b685489d13387aafd6737fad5223ce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.10
|
Security for nfsdict 0.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.