Simple File-based KV-Store
Project description
# kvfile
[](https://travis-ci.org/akariv/kvfile)
[](https://coveralls.io/r/akariv/kvfile?branch=master)
A simple Key-Value store that's file based - so can accommodate large data sets with a small memory footprint.
Internally will use the faster `leveldb` as a storage backend or `sqlite3` as fallback if `leveldb` is not available.
## The Basics
The API should feel familiar to anyone working with Python.
It exposes `get`, `keys` and `items` for reading from the DB, and `set` for setting a value in the DB.
### Initializing
```python
import datetime
import decimal
from kvfile import KVFile
kv = KVFile()
```
### Setting values
```python
kv.set('s', 'value')
kv.set('i', 123)
kv.set('d', datetime.datetime.fromtimestamp(12325))
kv.set('n', decimal.Decimal('1234.56'))
kv.set('ss', set(range(10)))
kv.set('o', dict(d=decimal.Decimal('1234.58'),
n=datetime.datetime.fromtimestamp(12325)))
```
### Getting values
```python
assert kv.get('s') == 'value'
assert kv.get('i') == 123
assert kv.get('d') == datetime.datetime.fromtimestamp(12325)
assert kv.get('n') == decimal.Decimal('1234.56')
assert kv.get('ss') == set(range(10))
assert kv.get('o') == dict(d=decimal.Decimal('1234.58'),
n=datetime.datetime.fromtimestamp(12325))
```
### Listing values
`keys()` and `items()` methods return a generator yielding the values for efficient stream processing.
The returned data is sorted ascending (by default) based on the keys
```python
assert list(kv.keys()) == ['d', 'i', 'n', 'o', 's', 'ss']
assert list(kv.items()) == [
('d', datetime.datetime.fromtimestamp(12325)),
('i', 123),
('n', decimal.Decimal('1234.56')),
('o', {'d': decimal.Decimal('1234.58'),
'n': datetime.datetime.fromtimestamp(12325)}),
('s', 'value'),
('ss', {0, 1, 2, 3, 4, 5, 6, 7, 8, 9})
]
```
Set the `reverse` argument to True for the `keys()` and `items()` methods to sort in descending order.
## Installing leveldb
On Debian based Linux:
```bash
$ apt-get install libleveldb-dev libleveldb1
```
On Alpine based Linux:
```bash
$ apk --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ --update add leveldb leveldb-dev
```
On OS X:
```bash
$ brew install leveldb
```
[](https://travis-ci.org/akariv/kvfile)
[](https://coveralls.io/r/akariv/kvfile?branch=master)
A simple Key-Value store that's file based - so can accommodate large data sets with a small memory footprint.
Internally will use the faster `leveldb` as a storage backend or `sqlite3` as fallback if `leveldb` is not available.
## The Basics
The API should feel familiar to anyone working with Python.
It exposes `get`, `keys` and `items` for reading from the DB, and `set` for setting a value in the DB.
### Initializing
```python
import datetime
import decimal
from kvfile import KVFile
kv = KVFile()
```
### Setting values
```python
kv.set('s', 'value')
kv.set('i', 123)
kv.set('d', datetime.datetime.fromtimestamp(12325))
kv.set('n', decimal.Decimal('1234.56'))
kv.set('ss', set(range(10)))
kv.set('o', dict(d=decimal.Decimal('1234.58'),
n=datetime.datetime.fromtimestamp(12325)))
```
### Getting values
```python
assert kv.get('s') == 'value'
assert kv.get('i') == 123
assert kv.get('d') == datetime.datetime.fromtimestamp(12325)
assert kv.get('n') == decimal.Decimal('1234.56')
assert kv.get('ss') == set(range(10))
assert kv.get('o') == dict(d=decimal.Decimal('1234.58'),
n=datetime.datetime.fromtimestamp(12325))
```
### Listing values
`keys()` and `items()` methods return a generator yielding the values for efficient stream processing.
The returned data is sorted ascending (by default) based on the keys
```python
assert list(kv.keys()) == ['d', 'i', 'n', 'o', 's', 'ss']
assert list(kv.items()) == [
('d', datetime.datetime.fromtimestamp(12325)),
('i', 123),
('n', decimal.Decimal('1234.56')),
('o', {'d': decimal.Decimal('1234.58'),
'n': datetime.datetime.fromtimestamp(12325)}),
('s', 'value'),
('ss', {0, 1, 2, 3, 4, 5, 6, 7, 8, 9})
]
```
Set the `reverse` argument to True for the `keys()` and `items()` methods to sort in descending order.
## Installing leveldb
On Debian based Linux:
```bash
$ apt-get install libleveldb-dev libleveldb1
```
On Alpine based Linux:
```bash
$ apk --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ --update add leveldb leveldb-dev
```
On OS X:
```bash
$ brew install leveldb
```
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
kvfile-0.0.2.tar.gz
(6.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kvfile-0.0.2.tar.gz.
File metadata
- Download URL: kvfile-0.0.2.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
913944f543c38a0f678e76dbfda37d00f1fac03af5f04d47876edadaeb8e4a52
|
|
| MD5 |
9b90b36606eec307989ece2aea1bbcd2
|
|
| BLAKE2b-256 |
93179ee55c44744fbc18d4d13df0bd9aa42467a50609f9c6575b6c3aa8b6e15a
|
File details
Details for the file kvfile-0.0.2-py2.py3-none-any.whl.
File metadata
- Download URL: kvfile-0.0.2-py2.py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
264c41a16c06808bb24f730264708fe5a7e7aa31fb3129a374f63e1ee0419acc
|
|
| MD5 |
bf37cdb1ff59a82f4936a8c5424e6ff0
|
|
| BLAKE2b-256 |
b87448a9268e0328f51438f3957e950bddd2ff4bac929bdb414a9a84f84e1b25
|