A key value datastore which stores data locally in a memory-mapped file.
Project description
# [key-value-ds](https://pypi.org/project/key-value-ds/)
##### File based Key-Value datastore
Supports basic CRD (Create, Read, Delete)
- Functionalities:
It can be initialized using an optional file path. If one is not provided, it will reliably create itself using uuid.
Key string capped at 32 characters and Value must be a JSON object capped at 16KB. (These values can be changed in config.py)
Every key supports setting a Time-To-Live property when it is created. This property is optional. If provided, it will be evaluated as an integer defining the number of seconds. Once the Time-To-Live for a key has expired, the key will no longer be available for Read or Delete operations.
Only one process can access the datastore (local file) at a time.
Thread safe.
Usage:
###### Creating an instance ` import key_value_ds ds_instance = key_value_ds.get_instance() `
Note: If file_path is provided in the get_instance() call, it will obtain lock on that file using fcntl. If object is created for the same file path twice, BlockingIOError is thrown.
###### Creating an data ` data_key = 'test_key' data_value = {"value": 1} # must be a JSON time_to_live = 5*1000 # in milliseconds ds_instance.create(data_key, data_value, ttl=time_to_live) `
###### Retrieving data ` retrieve_key = 'test_key' ds_instance.get(retrieve_key) # returns {"value": 1} if retrieved within 5 seconds else ValueError `
###### Deleting data ` key_to_delete = 'test_key' ds_instance.delete(key_to_delete) # key-value is removed from the datastore `
###### Delete all data ` ds_instance.delete_all() `
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for key_value_ds-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 720a05ff0327a9c799198c3db2e392fd2e8c17c7aabfb38ac546e197678519a9 |
|
MD5 | 093ac761b1232c669979f25004f3ddcb |
|
BLAKE2b-256 | da41ca1b9e7a0c195a43e7f203fe2cba2b902e1c2d45cd7673dc0aa35bb98a3e |