Python bindings for the rstar R*-tree spatial index
Project description
rstar-python
Python bindings for the rstar R*-tree spatial index library.
A fast, dynamic spatial index for points in 2–8 dimensions: insert and remove points after construction, run nearest-neighbour and radius searches, and query axis-aligned bounding boxes. Each point can carry an integer id so queries can return references to your data, not just coordinates.
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 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])
# --- 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])
Features
- Points in 2–8 dimensions
- Dynamic
insert/remove - Per-point integer ids (auto-assigned or supplied)
- Nearest-neighbour and k-nearest-neighbour queries
- Radius search and axis-aligned bounding-box (envelope) queries
- Vectorised
query/query_radiusover a numpy array of points, returning distances and ids - 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
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rstar_python-0.1.0.tar.gz.
File metadata
- Download URL: rstar_python-0.1.0.tar.gz
- Upload date:
- Size: 15.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bdea6d53a5118a00d49660298f86208df59fae798afd2f789770205f162c0858
|
|
| MD5 |
425ee008817e0ec9343d49ae977924d9
|
|
| BLAKE2b-256 |
806f1d4c93474ca6ef8381436e8c019311f79149787fe5abded4230c2d5b1630
|
Provenance
The following attestation bundles were made for rstar_python-0.1.0.tar.gz:
Publisher:
release.yml on kephale/rstar-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rstar_python-0.1.0.tar.gz -
Subject digest:
bdea6d53a5118a00d49660298f86208df59fae798afd2f789770205f162c0858 - Sigstore transparency entry: 1753662857
- Sigstore integration time:
-
Permalink:
kephale/rstar-python@268d78164cc15b6177d6281d61390cce56ef826b -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/kephale
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@268d78164cc15b6177d6281d61390cce56ef826b -
Trigger Event:
push
-
Statement type:
File details
Details for the file rstar_python-0.1.0-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: rstar_python-0.1.0-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 416.6 kB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be5a05ecf5ec1ce126d27b36e20bf9653cce9dfcff256ac5151841a2b4dd00a1
|
|
| MD5 |
ecd7a9566337b4b383da1aa7d53d008d
|
|
| BLAKE2b-256 |
4de2f76a0283d53d6efb59e2c48ea7960160bf74b38c655c255e34b435d0b529
|
Provenance
The following attestation bundles were made for rstar_python-0.1.0-cp310-abi3-win_amd64.whl:
Publisher:
release.yml on kephale/rstar-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rstar_python-0.1.0-cp310-abi3-win_amd64.whl -
Subject digest:
be5a05ecf5ec1ce126d27b36e20bf9653cce9dfcff256ac5151841a2b4dd00a1 - Sigstore transparency entry: 1753662869
- Sigstore integration time:
-
Permalink:
kephale/rstar-python@268d78164cc15b6177d6281d61390cce56ef826b -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/kephale
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@268d78164cc15b6177d6281d61390cce56ef826b -
Trigger Event:
push
-
Statement type:
File details
Details for the file rstar_python-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: rstar_python-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 777.7 kB
- Tags: CPython 3.10+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e410ced3473a4606f78ff1d9495ab0441a9fe0bacababb6cc624c5f355f0876
|
|
| MD5 |
53e99d8ddafff5d2e212c258a3039da3
|
|
| BLAKE2b-256 |
dfbff5f72d5c3848552c4cf014a23de83ac8d35f83e99390b74f1170a594169d
|
Provenance
The following attestation bundles were made for rstar_python-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl:
Publisher:
release.yml on kephale/rstar-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rstar_python-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl -
Subject digest:
7e410ced3473a4606f78ff1d9495ab0441a9fe0bacababb6cc624c5f355f0876 - Sigstore transparency entry: 1753662879
- Sigstore integration time:
-
Permalink:
kephale/rstar-python@268d78164cc15b6177d6281d61390cce56ef826b -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/kephale
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@268d78164cc15b6177d6281d61390cce56ef826b -
Trigger Event:
push
-
Statement type:
File details
Details for the file rstar_python-0.1.0-cp310-abi3-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: rstar_python-0.1.0-cp310-abi3-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 734.2 kB
- Tags: CPython 3.10+, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f800fb6632d482ee905cac19b18df328e1387f43b80f9eda4d6da671d9d46979
|
|
| MD5 |
1ed4ff3843aa625e525f05bb7db2f287
|
|
| BLAKE2b-256 |
692f92984dc60893e8c1510c5b9965dc1698f9cfb928500cdf2b41d4f06cfd2c
|
Provenance
The following attestation bundles were made for rstar_python-0.1.0-cp310-abi3-musllinux_1_2_aarch64.whl:
Publisher:
release.yml on kephale/rstar-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rstar_python-0.1.0-cp310-abi3-musllinux_1_2_aarch64.whl -
Subject digest:
f800fb6632d482ee905cac19b18df328e1387f43b80f9eda4d6da671d9d46979 - Sigstore transparency entry: 1753662912
- Sigstore integration time:
-
Permalink:
kephale/rstar-python@268d78164cc15b6177d6281d61390cce56ef826b -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/kephale
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@268d78164cc15b6177d6281d61390cce56ef826b -
Trigger Event:
push
-
Statement type:
File details
Details for the file rstar_python-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: rstar_python-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 573.4 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92c668e428338972e3771fc3b5300d125ad130f5cf8dd1f4297658a84d855377
|
|
| MD5 |
85dfb1ef6a77e4bfca2b97d8967a4dab
|
|
| BLAKE2b-256 |
08c472eec627bae600f13bc602ce84344abb17fd04b4cb08db814712f84cd6ef
|
Provenance
The following attestation bundles were made for rstar_python-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release.yml on kephale/rstar-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rstar_python-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
92c668e428338972e3771fc3b5300d125ad130f5cf8dd1f4297658a84d855377 - Sigstore transparency entry: 1753662891
- Sigstore integration time:
-
Permalink:
kephale/rstar-python@268d78164cc15b6177d6281d61390cce56ef826b -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/kephale
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@268d78164cc15b6177d6281d61390cce56ef826b -
Trigger Event:
push
-
Statement type:
File details
Details for the file rstar_python-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: rstar_python-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 558.7 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48e3e9e9f26d30c918bbae124774c5767a8d40c968a0f117245350f702ae4a4c
|
|
| MD5 |
acf0e477c0bb17fb6b16297be22dcd55
|
|
| BLAKE2b-256 |
976d8ecf583cc7ccab2a4d0750f6d2201b32c192f85db35d69f551c41f2087e2
|
Provenance
The following attestation bundles were made for rstar_python-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
release.yml on kephale/rstar-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rstar_python-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
48e3e9e9f26d30c918bbae124774c5767a8d40c968a0f117245350f702ae4a4c - Sigstore transparency entry: 1753662921
- Sigstore integration time:
-
Permalink:
kephale/rstar-python@268d78164cc15b6177d6281d61390cce56ef826b -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/kephale
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@268d78164cc15b6177d6281d61390cce56ef826b -
Trigger Event:
push
-
Statement type:
File details
Details for the file rstar_python-0.1.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.
File metadata
- Download URL: rstar_python-0.1.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.10+, macOS 10.12+ universal2 (ARM64, x86-64), macOS 10.12+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cdaf9c5eeaefc6c9ab96ee747c86d0b07bfc9e91fbdaa3bebfa0c8f3a6b79130
|
|
| MD5 |
a28d123396a6ce6423d16d9ec05a9307
|
|
| BLAKE2b-256 |
4e006b4a67f48e70345ce7d1e245ad16b245b13a3f0ad0016465724fe4a731f4
|
Provenance
The following attestation bundles were made for rstar_python-0.1.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:
Publisher:
release.yml on kephale/rstar-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rstar_python-0.1.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl -
Subject digest:
cdaf9c5eeaefc6c9ab96ee747c86d0b07bfc9e91fbdaa3bebfa0c8f3a6b79130 - Sigstore transparency entry: 1753662900
- Sigstore integration time:
-
Permalink:
kephale/rstar-python@268d78164cc15b6177d6281d61390cce56ef826b -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/kephale
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@268d78164cc15b6177d6281d61390cce56ef826b -
Trigger Event:
push
-
Statement type: