Intervaltree in rust
This crate exposes an interval tree implementation written in Rust to Python via PyO3. The Python wrapper provides the ability to build a tree from tuples, insert additional intervals, search for overlaps, and delete intervals by their (left, right) key.
Requirements
- Rust toolchain (for compiling the extension module)
- Python 3.8+
- maturin for building/installing the package
Quick start
python -m venv .venv
source .venv/bin/activate
pip install maturin
maturin develop
You can install the package with (also with uv)
pip install intervaltree_rs
maturin develop builds the extension module in-place and installs it into the active virtual environment, making it importable as intervaltree_rs.
Usage
Once installed, you can use the interval tree directly from Python:
from intervaltree_rs import IntervalTree
# Build a tree from tuples: (left, right, payload)
intervals = [
(5, 10, "a"),
(12, 18, "b"),
(1, 4, "c"),
]
tree = IntervalTree.from_tuples(intervals)
# Insert another interval
tree.insert((8, 11, "d"))
# Search for overlaps. Inclusive bounds are enabled by default.
hits = tree.search(9, 10)
for left, right, value in hits:
print(left, right, value)
# Delete by the interval key
removed = tree.delete((12, 18))
print("Removed:", removed)
Search options
IntervalTree.search(ql, qr, inclusive=True) accepts an inclusive flag. Set it to False to perform exclusive range queries.
Building a distributable wheel
To build a wheel that you can distribute or upload to PyPI, run:
maturin build --release
The built wheels will be placed under target/wheels/.
Running tests
The Python bindings are covered by Rust unit tests. Run them with:
cargo test
Metadata
Release files for intervaltree-rs 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| intervaltree_rs-0.1.1.tar.gz | 635.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| intervaltree_rs-0.1.1-cp38-abi3-macosx_11_0_arm64.whl | CPython 3.8 | abi3 | macOS 11.0+ ARM64 | Details |
Total release size: 851.2 kB
Release files / intervaltree_rs-0.1.1.tar.gz
| Download URL | intervaltree_rs-0.1.1.tar.gz |
|---|---|
| Size | 635.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bbe59aded265c772433d5c83a065f7b53b482463dd34fd2293f85c63aac9ca91
|
|
BLAKE2b-256 checksum How to use checksums |
e9d23d42d477ff13124e15e16a6d18660d6ccc13b890691787307a061707f697
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.9.6
|
Release files / intervaltree_rs-0.1.1-cp38-abi3-macosx_11_0_arm64.whl
| Download URL | intervaltree_rs-0.1.1-cp38-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 216.0 kB |
| Tags | CPython 3.8 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
33f961f4349d622ff593aef89563f8ff50e2c542cfbca04d6492a06d8b28eb54
|
|
BLAKE2b-256 checksum How to use checksums |
49b367d99f0d2f63016d792b3c4894d80ceac56651fdfd018fb2ad9bdc5664f7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.9.6
|