New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

lmdbm

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lmdbm

Python DBM style wrapper around LMDB (Lightning Memory-Mapped Database)

  • 0.0.6
  • PyPI
  • Socket score

Maintainers
1

lmdbm

This is a Python DBM interface style wrapper around LMDB (Lightning Memory-Mapped Database). It uses the existing lower level Python bindings py-lmdb. This is especially useful on Windows, where otherwise dbm.dumb is the default dbm database.

Install

  • pip install lmdbm

Example

from lmdbm import Lmdb
with Lmdb.open("test.db", "c") as db:
  db[b"key"] = b"value"
  db.update({b"key1": b"value1", b"key2": b"value2"})  # batch insert, uses a single transaction

Use inheritance to store Python objects using json serialization

import json
from lmdbm import Lmdb

class JsonLmdb(Lmdb):
  def _pre_key(self, value):
    return value.encode("utf-8")
  def _post_key(self, value):
    return value.decode("utf-8")
  def _pre_value(self, value):
    return json.dumps(value).encode("utf-8")
  def _post_value(self, value):
    return json.loads(value.decode("utf-8"))

with JsonLmdb.open("test.db", "c") as db:
  db["key"] = {"some": "object"}
  obj = db["key"]
  print(obj["some"])  # prints "object"

Warning

As of lmdb==1.2.1 the docs say that calling lmdb.Environment.set_mapsize from multiple processes "may cause catastrophic loss of data". If lmdbm is used in write mode from multiple processes, set autogrow=False and map_size to a large enough value: Lmdb.open(..., map_size=2**30, autogrow=False).

Benchmarks

See benchmark.py and requirements-bench.txt. Other storage engines which could be tested: wiredtiger, berkeleydb. Storage engines not benchmarked: - tinydb (because it doesn't have built-in str/bytes keys)

continuous writes in seconds (best of 3)

itemslmdbmlmdbm-batchpysossqlitedictsqlitedict-batchdbm.dumbsemidbmvedisvedis-batchunqliteunqlite-batch
100.0000.0150.0000.0310.0000.0160.0000.0000.0000.0000.000
1000.0940.0000.0000.2650.0160.1880.0000.0000.0000.0000.000
10001.6840.0160.0153.8850.1242.3870.0160.0150.0150.0160.000
1000016.8950.0930.26545.3341.32625.3500.1560.0930.0940.0940.093
100000227.1061.0302.698461.63812.964238.4001.6231.3881.4671.4661.357
10000003482.52013.10427.8155851.239133.3962432.94516.41115.69315.70914.50814.103

random reads in seconds (best of 3)

itemslmdbmlmdbm-batchpysossqlitedictsqlitedict-batchdbm.dumbsemidbmvedisvedis-batchunqliteunqlite-batch
100.0000.0000.0000.0000.0000.0000.000
1000.0000.0000.0310.0000.0000.0000.000
10000.0160.0150.2500.1090.0160.0150.000
100000.1090.1562.5581.1230.1710.1090.109
1000001.0142.13727.76911.4192.0901.1701.170
100000010.39024.258447.613870.58022.838214.486211.319

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc