{"id":6666,"library":"heapdict","title":"Heapdict","description":"Heapdict is a Python library that implements a mutable mapping (like a dictionary) but with the properties of a min-heap. It provides efficient decrease-key and increase-key operations, making it particularly suitable for priority queue implementations in algorithms such as Dijkstra's or A*. Unlike Python's built-in `heapq` module, heapdict allows for efficient modification of item priorities. The current version is 1.0.1, with its last release in September 2019.","status":"maintenance","version":"1.0.1","language":"en","source_language":"en","source_url":"https://github.com/DanielStutzbach/heapdict","tags":["data-structures","heap","priority-queue","dijkstra","a-star"],"install":[{"cmd":"pip install heapdict","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"symbol":"heapdict","correct":"from heapdict import heapdict"}],"quickstart":{"code":"from heapdict import heapdict\n\n# Create a new heapdict\nhd = heapdict()\n\n# Add items with priorities (key, priority)\nhd['task_A'] = 5\nhd['task_B'] = 1\nhd['task_C'] = 10\n\nprint(f\"Initial heapdict: {list(hd.items())}\")\n\n# Access the item with the lowest priority without removing it\nlowest_priority_item = hd.peekitem()\nprint(f\"Lowest priority item (peek): {lowest_priority_item}\")\n\n# Remove and return the item with the lowest priority\nfirst_task, first_priority = hd.popitem()\nprint(f\"Popped: {first_task} with priority {first_priority}\")\nprint(f\"Heapdict after pop: {list(hd.items())}\")\n\n# Change the priority of an existing item (decrease-key)\nhd['task_C'] = 2 # task_C now has higher priority than task_A\nprint(f\"Heapdict after changing task_C priority: {list(hd.items())}\")\n\n# Pop the next lowest priority item\nsecond_task, second_priority = hd.popitem()\nprint(f\"Popped: {second_task} with priority {second_priority}\")","lang":"python","description":"This example demonstrates how to create a `heapdict`, add items with associated priorities, peek at the lowest priority item, pop the lowest priority item, and efficiently change an item's priority."},"warnings":[{"fix":"As of the last stable release (1.0.1), there is no official fix. Users may need to downgrade Python, manually patch the library to use `collections.abc.MutableMapping`, or consider alternative priority queue implementations that are actively maintained for modern Python versions.","message":"Heapdict uses `collections.MutableMapping` which was deprecated in Python 3.8 and subsequently removed in Python 3.13. This causes an `AttributeError` when importing or using `heapdict` in Python 3.8+ (specifically 3.11, 3.12, 3.13 reported).","severity":"breaking","affected_versions":"Python 3.8 and above"},{"fix":"If stable sorting for equal priorities is critical, an alternative priority queue implementation should be considered, or a tie-breaking mechanism (e.g., adding an insertion index to the priority tuple) must be implemented by the user.","message":"Heapdict does not guarantee stable sorting for items with equal priorities. If multiple items have the same priority, their retrieval order is not guaranteed to be FIFO (First-In, First-Out), which differs from `heapq.nsmallest`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Users should be aware of the maintenance status and thoroughly test `heapdict` in their target Python environment, especially with Python versions newer than 3.7. Consider contributing fixes or using more actively maintained alternatives if long-term support is critical.","message":"The project has not seen a new release since September 2019, and several open issues exist regarding compatibility with newer Python versions and potential minor bugs. This indicates limited active maintenance.","severity":"gotcha","affected_versions":"All versions (due to lack of recent updates)"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}