Install & Compatibility
Where this runs
tested against v3.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.268s · 18.2MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.6s · import 0.222s · 19MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
File
✓ from zict import File
Func
✓ from zict import Func
LRU
✓ from zict import LRU
Buffer
✓ from zict import Buffer
LMDB
✓ from zict import LMDB
Requires `lmdb` to be installed separately for full functionality.
Sieve
✓ from zict import Sieve
This example demonstrates how to compose `zict` mappings to create a multi-layered storage system. It sets up an LRU cache (`LRU`) backed by a function-transforming mapping (`Func`) for serialization and compression, which in turn writes to disk using a file-based mapping (`File`). This allows efficient in-memory caching with persistent, compressed storage.
import pickle
import zlib
import os
import shutil
from zict import File, Func, LRU
# Create a temporary directory for file storage
storage_dir = 'zict_example_storage'
if os.path.exists(storage_dir):
shutil.rmtree(storage_dir)
# 1. File: A mapping that stores values as files in a directory
a = File(storage_dir, mode='a')
# 2. Func: A mapping that applies functions (e.g., compress/decompress, dumps/loads)
# to values as they are set or retrieved from the underlying mapping.
b = Func(zlib.compress, zlib.decompress, a)
c = Func(pickle.dumps, pickle.loads, b)
# 3. LRU: A Least Recently Used (LRU) cache that wraps another mapping.
# When the LRU overflows, items are evicted to the underlying mapping (c).
d = LRU(10, c) # Keep 10 items in the LRU cache
# Store and retrieve items
d['x'] = [1, 2, 3]
d['y'] = {'a': 1, 'b': 2}
print(f"Value for 'x': {d['x']}")
print(f"Value for 'y': {d['y']}")
# Populate more items to trigger LRU eviction
for i in range(15):
d[str(i)] = i * 10
# Accessing 'x' brings it back to the fast cache (LRU)
print(f"Accessing 'x' again: {d['x']}")
# Clean up resources (important for File, LMDB, etc.)
d.close()
# Clean up the temporary storage directory
shutil.rmtree(storage_dir)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'zict'
The 'zict' library is not installed in your current Python environment.
TypeError: Buffer() argument 'slow' must be an instance of collections.abc.MutableMapping, not int
The arguments provided to `zict.Buffer` (or `fast` argument) are not instances of `collections.abc.MutableMapping`.
fixEnsure both arguments passed to `zict.Buffer` are valid mutable mapping objects, such as `dict()`.
FileNotFoundError: [Errno 2] No such file or directory: '/path/to/your/zict_directory'
The directory specified for `zict.File` does not exist, and the `auto_mkdir` option was not set to `True`.
fixEither create the directory before initializing `zict.File` or set `auto_mkdir=True` in the constructor.
TypeError: LRU() argument 'max_bytes' must be an instance of int, not str
The `max_bytes` argument provided to `zict.LRU` is not an integer, but some other type like a string.
fixProvide an integer value for `max_bytes` when initializing `zict.LRU`.
Upgrade
Version history
3.0.0latest on PyPI · released Apr 17, 2023
Audit
Dependencies
No dependency data recorded yet.