Databases 5 min read

Master LMDB with lmcmd: A Powerful Command-Line Client

lmcmd is a Python‑based command‑line client for the Lightning Memory‑Mapped Database (LMDB) that offers efficient key‑value operations, import/export, searching, and database management, with easy installation via pip and a Redis‑style interface for rapid debugging and data handling.

Dunmao Tech Hub
Dunmao Tech Hub
Dunmao Tech Hub
Master LMDB with lmcmd: A Powerful Command-Line Client

What is LMDB?

LMDB (Lightning Memory‑Mapped Database) is a high‑performance key‑value store that uses memory‑mapped files. It provides fast read/write access, strong multi‑version concurrency control (MVCC), and full ACID guarantees while storing all data in a single file.

Efficiency : Direct memory‑mapped file access eliminates extra copying.

Strong transactionality : MVCC ensures consistent reads during concurrent writes.

Lightweight : Single‑file storage makes it suitable for embedded systems and large‑scale deployments.

ACID guarantees : Atomicity, consistency, isolation, and durability are enforced.

Why lmcmd was created

LMDB stores data in a binary format, which makes manual inspection and debugging difficult. No dedicated command‑line management tool existed, so the author implemented lmcmd, a Python‑based interactive console inspired by redis-cli. It offers basic key‑value operations, import/export, and search capabilities for LMDB databases.

Installation

lmcmd is distributed on PyPI. Install it with one of the following commands:

pip install lmcmd
pip3 install lmcmd

Usage

Connecting to a database

Provide the path to the LMDB environment directory. If the directory does not exist, lmcmd creates a new environment.

lmcmd my_database
lmcmd /absolute/path/to/my_database

After a successful connection the interactive prompt appears.

Command reference

show

: Prints the name of the currently opened database. set <KEY> <VALUE>: Stores a key‑value pair. get <KEY>: Retrieves the value associated with <KEY>. del <KEY>: Removes the specified key. list: Lists all key‑value pairs in the environment. export: Writes the entire database to export.json in JSON format. import <ID> <FILE_PATH>: Loads key‑value pairs from a JSON file. search <VALUE>: Returns keys whose values contain the given substring.

Example session

>>> set name Alice
Ok
>>> get name
Alice
>>> list
{name: Alice}
>>> export
Data Exported to export.json
>>> import id data.json
Data Imported!
>>> show
Database: my_database
>>> del name
Ok
>>> list
(Empty)
>>> search Alice
{name: Alice}

Source code

GitHub repository: https://github.com/nodcats/lmcmd

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Pythoncommand-lineCLI toolLMDBkey-value databaselmcmd
Dunmao Tech Hub
Written by

Dunmao Tech Hub

Sharing selected technical articles synced from CSDN. Follow us on CSDN: Dunmao.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.