Skip to main content

A simple, thread-safe, zero external dependencies key-value store with asynchronous memory buffering capabilities and disk persistence.

Project description

NADB - Not A Database

A simple, thread-safe, zero external dependencies key-value store with asynchronous memory buffering capabilities and disk persistence.

:rotating_light: This project is educational and not intended for production use. :rotating_light:

Features

  • Thread-safe operations for setting, getting, and deleting key-value pairs.
  • In-memory buffering of key-value pairs with asynchronous flushing to disk.
  • Periodic flushing of the buffer to disk to ensure data integrity.
  • Manual flushing capability for immediate persistence.
  • Namespace and database separation for organized data storage.
  • Simple usage and minimal setup required.

Installation

pip install nadb

Quickstart

Here's a basic example of how to use NADB:

from nadb import KeyValueStore, KeyValueSync

# Create a KeyValueStore instance

data_folder_path = './data'
db_name = 'db1'
buffer_size_mb = 1  # 1 MB
flush_interval_seconds = 60  # 1 minute
namespace = 'namespace1'

# Initialize the KeyValueSync for asynchronous flushing
kv_sync = KeyValueSync(flush_interval_seconds)

# Initialize the KeyValueStore
kv_store = KeyValueStore(data_folder_path, db_name, buffer_size_mb, namespace, kv_sync)

# Set some key-value pairs
kv_store.set('key1', 'value1')
kv_store.set('key2', 'value2')
kv_store.set('key3', 'value3')

# Get a value
value1 = kv_store.get('key1')  # Returns 'value1'

# Delete a key-value pair
kv_store.delete('key1')

# Manual flush (optional, as flushing occurs automatically based on buffer size and time interval)
kv_store.flush()

# Retrieve the status of all KeyValueStore instances
status = kv_sync.status()  # Returns a list of dictionaries with information about each KeyValueStore instance

# Stop accepting new KeyValueStore registrations, sync remaining ones, and exit
kv_sync.sync_exit()

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

nadb-0.0.7.tar.gz (3.9 kB view hashes)

Uploaded Source

Built Distribution

nadb-0.0.7-py3-none-any.whl (4.2 kB view hashes)

Uploaded Python 3

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