Skip to main content

An on-disk pythonic embedded key-value store for compressed data storage and distributed data analysis.

Project description

ShareDB

CI-badge codecov-badge version-badge python-badge os-badge license-badge

ShareDB in ActionInstallationLicenseContributingAcknowledgementsAPI

ShareDB is a lightweight, persistent key-value store with a dictionary-like interface built on top of LMDB. It is intended to replace a python dictionary when

  1. the key-value information needs to persist locally for later reuse,
  2. the data needs to be shared across multiple processes with minimal overhead, and
  3. the keys and values can be (de)serialized via msgpack or pickle.

A ShareDB instance may be opened simultaneously in children, for reading in parallel, as long as a single process writes to the instance. Parallel writes made across processes are not safe; they are not guaranteed to be written, and may corrupt instance. ShareDB is primarily developed and tested using Linux and is compatible with both Python 2.7 and Python 3.6 and above.

ShareDB in Action

>>> from ShareDB import ShareDB           # Easy import
>>> print(ShareDB.__version__)            # Check version
1.1.4
>>> myDB = ShareDB(path='./test.ShareDB') # Store ShareDB locally
>>> myDB['Name'] = ['Ayaan Hossain']      # Insert information
>>> myDB.get(key='Name')                  # Retrieve values
['Ayaan Hossain']
>>> # Accelerated batch insertion/update via a single transaction
>>> len(myDB.multiset(kv_iter=zip(range(0, 10), range(10, 20))).sync())
11
>>> 7 in myDB                             # Membership queries work
True
>>> myDB['non-existent key']              # KeyError on invalid get as expected
Traceback (most recent call last):
...
KeyError: "key=non-existent key of <class 'str'> is absent"
>>> myDB.pop(7)                           # Pop a key just like a dictionary
17
>>> list(myDB.multipopitem(num_items=5))  # Or, pop as many items as you need
[(0, 10), (1, 11), (2, 12), (3, 13), (4, 14)]
>>> myDB.remove(5).remove(6).length()     # Chain removal of several keys
2
>>> myDB.clear().length()                 # Or, clear entire ShareDB
0
>>> myDB.drop()                           # Close/delete when you're done
True

ShareDB methods either return data/result up on appropriate query, or a self is returned to facilitate method chaining. Terminal methods .close() and .drop() return a boolean indicating success.

Please see the /examples/ directory for full examples of ShareDB usage. Please see the API.md file for API details.

Installation

One-shot installation/upgrade of ShareDB from PyPI.

$ pip install --upgrade ShareDB

Alternatively, clone ShareDB from GitHub,

$ git clone https://github.com/ayaanhossain/ShareDB

navigate into repo, and install via pip.

$ cd ShareDB
$ pip install .

You can test ShareDB with pytest inside the /tests/ directory.

$ cd tests
$ pytest

Uninstallation of ShareDB is easy with pip.

$ pip uninstall ShareDB

License

ShareDB (c) 2019-2024 Ayaan Hossain.

ShareDB is an open-source software under MIT License.

See LICENSE file for more details.

Contributing

Please discuss any issues/bugs you're facing, or any changes/features you have in mind by opening an issue, following the Contributor Covenant. See COC.md file for details. Please provide detailed information, and code snippets to facilitate debugging.

To contribute to ShareDB, please clone this repository, commit your code on a separate new branch, and submit a pull request. Please annotate and describe all new and modified code with detailed comments and new unit tests as applicable. Please ensure that modified builds pass existing unit tests before sending pull-requests. For versioning, we use SemVer.

Acknowledgements

ShareDB is maintained by:

ShareDB was originally written to meet data analysis needs in Prof. Howard Salis' Lab at Penn State University.

API

ShareDB API details can be found in the API.md file.

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

sharedb-1.1.4.tar.gz (19.2 kB view details)

Uploaded Source

Built Distribution

ShareDB-1.1.4-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file sharedb-1.1.4.tar.gz.

File metadata

  • Download URL: sharedb-1.1.4.tar.gz
  • Upload date:
  • Size: 19.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for sharedb-1.1.4.tar.gz
Algorithm Hash digest
SHA256 e300dfdf1dafa9802b675d9216171cafdc94682fe7b9b2be85199792c84709c7
MD5 5b440b5b661b9a241affeb0e881c601a
BLAKE2b-256 31979d216646af712196761f5cdfc34220885809478a8f91b199aad9c549c69b

See more details on using hashes here.

File details

Details for the file ShareDB-1.1.4-py3-none-any.whl.

File metadata

  • Download URL: ShareDB-1.1.4-py3-none-any.whl
  • Upload date:
  • Size: 13.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for ShareDB-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1ffdaa0c9cf1aa43590a9f91ad0fb1deb1ba86293a95bbe3b5c14ad603f6e0d7
MD5 eabe6a2b1301d18fc3d6d362f69dddf7
BLAKE2b-256 e7e97321af0d25afab09fcc82f7908fdf8f0df104b3882d9a699b7eb477e9f70

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