simplekv
raw JSON → 0.14.1 verified Fri May 01 auth: no python
A key-value store for binary data, supporting multiple backends including filesystem, Redis, MongoDB, Azure Blob Storage, and Amazon S3. Current version: 0.14.1. Release cadence is irregular, with occasional minor and patch releases.
pip install simplekv Common errors
error ImportError: No module named 'simplekv.contrib.redis' ↓
cause The `redis` extra dependency is missing.
fix
Install simplekv with redis support:
pip install simplekv[redis] error AttributeError: 'generator' object has no attribute 'sort' ↓
cause `keys()` now returns a generator instead of a list (since 0.12.0).
fix
Convert to list:
list(store.keys()).sort() error TypeError: can't pickle 'generator' objects ↓
cause Trying to pickle the result of `keys()` (a generator) in multiprocessing context.
fix
Convert to list before passing to other processes:
list(store.keys()) Warnings
gotcha The `keys()` method returns a generator in Python 3 (since 0.12.0), not a list. This is a change from earlier versions where it returned a list. Wrap with `list()` if you need a list. ↓
fix Use `list(store.keys())` to get a list.
breaking In version 0.14.0, the Azure backend switched to `azure-storage-blob` version 12. Old code using the old Azure SDK will break. The store class name is now `AzureBlockBlobStore`. ↓
fix Update dependencies to `azure-storage-blob>=12` and import `AzureBlockBlobStore`.
gotcha The `S3Store`'s `open()` method removed seek/tell support in version 0.11.7 due to leaking HTTP connections. If you rely on random access on S3 file-like objects, this will break. ↓
fix Do not use `seek()` or `tell()` on S3Store opened files; read sequentially or download the entire object.
Install
pip install simplekv[redis] pip install simplekv[s3] Imports
- KeyValueStore
from simplekv import KeyValueStore - RedisStore
from simplekv.contrib.redis import RedisStore - S3Store
from simplekv.contrib.s3 import S3Store - FilesystemStore
from simplekv.fs import FilesystemStore - MongoStore
from simplekv.contrib.mongo import MongoStore - AzureBlockBlobStore
from simplekv.contrib.azure import AzureBlockBlobStore
Quickstart
import os
from simplekv.contrib.redis import RedisStore
# Initialize store (assuming Redis running on localhost)
store = RedisStore(host='localhost', port=6379)
# Put a value
store.put('key', b'value')
# Get a value
value = store.get('key')
print(value)
# Delete a value
store.delete('key')