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, **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=10_000_000) 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.0.tar.gz (8.4 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.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lmdb_simple-0.1.0.tar.gz
  • Upload date:
  • Size: 8.4 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.0.tar.gz
Algorithm Hash digest
SHA256 49ccad4b0fd64e618f65617721d170bedd89b8b9399d8ca705c94aacda1ca7f9
MD5 f55764c33e0a54235e5a37b77656d2b6
BLAKE2b-256 34542263c2766aae1a14692e3967ce28ef2b61162bdcc402a9fd4669d88ab205

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lmdb_simple-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f011557300a7f551aa17dddfabd90f488075ff84ac9af8acd1cb129569e6d120
MD5 50a464a84f112b19c85cd5b57f7770db
BLAKE2b-256 f6ce44f425c63be7d7861af309a6edef3f6ca129771ae5b33c700ef63524f48f

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