Super simple keyvalue store for python, backed by sqlite.
Project description
KeyValueSqlite
Super easy drop in replacement for python dictionary, which stores it's key-value to an sqlite database.
API
from keyvalue_sqlite import KeyValueSqlite
DB_PATH = '/path/to/db.sqlite'
db = KeyValueSqlite(DB_PATH, 'table-name')
# Now use standard dictionary operators
db.set_default('0', '1')
actual_value = db.get('0')
assert '1' == actual_value
db.set_default('0', '2')
assert '1' == db.get('0')
New in 1.0.4: atomic integers.
from keyvalue_sqlite import KeyValueSqlite
DB_PATH = '/path/to/db.sqlite'
db = KeyValueSqlite(DB_PATH, 'table-name')
# Now use standard dictionary operators
db.set_default('atomic_var', '1')
db.atomic_add('atomic_var', '2')
val = db.get('atomic_var')
assert '3' == actual_value
This datastructure is not going to win any performance races, but it is super simple to use with just a few lines of code. This is a great option for one of those small web apps which doesn't have enough load to justify mysql or postgres, or a file that will be used by multiple processes, or to store a file that can't be corrupted during a power failure.
When fetching large amounts of data try to use get_many() or dict_range().
Links
Versions
- 1.0.7: Don't use "default" as the default table name, sqlite doesn't like it.
- 1.0.6: Allow setting default timeout in the constructor
- 1.0.5: Makes table name optional.
- 1.0.4: Adds atomic_add to allow atomic int operations.
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
File details
Details for the file keyvalue_sqlite-1.0.7.tar.gz
.
File metadata
- Download URL: keyvalue_sqlite-1.0.7.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3dafb036b43a441039f1a2da00810eedae75c23e7b5f8617b775fd9ef3bdf895 |
|
MD5 | b568040982ab37db3b000e75e1996d90 |
|
BLAKE2b-256 | acb1d4311760127357373c8a361f43cbdfca18e812ea305d9b09e16fd2542d3a |
File details
Details for the file keyvalue_sqlite-1.0.7-py2.py3-none-any.whl
.
File metadata
- Download URL: keyvalue_sqlite-1.0.7-py2.py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf462e805bbd6a03c6765d3f2cce71b4fba5d9a28c6cdee55460bf1f7e492c37 |
|
MD5 | dc0f83cdae2f2250aa326504ac0f4e33 |
|
BLAKE2b-256 | 93f77a75d45245f1deada19acef970b630332f1aa24d5a64fae5281ee5203315 |