rheapdict
A Rust-powered indexed priority queue for Python: a dict that is also a
heap, with O(log n) decrease-key / increase-key. Exposed via
PyO3.
from rheapdict import HeapDict
pq = HeapDict({"a": 3, "b": 1})
pq["c"] = 2 # insert
pq["a"] = 0 # decrease-key, O(log n)
pq.popitem() # -> ("a", 0)
Why
Python's heapq has no way to change an item's priority, so algorithms like
Dijkstra, A*, Prim, LFU caches, and discrete-event schedulers either push
duplicate entries and skip stale ones, or use an indexed priority queue. The
existing indexed PQs (heapdict, last released 2019, and pqdict) are pure
Python, so every sift step runs in the interpreter.
rheapdict keeps the key→slot index in a real dict (so hashing and
equality keep exact Python semantics, at C speed) and runs the heap in Rust.
When both priorities are exact int/float, it compares them natively.
Anything else (tuples, Decimal, custom objects) falls back to Python's <.
Install
pip install rheapdict
Prebuilt abi3 wheels (Linux/macOS/Windows, Python 3.11+).
Benchmarks
Single-threaded, release build, random float priorities and str keys.
Source: benchmarks/bench.py.
| workload | n | rheapdict | heapdict | pqdict |
|---|---|---|---|---|
| push all, pop all | 100,000 | 0.13s | 0.91s | 0.86s |
| push n + 2n priority updates, pop all | 100,000 | 0.22s | 3.25s | 1.43s |
| Dijkstra, 8 edges/node | 100,000 | 0.46s | 2.10s | 1.48s |
| push all, pop all | 1,000,000 | 2.16s | 17.5s | 15.2s |
| push n + 2n priority updates, pop all | 1,000,000 | 3.43s | 55.4s | 22.8s |
| Dijkstra, 8 edges/node | 1,000,000 | 7.40s | 37.0s | 24.8s |
That is 4–16x faster than heapdict/pqdict. For reference, plain heapq
with (priority, key) tuples (no decrease-key at all) takes 2.63s for the
1M push/pop workload, so rheapdict is faster than that too, because it
avoids comparing tuples in Python.
API
HeapDict implements the MutableMapping interface (len, in, [],
del, get, pop, setdefault, update, keys/values/items,
clear, copy) plus the following:
| method | meaning |
|---|---|
popitem() |
remove and return the top (key, priority) |
peekitem() / topitem() |
return the top (key, priority) without removing it |
top() |
return the top key |
pop() |
with no arguments, remove and return the top key (pqdict semantics) |
push(k, p) / additem(k, p) |
insert a new key (KeyError if it is already present) |
updateitem(k, p) |
change an existing key (KeyError if it is missing) |
pushpopitem(k, p) |
push then pop in one step (faster than the two calls) |
HeapDict(..., max_heap=True) |
pop the largest priority first |
heapdict and pqdict are exported as aliases to ease migration.
Semantics
- Ties pop FIFO: equal priorities come out in insertion order, so the
output is deterministic (neither
heapdictnorheapqguarantees this). An item keeps its insertion position when its priority is updated. - Iteration (
iter,keys(), ...) is in insertion order, not priority order, and is a snapshot (mutating while iterating is safe). - Empty pops raise
KeyError, matchingdict.popitem. - Incomparable priorities (e.g.
1vs"x") raiseTypeError. As withheapq, the item is still stored, and the heap stays structurally valid. - Large ints:
intvsfloatcomparisons are exact (ints beyond 2^53 fall back to Python comparison). - Picklable and copyable. Subclassable.
Development
cargo test --no-default-features # Rust unit tests of the core heap
pip install -e '.[dev]' && maturin develop --release
pytest # includes a Hypothesis model test
python benchmarks/bench.py
Metadata
Release files for rheapdict 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rheapdict-0.1.0.tar.gz | 18.3 kB | With provenance | Details for rheapdict-0.1.0.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| rheapdict-0.1.0-cp311-abi3-win_amd64.whl | CPython 3.11 | abi3 | Windows x86-64 | Details for rheapdict-0.1.0-cp311-abi3-win_amd64.whl |
| rheapdict-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ x86-64 | Details for rheapdict-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
| rheapdict-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ ARM64 | Details for rheapdict-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
| rheapdict-0.1.0-cp311-abi3-macosx_11_0_arm64.whl | CPython 3.11 | abi3 | macOS 11.0+ ARM64 | Details for rheapdict-0.1.0-cp311-abi3-macosx_11_0_arm64.whl |
| rheapdict-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl | CPython 3.11 | abi3 | macOS 10.12+ x86-64 | Details for rheapdict-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl |
Total release size: 1.2 MB
Release files / rheapdict-0.1.0.tar.gz
| Download URL | rheapdict-0.1.0.tar.gz |
|---|---|
| Size | 18.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
45b2a3bc06bdf6c1b5efdcbf4b4b3d59dc5c44e205311cbab8ad353b74ddecf8
|
|
BLAKE2b-256 checksum How to use checksums |
1a0bf6ad210bcea7413294301d1afb0fc9e293044859bc3f01785b0657408f95
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logRelease files / rheapdict-0.1.0-cp311-abi3-win_amd64.whl
| Download URL | rheapdict-0.1.0-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 157.5 kB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
68ce44e803241febd21288d8e4241927e4435c3c8a66cc7dc225ea047f4ea8e2
|
|
BLAKE2b-256 checksum How to use checksums |
3d3246841fcf03fa66b85ca6ddfda5614a0022af780c2f873212e760403d17dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logRelease files / rheapdict-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | rheapdict-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 264.3 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
805f14b15a5da194bc200c539fe113a62505fccdc7ab6b13b8e54bcbcf3536dc
|
|
BLAKE2b-256 checksum How to use checksums |
3407beaaa45b2ac9c6994ffc9db4788acd6ec3bf6b28dacb458f8f692de4cf1d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logRelease files / rheapdict-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
| Download URL | rheapdict-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
|---|---|
| Size | 262.1 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
7c16b361c3302cfd5c6f0282ca5457e3a855f49cc0d62bd25b5e1f58303b07ea
|
|
BLAKE2b-256 checksum How to use checksums |
f8f738d86714e4b0401e450d30e34e340ce62b510f811b119915866488f25355
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logRelease files / rheapdict-0.1.0-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | rheapdict-0.1.0-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 243.7 kB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
3972d39e7fbef6914c77416cc71883bbfbfe2ad02d14c4abdd34ad5af26979c3
|
|
BLAKE2b-256 checksum How to use checksums |
0041e9557dbf07186795c0552432a8402771849fe91e479422d4fdc3826e5843
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logRelease files / rheapdict-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl
| Download URL | rheapdict-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 250.3 kB |
| Tags | CPython 3.11 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
4104c44aeebbbd88b73776f78ebd9f0682744b8bed1e6f501f2adc4a58a3d536
|
|
BLAKE2b-256 checksum How to use checksums |
7dcb0bc328af1cc7250d5c515e29af9f060df27c1c64aceb5e70136567cb152e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logSecurity for rheapdict 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 6 files in this release have been uploaded with provenance metadata.
Attestation for rheapdict-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.