Skip to main content

A lightweight JSON document database with field-level operation queuing and concurrency support

Project description

StarDDB (Star Document-database)

"Shoot for the moon. Even if you miss, you'll land among the stars." - Norman Vincent Peale

StarDDB is a simple to use, lightweight (single file implementation) DB for efficient JSON-like storage management.

Features

  • Concurrency support via field-level operation queuing
  • Easy-to-use API
  • Automatic background persistence
  • Nested document support
  • Thread-safe (Python) / Event-loop safe (Node.js)

Installation

pip install starddb

Quick Start

from stardb import StarDDBField, StarDDB

# Create a field and queue operations
field = StarDDBField(0)
field.update("set", 1)
field.update("mult", 5)
field.update("div", 0.5)
field.flush()
print(field.value)  # 10.0

# Use with a database file
db = StarDDB("data.json", save_time=5)
hook = db.db()
hook["health"].update("sub", 30)
hook["mana"].update("mult", 2)
db.close()

API

StarDDBField(value, max_queue_size=10000)

  • value — Initial value (any JSON-serializable type)
  • max_queue_size — Maximum queued operations (default: 10000)

Methods:

  • update(method, value) — Queue an operation. Methods: set, add, sub, mult, div, push
  • flush() — Block until all queued operations are processed

StarDDB(database, save_time, database_hook=None, safe_root=None)

  • database — Path to the JSON database file
  • save_time — Seconds between automatic saves
  • database_hook — Optional pre-loaded dict (skips file read)
  • safe_root — Optional root directory to restrict path traversal

Methods:

  • db() — Get the database hook (dict of StarDDBField instances)
  • flush() — Block until all field operations are processed
  • close() — Flush, save, and stop the background save thread
  • add_field(key_path, value) — Add a new field to a nested dict at runtime. key_path is a dot-separated string ("players.new_guy") or list of keys. Dict values are automatically crawled into StarDDBField instances. Raises KeyError if the path doesn't exist or the key already exists.

push operation:

# Append a value to a list field
hook["scores"].update("push", 30)

add_field examples:

# Add a primitive or list field
db.add_field("players.new_guy", 0)
db.add_field("players.new_guy.inventory", [])

# Add a nested dict (crawled automatically)
db.add_field("players.new_guy", {"coins": 0, "level": 1})
hook["players"]["new_guy"]["coins"].update("add", 5)

# Use a list of keys to avoid dot ambiguity
db.add_field(["some.weird.key", "nested"], 42)

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

starddb-1.0.1.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

starddb-1.0.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file starddb-1.0.1.tar.gz.

File metadata

  • Download URL: starddb-1.0.1.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for starddb-1.0.1.tar.gz
Algorithm Hash digest
SHA256 8a30c5c36905328f4a3c488333dbfc2eeae79a6af3ca26460706cf49a9db0cbe
MD5 77fa3e6619d6c95d097ca4dde61ba462
BLAKE2b-256 9a302503af5891732fc43d184eca3c15df1cac0d46389f7c10d7101c414a1a23

See more details on using hashes here.

File details

Details for the file starddb-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: starddb-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for starddb-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 33d23b45d96d6a53943c201ffe4001af21d90335657aa8713864299932002317
MD5 2cfa5f1f536912a2498805b2f857ee65
BLAKE2b-256 b73afb5ef170d6abec254e9ed2c51ae4b937e72c2e0acfbc667a80fabdea1c74

See more details on using hashes here.

Supported by

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