Registry / data / heapdict

heapdict

JSON →
library1.0.1pypypi✓ verified 84d ago

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.

pip install heapdict
INSTALL
IMPORT
SIG · HEAPDICT
H
heapdict
datapythonv1.0.1
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

heapdict
from heapdict import heapdict

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.

from heapdict import heapdict # Create a new heapdict hd = heapdict() # Add items with priorities (key, priority) hd['task_A'] = 5 hd['task_B'] = 1 hd['task_C'] = 10 print(f"Initial heapdict: {list(hd.items())}") # Access the item with the lowest priority without removing it lowest_priority_item = hd.peekitem() print(f"Lowest priority item (peek): {lowest_priority_item}") # Remove and return the item with the lowest priority first_task, first_priority = hd.popitem() print(f"Popped: {first_task} with priority {first_priority}") print(f"Heapdict after pop: {list(hd.items())}") # Change the priority of an existing item (decrease-key) hd['task_C'] = 2 # task_C now has higher priority than task_A print(f"Heapdict after changing task_C priority: {list(hd.items())}") # Pop the next lowest priority item second_task, second_priority = hd.popitem() print(f"Popped: {second_task} with priority {second_priority}")
Debug
Known issues
breakingHeapdict 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).
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.
affects: Python 3.8 and above
gotchaHeapdict 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`.
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.
affects: All versions
gotchaThe 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.
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.
affects: All versions (due to lack of recent updates)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'heapdict'
The 'heapdict' library is not installed in your Python environment or the environment is not correctly activated.
fix
Install the package using pip: `pip install heapdict`
KeyError: 'your_key_here'
You are attempting to access, delete, or modify a key that does not exist in the heapdict instance. Like a standard Python dictionary, heapdict raises KeyError for non-existent keys.
fix
Before accessing a key, check for its existence using the `in` operator (e.g., `if key in hd:`), use the `get()` method with a default value (e.g., `hd.get(key, default_value)`), or wrap the access in a `try-except KeyError` block.
TypeError: object of type 'NoneType' has no len()
This error occurs when an operation attempts to call `len()` on an object that is `None`. This often happens if a key or value retrieved from the `heapdict` is `None` (or another type without a `__len__` method), and subsequent code tries to get its length.
fix
Ensure that any objects (keys or values) you retrieve from `heapdict` and subsequently operate on are not `None` or a type that doesn't support the `len()` function when such an operation is performed. Add checks for `None` or validate the type of the retrieved object before calling `len()`.
Upgrade
Version history
1.0.1latest on PyPI · released Sep 9, 2019
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
heapdict — pip install heapdict · libregistry