Skip to main content

A tiny log-structured key-value database written in pure Python

Project description

ViperDB

codecov

ViperDB is a lightweight embedded key-value store written in pure Python. It has been designed for being extremely simple while efficient.

Features

  • tiny: the main db file consists of just ~300 lines of code.
  • highly coverage: thanks to the small codebase, every single line of code is tested.
  • log-structured: ViperDB takes design concepts by log-structured databases such as Bitcask.
  • written in pure Python: no external dependency needed.

Database layout

ViperDB simply consists of two files: a key log file and a value log file. The first is used to maintain information about values (e.g. offset, size, etc...) which are actually stored in the value log. This layout allows to speed-up db initialization, which consists in loading the pointers to the entire key-space from the key-file to a dictionary. For simplicity, the key file is treated as a text file, with each line containing a json-encoded entry. The value file is viewed as a raw sequence of bytes. Before being written to the value file, each value is encoded according to the following scheme: builtin types (except for the bytes type) are json-encoded, while user-defined classes are pickled.

To keep logic simple, no automatic compaction is performed in the background: unused space must be reclaimed explicitly through the reclaim function.

API usage

from viperdb import ViperDB

db = ViperDB('./db')
# db can be used as a simple dictionary
db['hello'] = 'ViperDB!'
assert db['hello'] == 'ViperDB'

del db['hello']
assert 'hello' not in db

db.reclaim() # call this method periodically to free unused space.
db.close() # flush any pending write and close the database.

Contribute

ViperDB is a very recent project and, as such, it comes with no warranty. If you find any bug, or have some suggestion, feel free to contribute by opening a new issue or making a pull request.

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

viperdb-1.0.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

viperdb-1.0.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file viperdb-1.0.0.tar.gz.

File metadata

  • Download URL: viperdb-1.0.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.22.0 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/18.0.1 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.10

File hashes

Hashes for viperdb-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e0d54080e3f43565cd8a8cc3016b09203b983f2bc13a70badcbe236eb660e7be
MD5 e6932fce55559c29695ec77a7e17036f
BLAKE2b-256 10d934aa0dc6c2d2288506872039c1e3f67568463bffcf9ed2e25ac4d24b6159

See more details on using hashes here.

File details

Details for the file viperdb-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: viperdb-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.22.0 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/18.0.1 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.10

File hashes

Hashes for viperdb-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ee4a978802aba556c6127f168ed5092d300e43653751625ea39785b153b53196
MD5 a7e3440eefdbf08bca9ea1659399b568
BLAKE2b-256 16f63914f385bd87ff5530b6db3f5757a60b2d749b0a338211eb6d843e1b2d35

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