rstar-python 0.1.0__cp310-abi3-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ from .rstar_python import PyRTree, __version__
2
+
3
+ __all__ = ["PyRTree", "__version__"]
rstar_python/py.typed ADDED
File without changes
Binary file
@@ -0,0 +1,77 @@
1
+ from typing import Sequence
2
+
3
+ import numpy as np
4
+ import numpy.typing as npt
5
+
6
+ __version__: str
7
+
8
+ class PyRTree:
9
+ """An R*-tree spatial index over points of 2 to 8 dimensions.
10
+
11
+ Each point carries an integer id (auto-assigned or supplied via ``data``).
12
+ Coordinate-returning queries return coordinates; the vectorised
13
+ ``query``/``query_radius`` return the stored ids.
14
+ """
15
+
16
+ def __init__(self, dims: int) -> None: ...
17
+ @property
18
+ def dims(self) -> int:
19
+ """Number of dimensions this tree indexes."""
20
+
21
+ def insert(self, point: Sequence[float], data: int | None = ...) -> int:
22
+ """Insert a single point, returning its id.
23
+
24
+ If ``data`` is omitted, an incrementing id is assigned automatically.
25
+ """
26
+
27
+ def bulk_load(
28
+ self,
29
+ points: Sequence[Sequence[float]] | npt.NDArray[np.float64],
30
+ data: Sequence[int] | None = ...,
31
+ ) -> None:
32
+ """Build the tree from many points at once (replaces existing contents).
33
+
34
+ ``data`` optionally supplies one id per point; otherwise ids are ``0..n``.
35
+ """
36
+
37
+ def nearest_neighbor(self, point: Sequence[float]) -> list[float] | None:
38
+ """Coordinates of the single nearest point, or ``None`` if empty."""
39
+
40
+ def k_nearest_neighbors(
41
+ self, point: Sequence[float], k: int
42
+ ) -> list[list[float]]:
43
+ """Coordinates of the ``k`` nearest points, closest first."""
44
+
45
+ def neighbors_within_radius(
46
+ self, point: Sequence[float], radius: float
47
+ ) -> list[list[float]]:
48
+ """Coordinates of all points within ``radius`` (Euclidean)."""
49
+
50
+ def locate_in_envelope(
51
+ self, min_corner: Sequence[float], max_corner: Sequence[float]
52
+ ) -> list[list[float]]:
53
+ """Coordinates of all points inside the axis-aligned box."""
54
+
55
+ def query(
56
+ self, points: npt.NDArray[np.float64], k: int = ...
57
+ ) -> tuple[npt.NDArray[np.float64], npt.NDArray[np.int64]]:
58
+ """Vectorised k-NN query (scipy/sklearn style).
59
+
60
+ ``points`` is an ``(M, dims)`` array. Returns ``(distances, ids)`` of
61
+ ``(M, k)`` arrays. Slots beyond the available points are ``inf`` / ``-1``.
62
+ """
63
+
64
+ def query_radius(
65
+ self, points: npt.NDArray[np.float64], radius: float
66
+ ) -> list[list[int]]:
67
+ """Vectorised radius query: per query point, the ids within ``radius``."""
68
+
69
+ def remove(self, point: Sequence[float]) -> bool:
70
+ """Remove a point by coordinates. Returns ``True`` if one was removed."""
71
+
72
+ def size(self) -> int:
73
+ """Number of points in the tree."""
74
+
75
+ def __len__(self) -> int: ...
76
+ def __contains__(self, point: Sequence[float]) -> bool: ...
77
+ def __repr__(self) -> str: ...
@@ -0,0 +1,143 @@
1
+ Metadata-Version: 2.4
2
+ Name: rstar-python
3
+ Version: 0.1.0
4
+ Classifier: Development Status :: 3 - Alpha
5
+ Classifier: Intended Audience :: Developers
6
+ Classifier: License :: OSI Approved :: MIT License
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Programming Language :: Python :: 3.10
9
+ Classifier: Programming Language :: Python :: 3.11
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Classifier: Programming Language :: Python :: 3.13
12
+ Classifier: Programming Language :: Rust
13
+ Classifier: Topic :: Scientific/Engineering
14
+ Classifier: Topic :: Software Development :: Libraries
15
+ Classifier: Operating System :: POSIX :: Linux
16
+ Classifier: Operating System :: MacOS
17
+ Classifier: Operating System :: Microsoft :: Windows
18
+ Requires-Dist: numpy>=1.21.6
19
+ License-File: LICENSE
20
+ Summary: Python bindings for the rstar R*-tree spatial index
21
+ Home-Page: https://github.com/kephale/rstar-python
22
+ Author-email: Kyle Harrington <kyle@kyleharrington.com>
23
+ License: MIT
24
+ Requires-Python: >=3.10
25
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
26
+ Project-URL: Homepage, https://github.com/kephale/rstar-python
27
+ Project-URL: Issues, https://github.com/kephale/rstar-python/issues
28
+ Project-URL: Repository, https://github.com/kephale/rstar-python
29
+
30
+ # rstar-python
31
+
32
+ Python bindings for the [rstar](https://github.com/georust/rstar) R*-tree spatial index library.
33
+
34
+ A fast, **dynamic** spatial index for points in 2–8 dimensions: insert and remove
35
+ points after construction, run nearest-neighbour and radius searches, and query
36
+ axis-aligned bounding boxes. Each point can carry an integer id so queries can
37
+ return references to *your* data, not just coordinates.
38
+
39
+ ## Installation
40
+
41
+ ```bash
42
+ pip install rstar-python
43
+ ```
44
+
45
+ Prebuilt `abi3` wheels are published for Linux, macOS, and Windows and work on
46
+ CPython 3.10+.
47
+
48
+ ## Why rstar-python?
49
+
50
+ | | rstar-python | scipy `cKDTree` / sklearn `KDTree` | `Rtree` (libspatialindex) |
51
+ | ---------------------------- | :----------: | :--------------------------------: | :-----------------------: |
52
+ | Dynamic insert / remove | ✅ | ❌ (static, rebuild) | ✅ |
53
+ | Bounding-box / region query | ✅ | ❌ (radius only) | ✅ |
54
+ | Returns ids of matches | ✅ | ✅ (row indices) | ✅ |
55
+ | Vectorised batch query | ✅ | ✅ | ❌ |
56
+ | Pure-Rust, no system C/C++ dep | ✅ | (C/Cython, bundled) | ❌ (needs libspatialindex) |
57
+
58
+ Reach for the KD-trees in scipy/scikit-learn when you build an index *once* from
59
+ a static array and only need point/radius queries. Reach for rstar-python when
60
+ you need to **mutate the index over time** or run **bounding-box queries** — with
61
+ easy prebuilt wheels and no C/C++ system dependency.
62
+
63
+ ## Usage
64
+
65
+ ```python
66
+ import numpy as np
67
+ from rstar_python import PyRTree
68
+
69
+ # Create a 3D R-tree
70
+ tree = PyRTree(dims=3)
71
+
72
+ # Insert points. insert() returns the point's id.
73
+ tree.insert([1.0, 2.0, 3.0]) # -> 0 (auto-assigned)
74
+ tree.insert([4.0, 5.0, 6.0], data=42) # -> 42 (explicit id)
75
+
76
+ # Or bulk-load (replaces existing contents). Accepts lists or numpy arrays,
77
+ # and an optional list of ids.
78
+ points = np.array([[1.0, 2.0, 3.0],
79
+ [4.0, 5.0, 6.0],
80
+ [7.0, 8.0, 9.0]], dtype=np.float64)
81
+ tree.bulk_load(points, data=[10, 20, 30])
82
+
83
+ # --- Coordinate-returning queries ---
84
+ tree.nearest_neighbor([1.1, 2.1, 3.1]) # -> [1.0, 2.0, 3.0]
85
+ tree.k_nearest_neighbors([1.1, 2.1, 3.1], k=2) # -> [[...], [...]]
86
+ tree.neighbors_within_radius([1.0, 2.0, 3.0], radius=1.0)
87
+ tree.locate_in_envelope(min_corner=[0, 0, 0], max_corner=[2, 2, 2])
88
+
89
+ # --- Vectorised, id-returning queries (scipy/sklearn style) ---
90
+ query_pts = np.array([[1.1, 2.1, 3.1], [7.0, 8.0, 9.0]], dtype=np.float64)
91
+ distances, ids = tree.query(query_pts, k=2)
92
+ # distances: (2, 2) float64 Euclidean distances
93
+ # ids: (2, 2) int64 ids; padded with -1 / inf if fewer than k exist
94
+
95
+ within = tree.query_radius(query_pts, radius=1.0) # list of id lists
96
+
97
+ # --- Bookkeeping ---
98
+ len(tree) # number of points
99
+ tree.dims # 3
100
+ [1.0, 2.0, 3.0] in tree # membership test
101
+ tree.remove([1.0, 2.0, 3.0])
102
+ ```
103
+
104
+ ## Features
105
+
106
+ - Points in 2–8 dimensions
107
+ - Dynamic `insert` / `remove`
108
+ - Per-point integer ids (auto-assigned or supplied)
109
+ - Nearest-neighbour and k-nearest-neighbour queries
110
+ - Radius search and axis-aligned bounding-box (envelope) queries
111
+ - Vectorised `query` / `query_radius` over a numpy array of points, returning
112
+ distances and ids
113
+ - Bulk loading (lists or numpy arrays) for fast construction
114
+ - Type stubs (`py.typed`) for IDE and `mypy` support
115
+ - Built on the fast Rust [rstar](https://github.com/georust/rstar) library
116
+
117
+ ## Development
118
+
119
+ Requirements:
120
+ - Rust (stable)
121
+ - Python 3.10+
122
+ - [maturin](https://github.com/PyO3/maturin)
123
+
124
+ ```bash
125
+ git clone https://github.com/kephale/rstar-python
126
+ cd rstar-python
127
+
128
+ python -m venv .venv
129
+ source .venv/bin/activate # or `.venv\Scripts\activate` on Windows
130
+
131
+ pip install maturin pytest numpy
132
+
133
+ # Build and install in development mode
134
+ maturin develop --release
135
+
136
+ # Run tests
137
+ pytest python/tests -v
138
+ ```
139
+
140
+ ## License
141
+
142
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
143
+
@@ -0,0 +1,9 @@
1
+ rstar_python/__init__.py,sha256=x-KHb-vmz4Hg-VAoy3IywKcNx-ISCaZAS_xU6ImN7sI,88
2
+ rstar_python/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ rstar_python/rstar_python.pyd,sha256=yt-YjBaVpoXUWI6yJMzo0T1VRDSRECiBIghNKPgz-Cw,1132032
4
+ rstar_python/rstar_python.pyi,sha256=7wSzm87JDk42-7aW4EWeUnaWcyCqTXXqBrKn1T-rz8I,2780
5
+ rstar_python-0.1.0.dist-info/METADATA,sha256=4E07xqX6-I681XF4-uHAbjW9ii4qMkosqSSVYmq3kAQ,5547
6
+ rstar_python-0.1.0.dist-info/WHEEL,sha256=OUT0XP5TL9Hq-6CIgsb5m6BAU8pfcNqYjx0xnFDWhNs,96
7
+ rstar_python-0.1.0.dist-info/licenses/LICENSE,sha256=1vNK5wtdii97XWiIu-tGrewxnElyhROT7asu56sopuQ,1097
8
+ rstar_python-0.1.0.dist-info/sboms/rstar-python.cyclonedx.json,sha256=PKodArq7zLicb7waKQy1SsiGrK8ZTywrjAa-TxdjtBs,39476
9
+ rstar_python-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.13.3)
3
+ Root-Is-Purelib: false
4
+ Tag: cp310-abi3-win_amd64
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Kyle I S Harrington
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.