A key value store
Project description
Python KVStore
A simple Key-Value store (similar to redis) built in python.
Sets can expire, not expire, and be saved with any arbitrary data. So you can set it as a JSON string, a dict, int, or any other value. It is up to the developer to implement and parse types correctly.
Projects Using
Notable Features
# create a new KVStore
kv1 = KVStore(name="transactions", dump_dir="/home/reece/kvstores")
# Set a key. Defaults to -1 timeout (no timeout)
kv1.set("tx;UUID-HERE", "{"data":{"time":"...","amount":"...","currency":"..."}}")
# Get the key, returns None if not found (ex: expired or never set)
res = kv1.get("tx;UUID-HERE")
# Set this key to expire in 100 seconds
kv1.set("other;expire_later", "some string here", 100)
# Store data in multiple sub keys (hashset).
# You can only set a timeout on the parent key for now IF its a new set. Else use .hset_expire(...)
kv1.hset("parent_key", "subkey1", "value", 10)
kv1.hset("parent_key", "subkey2", "value2")
kv1.hget("parent_key", "subkey1") # returns "value"
# Set values and increment a counter
kv1.set("counter", 0)
kv1.incr("counter") # returns 1
kv1.incr("counter", amount=4) # returns 5
# Keys
kv1.get_keys() # returns all non expired keys
kv1.get_keys("tx;*") # returns keys matching the regex
# Save current memory state to disk (the dump_dir set on initialize.)
kv1.dump()
# clear the store
kv1.clear()
# Load the previous dump from file
kv1.load()
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
py_kvstore-0.0.7.tar.gz
(5.4 kB
view details)
Built Distribution
File details
Details for the file py_kvstore-0.0.7.tar.gz
.
File metadata
- Download URL: py_kvstore-0.0.7.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2072bf626c5987377f5fae504c16b2f770a90a7d3a4f09aa99d398d416ad50b0 |
|
MD5 | c23f8f8dc87fb4132f0d7638bc8cf960 |
|
BLAKE2b-256 | a2c3d747d8563d652142827f87bc88b2317e9a8f6f6e85dbbbe4d82c66fd913a |
File details
Details for the file py_kvstore-0.0.7-py3-none-any.whl
.
File metadata
- Download URL: py_kvstore-0.0.7-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab30e5f99d3a5efbc04eb8811c8f56b6b245ff8a48f72a740778d87279c661c7 |
|
MD5 | bf1a7483514e8eb86a1a01b7f2b98cd6 |
|
BLAKE2b-256 | db69381f2b903ce18d5f43472dc2ea96976c691ff59e319d21715b5cdd70916f |