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.3.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.3-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lmdb_simple-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 d8f9afefa5649706268103a65ba3eea820f56908482c29ff90e5f81c6d300959
MD5 4ff3b74027adf6a60993167aa61c7f02
BLAKE2b-256 3c6d18deb550e11d1bf91a2acee802ed3c8946bc139a7dbcc260e17861bae2da

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lmdb_simple-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 9.4 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4d1681c10459dd9ed240dbabffc8e60438332c9ebc05d93f5ae5926f84be4c6a
MD5 8de97844308e73269677e0f567249859
BLAKE2b-256 538eb1fd67da542ec5c7d9e576fddaf3d3b5fdac630e7d3c7ddc9b5b9b7ce565

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