Skip to main content

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_radius over a numpy array of points, returning distances and ids
  • Bulk loading (lists or numpy arrays) for fast construction
  • Type stubs (py.typed) for IDE and mypy support
  • 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rstar_python-0.1.0.tar.gz (15.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

rstar_python-0.1.0-cp310-abi3-win_amd64.whl (416.6 kB view details)

Uploaded CPython 3.10+Windows x86-64

rstar_python-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl (777.7 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

rstar_python-0.1.0-cp310-abi3-musllinux_1_2_aarch64.whl (734.2 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

rstar_python-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (573.4 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

rstar_python-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (558.7 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

rstar_python-0.1.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (1.1 MB view details)

Uploaded CPython 3.10+macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

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

Hashes for rstar_python-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bdea6d53a5118a00d49660298f86208df59fae798afd2f789770205f162c0858
MD5 425ee008817e0ec9343d49ae977924d9
BLAKE2b-256 806f1d4c93474ca6ef8381436e8c019311f79149787fe5abded4230c2d5b1630

See more details on using hashes here.

Provenance

The following attestation bundles were made for rstar_python-0.1.0.tar.gz:

Publisher: release.yml on kephale/rstar-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for rstar_python-0.1.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 be5a05ecf5ec1ce126d27b36e20bf9653cce9dfcff256ac5151841a2b4dd00a1
MD5 ecd7a9566337b4b383da1aa7d53d008d
BLAKE2b-256 4de2f76a0283d53d6efb59e2c48ea7960160bf74b38c655c255e34b435d0b529

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rstar_python-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for rstar_python-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 7e410ced3473a4606f78ff1d9495ab0441a9fe0bacababb6cc624c5f355f0876
MD5 53e99d8ddafff5d2e212c258a3039da3
BLAKE2b-256 dfbff5f72d5c3848552c4cf014a23de83ac8d35f83e99390b74f1170a594169d

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rstar_python-0.1.0-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for rstar_python-0.1.0-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 f800fb6632d482ee905cac19b18df328e1387f43b80f9eda4d6da671d9d46979
MD5 1ed4ff3843aa625e525f05bb7db2f287
BLAKE2b-256 692f92984dc60893e8c1510c5b9965dc1698f9cfb928500cdf2b41d4f06cfd2c

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rstar_python-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rstar_python-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 92c668e428338972e3771fc3b5300d125ad130f5cf8dd1f4297658a84d855377
MD5 85dfb1ef6a77e4bfca2b97d8967a4dab
BLAKE2b-256 08c472eec627bae600f13bc602ce84344abb17fd04b4cb08db814712f84cd6ef

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rstar_python-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for rstar_python-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 48e3e9e9f26d30c918bbae124774c5767a8d40c968a0f117245350f702ae4a4c
MD5 acf0e477c0bb17fb6b16297be22dcd55
BLAKE2b-256 976d8ecf583cc7ccab2a4d0750f6d2201b32c192f85db35d69f551c41f2087e2

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

File hashes

Hashes for rstar_python-0.1.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 cdaf9c5eeaefc6c9ab96ee747c86d0b07bfc9e91fbdaa3bebfa0c8f3a6b79130
MD5 a28d123396a6ce6423d16d9ec05a9307
BLAKE2b-256 4e006b4a67f48e70345ce7d1e245ad16b245b13a3f0ad0016465724fe4a731f4

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page