Generic interface to key-value stores
Project description
Pythonic, unified API to multiple key-value stores.
This base package includes:
Abstract definition of the Store API, which all storage systems follow.
In-memory caching of data of values from a store using LRU eviction.
In-memory transient storage backed by Python dictionaries.
Simple filesystem-based storage using directories and plain files.
Adaptors for transparent (de)serialization of stored values.
Support for additional storage system is by packages distributed separately:
indicium-leveldb (planned, not yet available).
indicium-memcache (planned, not yet available).
Usage
Create a Store which saves content on-disk, using JSON for serialization, and store somwthing that resembles an user account:
from indicium.base import Serializer
import json
filestore = Serializer(FSStore("./data", extension=".json"), pickle)
filestore.put("/user/jdoe", { "id": "jdoe", "name": "John Doe",
"email": "j@doe.org", "password": "supersekrit" })
account = filestore.get("/user/jdoe")
assert account["email"] == "j@doe.org"
The ./data/user/jdoe.json will contain the account data in JSON format. The following adds an in-memory cache to the above store, which holds up to 100 elements, to speed up access to data:
from indicium.cache import LRUCache
cachedstore = LRUCache(filestore, size=100)
account = cachedstore.get("/user/jdoe")
assert account["email"] == "j@doe.org"
Once you have a collection of objects, you can run use queries to retrieve all the elements whose keys match a certain pattern. For example, this obtains the user accounts with an identifier starting with the letter j from the store above:
for key, account cachedstore.query("/user/j*"):
print(account["id"], account["name"])
Installation
All stable releases are uploaded to PyPI, so you can install them and upgrade using pip:
pip install indicium
Alternatively, you can install the latest development code —at your own risk— directly from the Git repository:
pip install git://github.com/aperezdc/indicium
Development
If you want to contribute, please use the usual GitHub workflow:
Clone the repository.
Hack on your clone.
Send a pull request for review.
If you do not have programming skills, you can still contribute by reporting issues that you may encounter. Contributions to the documentation are very welcome, too!
Inspiration
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file indicium-0.1.0a3.tar.gz
.
File metadata
- Download URL: indicium-0.1.0a3.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 294e491e93e853dd4bc1358042be5f863c20b2c1d2c8ed7690095f22256200d0 |
|
MD5 | 11177273b8fd19abef5a12d3f8a0ef4d |
|
BLAKE2b-256 | fdffcb7ed6c19be11d39644af4f9ae2235c3ccef1187ef0d4d80760404fd8be1 |