Skip to main content

ShareDB

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

ShareDB in Action • Installation • License • Contributing • Acknowledgements • API

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
2.0.0
>>> 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
>>> myDB.pop(99, 'missing')               # Pop with a default for absent keys
'missing'
>>> myDB.update({'x': 100, 'y': 200})    # Update from a dict or iterable of pairs
ShareDB instantiated from ./test.ShareDB/
>>> myDB.setdefault('x', 999)             # Return existing value, or insert default
100
>>> 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
5
>>> 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.

Notes

  • None is not a valid key or value in ShareDB.
  • When using serial='msgpack', tuples are deserialized as lists (msgpack does not distinguish between tuple and list).

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-2026 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.

Metadata

Release files for ShareDB 2.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ShareDB 2.0.2
File Size Uploaded
sharedb-2.0.2.tar.gz 21.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ShareDB 2.0.2
File Interpreter ABI Platform
sharedb-2.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 37.3 kB

Release files / sharedb-2.0.2.tar.gz

Download URL sharedb-2.0.2.tar.gz
Size 21.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a9031c418e26491bca347557d832d69f06faf645cb0179d9d41664e5ebef986e
BLAKE2b-256 checksum
How to use checksums
bb29f356ce0a661134648d752d62f75e1aae871c4fcc096b74ca126972b865f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Release files / sharedb-2.0.2-py3-none-any.whl

Download URL sharedb-2.0.2-py3-none-any.whl
Size 15.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3fe04a37152c3a5df3aace5b7348000bf54626155b6c9a4b235e3d0bb4e2258d
BLAKE2b-256 checksum
How to use checksums
6fd95883276c22336fcd8b71ddcbd138a5d9d1bb5b54712179c0c64b8fbd8a58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Release history Release notifications | RSS feed

This release

2.0.2 This release

2 release files

1.1.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page