Registry / data / zict
library3.0.0pypypi✓ verified 23d ago

Zict provides a collection of abstract MutableMapping classes that can be composed to build complex storage systems. It allows developers to create custom dictionaries that manage data across different locations (in-memory, on disk), apply various eviction policies (like LRU), and handle data transformations (compression, serialization). This enables intuitive interfaces over sophisticated storage strategies. The library is currently at version 3.0.0 and appears to be actively maintained.

pip install zict
INSTALL
IMPORT
SIG · ZICT
Z
zict
datapythonv3.0.0
Install
1.6s avg
Import
245ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.268s · 18.2MB
glibc
py 3.103.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)
Debug
Known issues
gotchaWhen using `zict.Sieve` in a multithreaded environment, be aware that the `__getitem__` and `__setitem__` methods of the *underlying mappings* are not protected by locks. This means if multiple threads access the same underlying mapping concurrently via Sieve, race conditions could occur. Only `__contains__` and `__delitem__` methods of underlying mappings are protected if they are fast.
fix
Implement external locking mechanisms or ensure thread-safe underlying mappings for concurrent `__getitem__` and `__setitem__` operations when using `zict.Sieve`.
affects: All versions
gotchaMappings that interface with system resources (e.g., `zict.File`, `zict.LMDB`) must have their `close()` method called to release those resources. Failure to do so can lead to resource leaks, file locks, or data corruption, especially in long-running applications or when reopening mappings.
fix
Always call the `.close()` method on `zict` mappings that manage external resources when they are no longer needed. Consider using a `with` statement if the mapping supports the context manager protocol, or a `try...finally` block.
affects: All versions
gotcha`zict.LMDB` requires the `lmdb` Python package to be installed separately to function correctly. It is not listed as a direct dependency of `zict` itself. Without it, attempting to use `zict.LMDB` will result in an `ImportError`.
fix
If planning to use `zict.LMDB`, ensure `pip install lmdb` is run in your environment.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'zict'
The 'zict' library is not installed in your current Python environment.
fix
pip install zict
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`.
fix
Ensure 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`.
fix
Either 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.
fix
Provide 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.

Agent activity
51 hits · last 30 days
node
42
OpenAI (training)
2
Resources
zict — pip install zict · libregistry