Skip to main content

Library for Persistent key-value containers, compatible with Python dict.

Project description

🗿Stones

Build Status Codecov Python 3.6

Base library for persistent key-value stores, 100% compatible with Python dict.

Stones image

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 and 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.6+ and pip. A virtual environment is strongly encouraged.

$ pip install git+https://github.com/croqaz/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:

Node.js:

  • MemDown - abstract LevelDown store for Node.js and browsers
  • 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

License

MIT © Cristi Constantin.

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

stones-0.1.3.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

stones-0.1.3-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file stones-0.1.3.tar.gz.

File metadata

  • Download URL: stones-0.1.3.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.9

File hashes

Hashes for stones-0.1.3.tar.gz
Algorithm Hash digest
SHA256 feb60b95a682032fcc85ad70a6db21fd063ada663c1f6f6f567958213875db53
MD5 5bfc0c0c16107af90b1ccac526176f05
BLAKE2b-256 c2104a3da27955ef8bb6af8c39503edf13ac2209b8a00f4211374ad878c03462

See more details on using hashes here.

File details

Details for the file stones-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: stones-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.9

File hashes

Hashes for stones-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5edf6893d18ce907bbb245d93877a9d70dc0b163e8ec1e3f10fc85a6d9cab4a7
MD5 e4b9dc6917f86478ea1f86d4d311d916
BLAKE2b-256 edaf4aaa9b08ba1bf00df1478b9f276e7eb5000502fdc9e4354c39e717f46aff

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page