Convenience of key value store
Project description
kona
It is a project created to manage various key-value stores.
Currently, only RocksDB is supported, but we will continue to increase the number of key-value stores that can be supported.
Prerequisite
- python 3.7.5
Supported Key-Value Store
- RocksDB
Installation
$ pip install kona
Example
from kona.key_value_store import KeyValueStore
db = KeyValueStore.new(
'file://./key_value_store_test_database',
store_type='rocksdb',
create_if_missing=True
)
db.put(b'foo', b'bar')
print(db.get(b'foo'))
db.close()
db.destroy_store()
# Result
# b'bar'
Batch
You can write to DataBase at a specific point in time using WriteBatch()
.
from kona.key_value_store import KeyValueStore
db = KeyValueStore.new(
'file://./key_value_store_test_database',
store_type='rocksdb',
create_if_missing=True
)
batch = db.WriteBatch()
batch.put(b'test_key_1', b'test_value_1')
batch.put(b'test_key_2', b'test_value_2')
batch.write()
print(db.get(b'test_key_1'))
print(db.get(b'test_key_2'))
db.destroy_store()
# Result
# b'test_value_1'
# b'test_value_2'
CancelableBatch
You can cancel data written in batches using CancelableWriteBatch()
.
from kona.key_value_store import KeyValueStore
db = KeyValueStore.new(
'file://./key_value_store_test_database',
store_type='rocksdb',
create_if_missing=True
)
test_items = {
b'test_key_1': b'test_value_1',
b'test_key_2': b'test_value_2',
b'test_key_3': b'test_value_3',
b'test_key_4': b'test_value_4',
b'test_key_5': b'test_value_5',
}
for key, value in test_items.items():
db.put(key, value)
cancelable_batch = db.CancelableWriteBatch()
cancelable_batch.put(b'cancelable_key_1', b'cancelable_value_1')
cancelable_batch.put(b'test_key_2', b'edited_test_value_2')
cancelable_batch.put(b'cancelable_key_2', b'cancelable_value_2')
cancelable_batch.put(b'test_key_4', b'edited_test_value_4')
cancelable_batch.write()
for key, value in db.Iterator():
print(f'Before Cancel: key={key}, value={value}')
cancelable_batch.cancel()
for key, value in db.Iterator():
print(f'After Cancel: key={key}, value={value}')
db.destroy_store()
# Before Cancel
# Before Cancel: key=b'cancelable_key_1', value=b'cancelable_value_1'
# Before Cancel: key=b'cancelable_key_2', value=b'cancelable_value_2'
# Before Cancel: key=b'test_key_1', value=b'test_value_1'
# Before Cancel: key=b'test_key_2', value=b'edited_test_value_2'
# Before Cancel: key=b'test_key_3', value=b'test_value_3'
# Before Cancel: key=b'test_key_4', value=b'edited_test_value_4'
# Before Cancel: key=b'test_key_5', value=b'test_value_5'
# After Cancel
# After Cancel: key=b'test_key_1', value=b'test_value_1'
# After Cancel: key=b'test_key_2', value=b'test_value_2'
# After Cancel: key=b'test_key_3', value=b'test_value_3'
# After Cancel: key=b'test_key_4', value=b'test_value_4'
# After Cancel: key=b'test_key_5', value=b'test_value_5'
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
kona-0.1.2.tar.gz
(11.5 kB
view details)
Built Distribution
kona-0.1.2-py3-none-any.whl
(13.3 kB
view details)
File details
Details for the file kona-0.1.2.tar.gz
.
File metadata
- Download URL: kona-0.1.2.tar.gz
- Upload date:
- Size: 11.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbe153db5c4de6a8a505179c92884a020a249543192b2c1f707a2450d2394bfa |
|
MD5 | 5439ab6fcf417398078de16705c8caaa |
|
BLAKE2b-256 | fb2e2697bb5c79713ec178cabf939b05289307d33a7a1511ac5e0c00a56849ef |
File details
Details for the file kona-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: kona-0.1.2-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b47b7410d3420fa9628f17fa1b0cfef87cb30ea688c00114fb43ad07ba65ba3d |
|
MD5 | 89a84de0fa0b4e713b4e37d9b886a042 |
|
BLAKE2b-256 | 5573033c8f60220e915095cc380e8a15271da2aea0aa3ece3f05f9ec631511d6 |