{"id":6391,"library":"leveldb","title":"Python LevelDB Bindings (Unmaintained)","description":"This package provides Python bindings for the LevelDB key-value store. It allows Python applications to interact with LevelDB databases for embedded, persistent key-value storage. Note: This specific PyPI package (`leveldb`) is largely unmaintained (last release 2017). Version 0.201. Releases are infrequent to non-existent.","status":"abandoned","version":"0.201","language":"en","source_language":"en","source_url":"https://github.com/syndbg/python-leveldb","tags":["database","key-value","leveldb","bindings","embedded","unmaintained"],"install":[{"cmd":"pip install leveldb","lang":"bash","label":"Install the Python bindings"}],"dependencies":[{"reason":"This package provides bindings to the LevelDB C++ library, which must be installed on your system. Installation varies by OS (e.g., `sudo apt-get install libleveldb-dev` on Debian/Ubuntu).","package":"LevelDB C++ Library","optional":false}],"imports":[{"note":"The primary interface is directly from the top-level `leveldb` module, usually instantiated as `leveldb.LevelDB`.","wrong":"from leveldb import LevelDB","symbol":"LevelDB","correct":"import leveldb\ndb = leveldb.LevelDB('./path/to/db')"}],"quickstart":{"code":"import leveldb\nimport os\nimport shutil\n\n# Define a temporary database path\ndb_path = './my_temp_leveldb'\n\n# Ensure clean slate for demonstration\nif os.path.exists(db_path):\n    shutil.rmtree(db_path)\n\ntry:\n    # Open the database, creating it if it doesn't exist\n    # Note: create_if_missing is implicitly True by default\n    db = leveldb.LevelDB(db_path)\n    print(f\"Database opened at {db_path}\")\n\n    # Put a key-value pair (keys and values must be bytes)\n    db.Put(b'name', b'Alice')\n    db.Put(b'age', b'30')\n    print(\"Put: name -> Alice, age -> 30\")\n\n    # Get a value\n    name = db.Get(b'name')\n    print(f\"Get 'name': {name.decode('utf-8')}\")\n\n    # Iterate through keys\n    print(\"All keys in DB:\")\n    for key, value in db.RangeIter():\n        print(f\"  {key.decode('utf-8')}: {value.decode('utf-8')}\")\n\n    # Try to get a non-existent key (raises KeyError)\n    try:\n        db.Get(b'city')\n    except KeyError:\n        print(\"Successfully caught KeyError for non-existent key 'city'\")\n\nfinally:\n    # Clean up the database directory\n    if os.path.exists(db_path):\n        shutil.rmtree(db_path)\n        print(f\"Cleaned up database at {db_path}\")\n","lang":"python","description":"This example demonstrates opening a LevelDB database, putting and getting key-value pairs (which must be bytes), iterating over all entries, and handling missing keys."},"warnings":[{"fix":"Migrate to `plyvel`. It offers similar functionality with ongoing maintenance. Installation for `plyvel` is `pip install plyvel`.","message":"This `leveldb` PyPI package is unmaintained (last release 2017) and is known to have compatibility issues with newer Python versions and operating systems. For active development and better support, consider using `plyvel` (https://pypi.org/project/plyvel/), which is an actively maintained alternative.","severity":"breaking","affected_versions":"<=0.201"},{"fix":"Always encode strings to bytes (e.g., `b'my_key'` or `'my_key'.encode('utf-8')`) before passing them to LevelDB methods like `Put` or `Get`.","message":"Keys and values *must* be `bytes`. Attempting to use `str` will result in a `TypeError` or unexpected behavior.","severity":"gotcha","affected_versions":"<=0.201"},{"fix":"Wrap `db.Get(key)` calls in a `try...except KeyError` block, or use an alternative like `plyvel`'s `get(key, default=None)` which provides a more Pythonic default return.","message":"Retrieving a non-existent key with `db.Get(key)` will raise a `KeyError`, not return `None`.","severity":"gotcha","affected_versions":"<=0.201"},{"fix":"Ensure proper resource management, closing database connections when no longer needed. If multiple processes/threads need to access the same DB, consider a separate serialization layer or design your application to use separate DBs.","message":"Only one process can open a LevelDB database at a time for writes. Attempting to open an already-locked database for writing will result in an error or hang, typically `leveldb.Error`.","severity":"gotcha","affected_versions":"<=0.201"},{"fix":"Install the appropriate `libleveldb-dev` (or equivalent) package for your operating system (e.g., `sudo apt-get install libleveldb-dev` on Debian/Ubuntu, `brew install leveldb` on macOS).","message":"Requires the C++ LevelDB library to be installed on the system *before* `pip install leveldb`. Without it, installation will fail with compilation errors.","severity":"gotcha","affected_versions":"<=0.201"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z"}