rstar-python
Python bindings for the rstar R*-tree spatial index library.
A fast, dynamic spatial index for points and stored axis-aligned bounding boxes in 2–8 dimensions. Insert and remove items after construction, run nearest-neighbour and radius searches, and query spatial regions. Each item can carry an integer id so queries can return references to your data.
Installation
pip install rstar-python
Prebuilt abi3 wheels are published for Linux, macOS, and Windows and work on
CPython 3.10+.
Why rstar-python?
| rstar-python | scipy cKDTree / sklearn KDTree |
Rtree (libspatialindex) |
|
|---|---|---|---|
| Dynamic insert / remove | ✅ | ❌ (static, rebuild) | ✅ |
| Bounding-box / region query | ✅ | ❌ (radius only) | ✅ |
| Returns ids of matches | ✅ | ✅ (row indices) | ✅ |
| Vectorised batch query | ✅ | ✅ | ❌ |
| Pure-Rust, no system C/C++ dep | ✅ | (C/Cython, bundled) | ❌ (needs libspatialindex) |
Reach for the KD-trees in scipy/scikit-learn when you build an index once from a static array and only need point/radius queries. Reach for rstar-python when you need to mutate the index over time or run bounding-box queries — with easy prebuilt wheels and no C/C++ system dependency.
Usage
import numpy as np
from rstar_python import PyBBoxRTree, PyRTree
# Create a 3D R-tree
tree = PyRTree(dims=3)
# Insert points. insert() returns the point's id.
tree.insert([1.0, 2.0, 3.0]) # -> 0 (auto-assigned)
tree.insert([4.0, 5.0, 6.0], data=42) # -> 42 (explicit id)
# Or bulk-load (replaces existing contents). Accepts lists or numpy arrays,
# and an optional list of ids.
points = np.array([[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0],
[7.0, 8.0, 9.0]], dtype=np.float64)
tree.bulk_load(points, data=[10, 20, 30])
# --- Coordinate-returning queries ---
tree.nearest_neighbor([1.1, 2.1, 3.1]) # -> [1.0, 2.0, 3.0]
tree.k_nearest_neighbors([1.1, 2.1, 3.1], k=2) # -> [[...], [...]]
tree.neighbors_within_radius([1.0, 2.0, 3.0], radius=1.0)
tree.locate_in_envelope(min_corner=[0, 0, 0], max_corner=[2, 2, 2])
tree.locate_in_envelope_ids([0, 0, 0], [2, 2, 2]) # stored ids, closed AABB
# Remove an exact point+id when coordinates are shared by multiple items.
tree.remove_item([1.0, 2.0, 3.0], data=10)
# --- Vectorised, id-returning queries (scipy/sklearn style) ---
query_pts = np.array([[1.1, 2.1, 3.1], [7.0, 8.0, 9.0]], dtype=np.float64)
distances, ids = tree.query(query_pts, k=2)
# distances: (2, 2) float64 Euclidean distances
# ids: (2, 2) int64 ids; padded with -1 / inf if fewer than k exist
within = tree.query_radius(query_pts, radius=1.0) # list of id lists
# --- Bookkeeping ---
len(tree) # number of points
tree.dims # 3
[1.0, 2.0, 3.0] in tree # membership test
tree.remove([1.0, 2.0, 3.0])
# --- Stored bounding boxes ---
boxes = PyBBoxRTree(dims=2)
boxes.insert([0.0, 0.0], [2.0, 2.0], data=100)
boxes.insert([2.0, 1.0], [3.0, 3.0])
# Returns both ids: intersection uses closed bounds, so touching counts.
boxes.intersection([1.0, 1.0], [2.0, 2.0])
# Query many boxes in one native call. Results use CSR-style row offsets:
# the matches for row i are ids[offsets[i]:offsets[i + 1]].
query_mins = np.array([[0.0, 0.0], [5.0, 5.0]], dtype=np.float64)
query_maxs = np.array([[2.0, 2.0], [6.0, 6.0]], dtype=np.float64)
ids, offsets = boxes.intersection_batch(query_mins, query_maxs)
boxes.remove_item([0.0, 0.0], [2.0, 2.0], data=100)
# Bulk loading replaces the stored boxes.
boxes.bulk_load(
min_corners=[[0.0, 0.0], [5.0, 5.0]],
max_corners=[[1.0, 1.0], [6.0, 6.0]],
data=[10, 20],
)
Features
- Points and stored axis-aligned bounding boxes in 2–8 dimensions
- Dynamic insertion and exact item removal
- Per-item integer ids (auto-assigned or supplied)
- Nearest-neighbour and k-nearest-neighbour queries
- Radius search and axis-aligned bounding-box (envelope) queries
- Vectorised point
query/query_radiusand bounding-boxintersection_batchqueries over NumPy arrays - NumPy-native batched intersection results without Python integer boxing
- Bulk loading (lists or NumPy arrays) for fast construction
- Type stubs (
py.typed) for IDE andmypysupport - Built on the fast Rust rstar library
Development
Requirements:
- Rust (stable)
- Python 3.10+
- maturin
git clone https://github.com/kephale/rstar-python
cd rstar-python
python -m venv .venv
source .venv/bin/activate # or `.venv\Scripts\activate` on Windows
pip install maturin pytest numpy
# Build and install in development mode
maturin develop --release
# Run tests
pytest python/tests -v
# Run the bounding-box performance benchmark
python python/benchmarks/benchmark_bbox_rtree.py
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for rstar-python 0.2.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 | |
|---|---|---|---|
| rstar_python-0.2.0.tar.gz | 22.8 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| rstar_python-0.2.0-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details |
| rstar_python-0.2.0-cp310-abi3-musllinux_1_2_x86_64.whl | CPython 3.10 | abi3 | Linux musl 1.2+ x86-64 | Details |
| rstar_python-0.2.0-cp310-abi3-musllinux_1_2_aarch64.whl | CPython 3.10 | abi3 | Linux musl 1.2+ ARM64 | Details |
| rstar_python-0.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| rstar_python-0.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| rstar_python-0.2.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl | CPython 3.10 | abi3 | macOS 10.12+ universal2 (ARM64, x86-64), macOS 11.0+ ARM64, macOS 10.12+ x86-64 | Details |
Total release size: 5.5 MB
Release files / rstar_python-0.2.0.tar.gz
| Download URL | rstar_python-0.2.0.tar.gz |
|---|---|
| Size | 22.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
42d3dba2e5b3054238a85d644a499d51d5a532e1c97095095d31f193ab96618b
|
|
BLAKE2b-256 checksum How to use checksums |
51cdf9f9e9225ca0438dd46ebc5c350a8a6c8f2dbc5ed37896b0f941a6464c14
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 21, 2026.
Transparency logRelease files / rstar_python-0.2.0-cp310-abi3-win_amd64.whl
| Download URL | rstar_python-0.2.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 598.2 kB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
1355d112e36d818b9d62b09627bf00de39a160caaa04238ca01afb6ea10855fc
|
|
BLAKE2b-256 checksum How to use checksums |
15132f22d60ef98aa97e6a1eafad0aea794f49b3aff515fb4eb3b7c7cbd0a0f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 21, 2026.
Transparency logRelease files / rstar_python-0.2.0-cp310-abi3-musllinux_1_2_x86_64.whl
| Download URL | rstar_python-0.2.0-cp310-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 982.0 kB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
2cf78a54f0f3971d9d3b6c1f7879647e0d0f199aeee116b7fe27cbfb8c9a3883
|
|
BLAKE2b-256 checksum How to use checksums |
63f8507b9c137ddd7d2e70c17990af7f4b6e8d6682a7f76ec7c79e1fc6dc31a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 21, 2026.
Transparency logRelease files / rstar_python-0.2.0-cp310-abi3-musllinux_1_2_aarch64.whl
| Download URL | rstar_python-0.2.0-cp310-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 934.9 kB |
| Tags | CPython 3.10 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
29e1308377ade8919514f8e9a91804d08f94838a115b9bf02332ea2b7e3d7b86
|
|
BLAKE2b-256 checksum How to use checksums |
bd964b36eaa3ab31f7e8371ff2172d47b8fe20a2a6b4596e610db9b36e04b2fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 21, 2026.
Transparency logRelease files / rstar_python-0.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | rstar_python-0.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 763.4 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
88d96ce7a2d6d0c220f994c630b1ad53b8f77094dd3a4735c63a5de22076d3f2
|
|
BLAKE2b-256 checksum How to use checksums |
0554729222a89e4658318cdc2f362e614c550b4ff03b098dfca935a99543ec90
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 21, 2026.
Transparency logRelease files / rstar_python-0.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | rstar_python-0.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 759.1 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
e30f02892a99345fc8e9d71724f8260c95196ac42af159dac43cd3704d46ce90
|
|
BLAKE2b-256 checksum How to use checksums |
86c9949f8c75365099be03dab34a824984ec370cd4d448769e9f7fd521316d40
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 21, 2026.
Transparency logRelease files / rstar_python-0.2.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
| Download URL | rstar_python-0.2.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl |
|---|---|
| Size | 1.4 MB |
| Tags | CPython 3.10 abi3 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
e82a0270f2dd9b49e0e39e94b127f2b1bedf7587ec84cecec1ba93d0bcb47965
|
|
BLAKE2b-256 checksum How to use checksums |
182187c55bfadbd675fb4b81413b79ae8b89a4392512f81157a4de5287ea79bd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 21, 2026.
Transparency log