
Research
2025 Report: Destructive Malware in Open Source Packages
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.
fastquadtree
Advanced tools
Rust-accelerated quadtree for Python with fast inserts, range queries, and k-NN search.

Rust-optimized quadtree with a clean Python API
👉 Check out the Docs: https://elan456.github.io/fastquadtree/
See examples of how fastquadtree can be used in the runnables section.
pip install fastquadtree
from fastquadtree import QuadTree # Point handling
from fastquadtree import RectQuadTree # Bounding box handling
from fastquadtree import QuadTreeObjects # Point handling with object tracking
from fastquadtree import RectQuadTreeObjects # Bounding box handling with object tracking
from fastquadtree.pyqtree import Index # Drop-in pyqtree shim (~6.5x faster while keeping the same API)
fastquadtree outperforms all other quadtree Python packages, including the Rtree spatial index.

| Library | Build (s) | Query (s) | Total (s) | Speed vs PyQtree |
|---|---|---|---|---|
| fastquadtree (np)1 | 0.057 | 0.021 | 0.078 | 54.45× |
| fastquadtree2 | 0.060 | 0.189 | 0.249 | 17.04× |
| Shapely STRtree3 | 0.321 | 0.196 | 0.517 | 8.21× |
| fastquadtree (obj tracking)4 | 0.437 | 0.239 | 0.675 | 6.28× |
| Rtree | 1.796 | 0.561 | 2.357 | 1.80× |
| nontree-QuadTree | 1.275 | 1.272 | 2.547 | 1.67× |
| e-pyquadtree | 2.144 | 1.507 | 3.650 | 1.16× |
| quads | 3.001 | 1.171 | 4.172 | 1.02× |
| PyQtree | 3.677 | 0.565 | 4.242 | 1.00× |
See the benchmark section for details, including configurations, system info, and native vs shim benchmarks.
QuadTree(bounds, capacity, max_depth=None, dtype="f32")bounds — tuple (min_x, min_y, max_x, max_y) defines the 2D area covered by the quadtreecapacity — max number of points kept in a leaf before splittingmax_depth — optional depth cap. If omitted, the tree can keep splitting as neededdtype — data type for coordinates, e.g., "f32", "f64", "i32", "i64"insert(xy, id_=None) -> int
query(rect) -> list[tuple[int, float, float]]
nearest_neighbor(xy) -> tuple[int, float, float] | None
delete(id, x, y) -> bool
For object tracking, use QuadTreeObjects instead. See the docs for more methods.
(min_x, min_y, max_x, max_y).(x >= min_x and x < max_x and y >= min_y and y < max_y).
This only matters for points exactly on edges.capacity so that leaves keep a small batch of points. Typical values are 8 to 64.max_depth to prevent long chains.maturin develop --release.QuadTree when you only need spatial indexing. Use QuadTreeObjects when you need to store Python objects with your points.
A simple demo of moving objects with collision detection using fastquadtree. You can toggle between quadtree mode and brute-force mode to see the performance difference.
See the runnables guide for setup instructions.
Can I delete items from the quadtree?
Yes! Use delete(id, x, y) to remove specific items. You must provide both the ID and exact location for precise deletion. This handles cases where multiple items exist at the same location. If you're using QuadTreeObjects, you can also use delete_by_object(obj) for convenient object-based deletion with O(1) lookup. The tree automatically merges nodes when item counts drop below capacity.
Can I store rectangles or circles?
Yes, you can store rectangles using the RectQuadTree class. Circles can be approximated with bounding boxes. See the RectQuadTree docs for details.
Do I need NumPy installed?
No, NumPy is a fully optional dependency. If you do have NumPy installed, you can use methods such as query_np and insert_many_np for better performance. Note that insert_many raises TypeError on NumPy input—you must use insert_many_np explicitly for NumPy arrays. The Rust core is able to handle NumPy arrays faster than Python lists, so there's a lot of time savings in utilizing the NumPy functions. See the Native vs Shim benchmark for details on how returing NumPy arrays can speed up queries.
# Using Python lists
qt.insert_many([(10, 20), (30, 40), (50, 60)])
# Using NumPy arrays (requires NumPy)
import numpy as np
points = np.array([[10, 20], [30, 40], [50, 60]])
qt.insert_many_np(points) # Use insert_many_np for NumPy arrays
Does fastquadtree support multiprocessing?
Yes, fastquadtree objects can be serialized to bytes using the to_bytes() method and deserialized back using from_bytes(). This allows you to share quadtree data across processes and even cache prebuilt trees to disk. When using QuadTreeObjects or RectQuadTreeObjects, you must pass include_objects=True to to_bytes() to serialize Python objects, and allow_objects=True to from_bytes() when loading. By default, objects are skipped for safety, as deserializing untrusted Python objects can be unsafe. See the interactive v2 demo for an example of saving and loading a quadtree, and the QuadTreeObjects API docs for full details on the serialization methods.
MIT. See LICENSE.
FAQs
Rust-accelerated quadtree for Python with fast inserts, range queries, and k-NN search.
We found that fastquadtree demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.

Research
/Security News
A five-month operation turned 27 npm packages into durable hosting for browser-run lures that mimic document-sharing portals and Microsoft sign-in, targeting 25 organizations across manufacturing, industrial automation, plastics, and healthcare for credential theft.