Skip to main content

LMDB-backed dict-like store

Project description

lmdb-simple

Project Overview

This document outlines the implementation and packaging plan for the lmdb-simple Python package, targeting Python 3.9+ and designed to be OS-agnostic. The package will provide a dict-like interface on top of an LMDB disk store, with context-manager support and fork-safe multiprocessing readers (picklable LmdbDict instances).

1. Project Layout

lmdb-simple/
├── LICENSE
├── MANIFEST.in
├── README.md
├── setup.py
└── lmdb_simple/
    ├── __init__.py
    └── core.py

2. Dependencies

lmdb>=1.0.0 • Python standard library (typing, pathlib, multiprocessing)

3. Core API (lmdb_simple/core.py)

  • class LmdbDict[K, V] (implements MutableMapping[K, V] and ContextManager) • __init__(self, path: Union[str, Path], writer: bool = False, map_size_gb: float = 1.0, **env_kwargs) • Mapping methods: __getitem__, __setitem__, __delitem__, __len__, __iter__ • Views: keys(), values(), items() • Sync/flush: flush() • Close: close() • Context‐manager: __enter__(), __exit__() • Optional transaction(write: bool) context manager for batch writes • Full type hints and docstrings on public methods

5. Packaging (setup.py)

  • name="lmdb-simple", version="0.1.0"
  • python_requires=">=3.9"
  • install_requires=["lmdb>=1.6.2"]
  • Read long description from README.md
  • Include license, classifiers, and find_packages()
  • MANIFEST.in to include README.md and LICENSE

6. Documentation & Examples

  • Flesh out README.md (this file) with:
    • Quickstart examples for reader/writer, context managers, and multiprocessing
    • API reference links to docstrings

7. OS‐Agnostic Considerations

  • Use pathlib for filesystem paths
  • Rely on LMDB’s cross‐platform locking

8. Publishing Workflow

  1. Build: python setup.py sdist bdist_wheel
  2. Upload: twine upload dist/*
  3. Tag & release on GitHub

With this plan in place, we can now scaffold and implement the package per these outlines.

Quickstart

Install from PyPI:

pip install lmdb-simple

Basic usage:

from lmdb_simple.core import LmdbDict

# Writer mode: open (and create if needed) for writing
with LmdbDict("path/to/db", writer=True, map_size_gb=1.0) as db:
    db["foo"] = "bar"                # store strings
    db[b"bytes"] = b"raw bytes"      # store raw bytes
    db[1] = {"nested": [1, 2, 3]}     # store arbitrary Python objects

# Reader mode: open for read-only
with LmdbDict("path/to/db") as db:
    print(db["foo"])                 # "bar"
    print(db[b"bytes"])              # b"raw bytes"
    print(db[1])                       # {"nested": [1, 2, 3]}
    for key, value in db.items():
        print(key, value)

Multiprocessing

from lmdb_simple.core import LmdbDict
from multiprocessing import Pool

TEST_DB_PATH = "path/to/db"

# Create the reader at module level so that each worker process
# will reuse the same LMDB environment when unpickled.
reader = LmdbDict(TEST_DB_PATH)

def reader_worker(key):
    return reader[key]

if __name__ == "__main__":
    keys = [...]

    with Pool(processes=4) as pool:
        for result in pool.imap_unordered(reader_worker, keys):
            print(result)

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

lmdb_simple-0.1.1.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

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

lmdb_simple-0.1.1-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file lmdb_simple-0.1.1.tar.gz.

File metadata

  • Download URL: lmdb_simple-0.1.1.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.0

File hashes

Hashes for lmdb_simple-0.1.1.tar.gz
Algorithm Hash digest
SHA256 94d3364c41cb164ef80d045704d893c8afad1e54ab516195ae2c3ff67c790847
MD5 19194bd750febc3f4216ad73b7a90b24
BLAKE2b-256 9565bbd998bd5865bf130cf792ce8b8ad5c37f1cd25f57410e703f46d37a07b1

See more details on using hashes here.

File details

Details for the file lmdb_simple-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: lmdb_simple-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.0

File hashes

Hashes for lmdb_simple-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dce9ba22a475b0fd688d013af3766115df52bfcc61e6c0ad91f3befae41f1bb7
MD5 95c42dc0bc26000f93b12ca98f336771
BLAKE2b-256 a58d447a63480e1a031f02749116f9d2613059ce89cd6d05a5f012be6b03c19b

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