Skip to main content

Droplet Poster

Droplet

Small. Simple. Flexible.

Droplet is a lightweight, embedded key-value database for Python that supports both in-memory and persistent storage.

Designed to keep data storage simple, Droplet provides a straightforward API for storing, retrieving, and managing Python values without requiring SQL, a database server, or complicated configuration.

By default, Droplet operates entirely in memory. When persistence is needed, switch to persistent mode to store data locally in a single binary file.

Features

  • 🧠 In-memory storage by default: Store and retrieve values without disk I/O.
  • 💾 Optional persistence: Keep data between sessions using a single binary database file.
  • ⚡ Simple API: Straightforward methods for reading, writing, updating, and deleting values.
  • 🐍 Python type support: Store strings, integers, floats, booleans, bytes, UUIDs, dictionaries, lists, and tuples.
  • 🗂️ Namespaces: Organize related keys into logical groups.
  • 📦 Batch operations: Read, write, and delete multiple values efficiently.
  • ⏱️ Time-to-live (TTL): Automatically invalidate values after a specified duration.
  • 🏗️ Dataclass support: Store dataclass instances and reconstruct them when retrieving.
  • 🧹 Database compaction: Reclaim disk space in persistent databases.
  • 🔄 JSON import / export: Export stored data to JSON or import JSON into a database.

Installation

Droplet is available on PyPI.

pip install droplet-db

Requires Python 3.10 or newer.

Quick Start

Droplet uses in-memory storage by default.

from droplet import Droplet

db = Droplet()

db.set("name", "Stormy")
db.set("age", 25)

print(db.get("name"))  # Stormy
print(db.get("age"))   # 25

No files are created in memory mode.

Persistent storage

To retain your data between sessions, enable persistent mode.

from droplet import Droplet

db = Droplet(mode="persistent")
db.open()

db.set("name", "Stormy")
db.set("age", 25)

db.close()

The database is stored in database.droplet in the current working directory.

When you reopen it, the data is restored:

db = Droplet(mode="persistent")
db.open()

print(db.get("name"))  # Stormy

db.close()

Storage Modes

Droplet supports two storage modes, both using the same API.

Feature Memory Persistent
Default mode Yes No
Disk storage No Yes
Survives reopening No Yes
Key-value operations Yes Yes
Namespaces Yes Yes
TTL Yes Yes
Batch operations Yes Yes
Dataclass support Yes Yes
Compaction Not needed Supported

Memory mode

Memory mode is ideal for temporary application data, caching, and other use cases where persistence isn't required.

db = Droplet(mode="memory")

db.set("cache:user:1", {"name": "Stormy"})
db.set("session", "abc123", ttl=300)

Persistent mode

Persistent mode uses a binary file to preserve data between application sessions.

# Default persistent file location
db = Droplet(mode="persistent")

# Store the database in a custom directory
db = Droplet("./storage", mode="persistent")

# Use a custom database filename
db = Droplet("./storage/application.droplet", mode="persistent")

Persistent storage uses an append-only binary record format. Database compaction can reclaim space occupied by obsolete records.

Usage

Storing and retrieving values

db.set("username", "Stormy")
db.set("preferences", {
    "theme": "dark",
    "notifications": True
})

print(db.get("username"))  # Stormy
print(db.get("preferences")["theme"])  # dark

Namespaces

db.set("1", "Stormy", namespace="users")
db.set("1", "Laptop", namespace="products")

print(db.get("1", namespace="users"))     # Stormy
print(db.get("1", namespace="products"))  # Laptop

Batch operations

db.set_batch({
    "name": "Stormy",
    "age": 25,
    "active": True
})

values = db.get_batch(["name", "age"])
print(values)

db.delete_batch(["name", "age"])

Expiring values

db.set("session", "abc123", ttl=60)

The value expires after 60 seconds. Retrieving an expired value raises KeyError.

Dataclass support

from dataclasses import dataclass

@dataclass
class User:
    name: str
    age: int

db.set_as("user", User("Stormy", 25))

user = db.get_as("user", User)
print(user)  # User(name='Stormy', age=25)

Counters

db.set("visits", 0)

db.increment("visits", 5)
db.decrement("visits", 2)

print(db.get("visits"))  # 3

Context managers

from droplet import Droplet

with Droplet(path='app.droplet', mode='persistent') as db:
    db.set('name', 'Stormy')
    print(db.get('name')) # Stormy
    print(db.is_open) # True

print(db.is_open) # False

Inspecting data

print(db.keys())
print(db.values())
print(dict(db.view()))
print(db.count())

How Droplet Works

Droplet maintains a Python dictionary for fast key-value access.

In memory mode, values are stored entirely in memory without creating database files.

In persistent mode, Droplet additionally writes binary records to disk. When the database is reopened, these records are used to reconstruct its state.

Both modes share the same public API, allowing developers to choose the storage behavior that best suits their application.

Droplet is designed for lightweight, single-threaded use.

Roadmap

Planned improvements include:

  • Transaction support.
  • Additional developer utilities.
  • Reliability and performance improvements.

Project Status

Droplet is an early-stage open-source project under active development.

The API and binary file format may change before version 1.0.

Contributing

Bug reports, feature suggestions, and contributions are welcome.

Visit the GitHub repository to open an issue or contribute.

License

Droplet is released under the MIT License.

See LICENSE for details.


Small. Simple. Flexible.

GitHub · PyPI

Metadata

Release files for droplet-db 0.3.4

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

Source distribution (sdist)

Source distribution for droplet-db 0.3.4
File Size Uploaded Provenance Actions
droplet_db-0.3.4.tar.gz 25.2 kB Without provenance Details for droplet_db-0.3.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for droplet-db 0.3.4
File Interpreter ABI Platform Actions
droplet_db-0.3.4-py3-none-any.whl Python 3 none any Details for droplet_db-0.3.4-py3-none-any.whl

Total release size: 44.4 kB

Release files / droplet_db-0.3.4.tar.gz

Download URL droplet_db-0.3.4.tar.gz
Size 25.2 kB
Tags Source
SHA-256 checksum
How to use checksums
5c65846b9b45bfa9b8ddb4fb4ca357fe0d5d34428228749ee7da6e1c509ca44a
BLAKE2b-256 checksum
How to use checksums
bdcd2a63561e5f23afb25f30a8ac448d0b51c5bc2706895661b22dc54d9d8c9a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / droplet_db-0.3.4-py3-none-any.whl

Download URL droplet_db-0.3.4-py3-none-any.whl
Size 19.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
86e5bb4b73baa77b0bffe266aafa6d42425fbe082f176fb6c5c2f969ab648fcb
BLAKE2b-256 checksum
How to use checksums
31c8e90b52c663b48c2cfb3cc6011f8ddaf6247008cf4a5ff2923b21a678825e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Security for droplet-db 0.3.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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