🗿Stones
Base library for persistent key-value stores, 100% compatible with Python dict.
The idea behind this project is to have a common interface for a multitude of persistent key-value stores, easy to use and extend, with some extra built-in features as bonus. Inspired from Datastore and MemDown.
It plays nice with Object Querying libraries like: JMESPath, or JSONPath RW, or ObjectPath.
Features and Limitations
- the same API that you already know from Python dict
- thread safe updates
- excellent test coverage (>90%)
- 1st limitation: the keys can only be bytes. They are converted from str to bytes for compatibility.
- 2nd limitation: the values are actually also bytes, but a serializer (default is Pickle) converts the data structure into bytes
- there are several serializers available: Pickle, JSON and optional: cbor2, msgpack. You can easily add your own serializer, please check the documentation below.
- 3rd limitation: after the data was serialized, you have to continue using the same serializer. If for some reason, you want to switch the serializer, you can create a new Store with your new serializer and copy all the data from the old Store.
- the Memory Store and LMDB are available by default. Other key-value Stores used to be implemented (DBM, LevelDB, Redis), but are not included anymore.
Install
This project uses Python 3.10+, or pip.
$ pip install stones
Usage
from stones import stone, LmdbStore
# Create a new persistent dictionary, backed by LMDB
stor = stone('my-db', LmdbStore, serialize='pickle')
# You can use it just like a normal Python dict,
# with the limitation that keys are bytes,
# and the values must be serializable
stor[b's'] = b'whatever'
stor[b'li'] = [True, False, None, -1]
stor[b'tu'] = ('Yes', 'No', 3)
b's' in stor
# True
len(stor)
# 3
stor.keys()
# [b'li', b's', b'tu']
stor.values()
# [[True, False, None, -1], b'whatever', ('Yes', 'No', 3)]
# The data is decoded in place
-1 in stor[b'li']
# True
3 in stor[b'tu']
# True
del stor[b'li']
stor.get(b'li', False)
# False
# The data is persisted
del stor
# Re-create the store, using the same encoder
stor = stone('my-db', LmdbStore, serialize='pickle')
len(stor)
# 2
stor.keys()
# [b's', b'tu']
More or less similar projects
Python:
- TinyDB - awesome lightweight document oriented database
- RocksDict - Key-value storage supporting any Python object
- uCache - Lightweight caching library for Python
- RaRe-Technologies/sqlitedict - Persistent dict backed by sqlite3 and pickle, multithread-safe
- Lukedeo/Cupboard - store things in a variety of NoSQL KV stores
- ShuhaoWu/Kvkit - unmaintained since 2014
- Datastore - unmaintained since 2014
- Persistent dict ActiveState recipe - from 2009
Node.js:
- lowDB - simple to use local JSON database. Powered by plain JS.
- Keyv - Key-value storage across multiple backends via storage adapters. Supports TTL based expiry, making it suitable as a cache or a persistent key-value store.
- MemDown - abstract LevelDown store for Node.js and browsers
- AppStorage - LocalStorage for Node.js, auto syncing objects with JSON files
- NeDB - embedded database for Node.js, nw.js, Electron and browsers
- FortuneJS - database abstraction layer with a common interface for databases
- PouchDB - pocket-sized database
- ToiletDB - flushes an object to a JSON file
- whatDB - in-memory JavaScript database for Small Web applications that persists to JSON files
Other:
- CubDB - Embedded key-value database written in the Elixir language. It runs locally, it is schema-less, and backed by a single file.
License
MIT © Cristi Constantin.
Metadata
Release files for stones 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| stones-0.3.0.tar.gz | 13.5 kB | Without provenance | Details for stones-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| stones-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for stones-0.3.0-py3-none-any.whl |
Total release size: 24.3 kB
Release files / stones-0.3.0.tar.gz
| Download URL | stones-0.3.0.tar.gz |
|---|---|
| Size | 13.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b6ac7dcac83ae32e3e6d6a9c8a12762a532d9ad9e04a017e783a73e5e32bf6a6
|
|
BLAKE2b-256 checksum How to use checksums |
350ea524f432da12b210d6d8817d3690fb0d9ab39f439943d5ea7289d9b445d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.14
|
Release files / stones-0.3.0-py3-none-any.whl
| Download URL | stones-0.3.0-py3-none-any.whl |
|---|---|
| Size | 10.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dcd64ca8a13c82bb623002d98a79c8df2b0937b1285674ad692692979bf6c527
|
|
BLAKE2b-256 checksum How to use checksums |
da2248207692633cf31b5d248aa11e746d092d64eacdccfc074a30ae4546ed9b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.14
|
Security for stones 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.