{"id":3216,"library":"plyvel","title":"Plyvel, a fast and feature-rich Python interface to LevelDB","description":"Plyvel is a fast and feature-rich Python interface to LevelDB. It provides a comprehensive, high-performance Pythonic API that wraps most of the underlying LevelDB C++ API, leveraging Cython for speed. Key features include support for write batches, database snapshots, flexible iterators, and prefixed databases. The library is actively maintained, with version 1.5.1 released in January 2024, consistently adding support for new Python versions and ensuring compatibility with recent LevelDB releases.","status":"active","version":"1.5.1","language":"python","source_language":"en","source_url":"https://github.com/wbolster/plyvel","tags":["database","leveldb","key-value store","nosql","embedded database"],"install":[{"cmd":"pip install plyvel","lang":"bash","label":"Recommended Installation"},{"cmd":"sudo apt-get install libleveldb1v5 libleveldb-dev python3-dev\npip install plyvel","lang":"bash","label":"Installation from source (Debian/Ubuntu example)"}],"dependencies":[{"reason":"Core database engine. Pre-built wheels often embed it; source builds require development headers and shared library.","package":"leveldb","optional":false},{"reason":"Required for building from source.","package":"cython","optional":true}],"imports":[{"symbol":"plyvel","correct":"import plyvel"},{"note":"Main class for interacting with a LevelDB database.","symbol":"DB","correct":"db = plyvel.DB(...)"}],"quickstart":{"code":"import plyvel\nimport os\nimport shutil\n\n# Define a path for the LevelDB database\ndb_path = '/tmp/testdb_plyvel_quickstart'\n\n# Clean up any previous database at the path\nif os.path.exists(db_path):\n    shutil.rmtree(db_path)\n\ntry:\n    # Open a new database, creating it if it doesn't exist\n    # Using a context manager ensures the database is properly closed\n    with plyvel.DB(db_path, create_if_missing=True) as db:\n        print(f\"Database opened at: {db_path}\")\n\n        # Put key-value pairs (keys and values must be bytes)\n        db.put(b'name', b'Alice')\n        db.put(b'age', b'30')\n        db.put(b'city', b'New York')\n\n        # Get a value\n        name = db.get(b'name')\n        if name:\n            print(f\"Name: {name.decode('utf-8')}\")\n\n        # Iterate over all key-value pairs\n        print(\"\\nAll entries:\")\n        for key, value in db:\n            print(f\"  {key.decode('utf-8')}: {value.decode('utf-8')}\")\n\n        # Delete a key\n        db.delete(b'age')\n        print(\"\\nAfter deleting 'age':\")\n\n        # Verify deletion by iterating again\n        for key, value in db:\n            print(f\"  {key.decode('utf-8')}: {value.decode('utf-8')}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\nfinally:\n    # Ensure cleanup even if an error occurs\n    if os.path.exists(db_path):\n        shutil.rmtree(db_path)\n        print(f\"\\nCleaned up database directory: {db_path}\")","lang":"python","description":"This quickstart demonstrates opening a LevelDB database, performing basic put, get, and delete operations, and iterating over stored key-value pairs using `plyvel`. It highlights the recommended practice of using `plyvel.DB` as a context manager for automatic resource management and proper database closing."},"warnings":[{"fix":"Upgrade to Python 3 or pin Plyvel version to <1.3.0 if Python 2 compatibility is essential.","message":"Plyvel 1.3.0 (released October 2020) completely dropped support for Python 2. Users migrating to newer Plyvel versions must ensure their projects are running on Python 3.","severity":"breaking","affected_versions":"<1.3.0 (for Python 2 support)"},{"fix":"Use pre-built binary wheels where available, or install `LevelDB` development headers (e.g., `sudo apt-get install libleveldb-dev`) before `pip install plyvel`.","message":"Installing Plyvel from source (not via pre-built wheels) requires LevelDB development headers and a compatible LevelDB shared library (>= 1.21 for Plyvel 1.4.0+). Failing to provide these can lead to compilation errors or `ImportError` due to undefined symbols. On Linux, `pip install plyvel` often works due to embedded LevelDB in wheels, but if building from source, install `libleveldb-dev` (or equivalent) first.","severity":"gotcha","affected_versions":"All versions when building from source"},{"fix":"Always ensure exclusive access or use `plyvel.DB` as a context manager (`with plyvel.DB(...) as db:`) which handles closing safely at the end of the block.","message":"Closing a `plyvel.DB` instance while it is actively being accessed by other threads can lead to hard crashes due to a lack of internal synchronization. Ensure that no other threads are performing database operations concurrently when calling `DB.close()`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Avoid Python-based custom comparators in performance-critical sections. Rely on LevelDB's default byte-wise comparator or consider alternative key encoding strategies if custom ordering is needed without the performance cost.","message":"Implementing custom LevelDB comparators using Python callables in Plyvel incurs a significant performance penalty (e.g., up to a 4x slowdown for bulk writes) compared to LevelDB's native C++ comparators.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'1.5.1':67 '2024':71 'activ':63 'ad':73 'api':32,41 'batch':52 'c':40 'compat':81 'comprehens':27 'consist':72 'cython':43 'databas':53,59,86,94 'embed':93 'ensur':80 'fast':3,15 'featur':6,18,47 'feature-rich':5,17 'flexibl':55 'high':29 'high-perform':28 'includ':48 'interfac':9,21 'iter':56 'januari':70 'key':46,89 'key-valu':88 'leveldb':11,23,39,84,87 'leverag':42 'librari':61 'maintain':64 'new':76 'nosql':92 'perform':30 'plyvel':1,12 'prefix':58 'provid':25 'python':8,20,31,77 'recent':83 'releas':68,85 'rich':7,19 'snapshot':54 'speed':45 'store':91 'support':49,74 'under':38 'valu':90 'version':66,78 'wrap':34 'write':51","created_at":"2026-04-11T09:25:59.627108+00:00","updated_at":"2026-04-16T18:04:55.873090+00:00","problems":[{"fix":"pip install plyvel","cause":"The 'plyvel' package is not installed in the current Python environment.","error":"ModuleNotFoundError: No module named 'plyvel'"},{"fix":"Install the LevelDB development package for your operating system (e.g., `sudo apt-get install libleveldb-dev` on Debian/Ubuntu, `brew install leveldb` on macOS).","cause":"During installation, the 'plyvel' C++ extension cannot find the LevelDB development headers on your system, which are required to build the library from source.","error":"fatal error: 'leveldb/db.h': No such file or directory"},{"fix":"Ensure all `plyvel.DB` instances are properly closed using `db.close()` or by using them as context managers (`with plyvel.DB(...) as db:`). Verify no other processes are accessing the database directory.","cause":"Another process or a previously unclosed `plyvel.DB` instance is holding a lock on the LevelDB database directory, preventing a new instance from opening it. LevelDB databases can only be opened by one process at a time.","error":"plyvel._plyvel.IOError: IO error: lock /path/to/db/LOCK: Resource temporarily unavailable"},{"fix":"Ensure your system's LevelDB library meets the 'plyvel' version requirements (LevelDB >= 1.20 for Plyvel 1.x). Upgrade your system's LevelDB (e.g., `sudo apt-get install libleveldb-dev libleveldb1v5` or manual installation). Alternatively, install an older 'plyvel' version compatible with your system's LevelDB (`pip install plyvel==<compatible_version>`).","cause":"This 'undefined symbol' error indicates a mismatch between the LevelDB C++ library that 'plyvel' was compiled against and the LevelDB library available on your system at runtime, often due to version incompatibility (e.g., system LevelDB is older than required by Plyvel 1.x, which needs LevelDB >= 1.20).","error":"ImportError: dlopen(/path/to/plyvel/_plyvel.so, 2): Symbol not found: __ZTIN7leveldb10ComparatorE"},{"fix":"Ensure the specified database directory exists and that the Python process has full read/write permissions to it. Use an absolute path. On Windows, complex installation steps for LevelDB and setting environment variables may be necessary if `pip install plyvel` fails to use pre-built wheels.","cause":"The LevelDB database path is inaccessible, has incorrect permissions, or contains invalid characters, preventing LevelDB from creating its necessary lock file or other files, especially on Windows.","error":"plyvel._plyvel.Error: NotFound: c:/tmp/testdb/LOCK: The system cannot find the path specified"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.5.1","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/wbolster/plyvel","docs":null,"changelog":null,"pypi":"https://pypi.org/project/plyvel/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-28","next_check":"2026-07-28","install_tag":null}}