Skip to main content

PySpart

License Python Version PyPI

Python bindings for the Spart library.

Installation

pip install pyspart

Examples

Below are some examples of how to use the different trees in PySpart.

Quadtree (2D)

from pyspart import Quadtree, Point2D

# Define the bounding area for the Quadtree.
boundary = {"x": 0.0, "y": 0.0, "width": 10.0, "height": 10.0}

# Create a new Quadtree with a maximum capacity of 3 points per node.
tree = Quadtree(boundary, 3)

# Define some 2D points.
point1 = Point2D(1.0, 2.0, "Point1")
point2 = Point2D(3.0, 4.0, "Point2")
point3 = Point2D(5.0, 6.0, "Point3")
point4 = Point2D(7.0, 8.0, "Point4")
point5 = Point2D(2.0, 3.0, "Point5")

# Insert points into the Quadtree.
tree.insert(point1)
tree.insert(point2)
tree.insert(point3)
tree.insert(point4)
tree.insert(point5)

# Perform a k-nearest neighbor (kNN) search.
neighbors = tree.knn_search(point1, 2)
print(f"kNN search results for {point1}: {neighbors}")

# Perform a range search with a radius of 5.0.
range_points = tree.range_search(point1, 5.0)
print(f"Range search results for {point1}: {range_points}")

# Remove a point from the tree.
tree.delete(point1)

Octree (3D)

from pyspart import Octree, Point3D

# Define the bounding area for the Octree.
boundary = {"x": 0.0, "y": 0.0, "z": 0.0, "width": 10.0, "height": 10.0, "depth": 10.0}

# Create a new Octree with a maximum capacity of 3 points per node.
tree = Octree(boundary, 3)

# Define some 3D points.
point1 = Point3D(1.0, 2.0, 3.0, "Point1")
point2 = Point3D(3.0, 4.0, 5.0, "Point2")
point3 = Point3D(5.0, 6.0, 7.0, "Point3")
point4 = Point3D(7.0, 8.0, 9.0, "Point4")
point5 = Point3D(2.0, 3.0, 4.0, "Point5")

# Insert points into the Octree.
tree.insert(point1)
tree.insert(point2)
tree.insert(point3)
tree.insert(point4)
tree.insert(point5)

# Perform a kNN search.
neighbors = tree.knn_search(point1, 2)
print(f"kNN search results for {point1}: {neighbors}")

# Perform a range search with a radius of 5.0.
range_points = tree.range_search(point1, 5.0)
print(f"Range search results for {point1}: {range_points}")

# Remove a point from the tree.
tree.delete(point1)

Kd-tree (3D)

from pyspart import KdTree3D, Point3D

# Create a new Kd-tree for 3D points.
tree = KdTree3D()

# Define some 3D points.
point1 = Point3D(1.0, 2.0, 3.0, "Point1")
point2 = Point3D(3.0, 4.0, 5.0, "Point2")
point3 = Point3D(5.0, 6.0, 7.0, "Point3")
point4 = Point3D(7.0, 8.0, 9.0, "Point4")
point5 = Point3D(2.0, 3.0, 4.0, "Point5")

# Insert points into the Kd-tree.
tree.insert(point1)
tree.insert(point2)
tree.insert(point3)
tree.insert(point4)
tree.insert(point5)

# Perform a kNN search.
neighbors = tree.knn_search(point1, 2)
print(f"kNN search results for {point1}: {neighbors}")

# Perform a range search with a radius of 5.0.
range_points = tree.range_search(point1, 5.0)
print(f"Range search results for {point1}: {range_points}")

# Remove a point from the tree.
tree.delete(point1)

R-tree (3D)

from pyspart import RTree3D, Point3D

# Create a new R-tree with a maximum capacity of 4 points per node.
tree = RTree3D(4)

# Define some 3D points.
point1 = Point3D(1.0, 2.0, 3.0, "Point1")
point2 = Point3D(3.0, 4.0, 5.0, "Point2")
point3 = Point3D(5.0, 6.0, 7.0, "Point3")
point4 = Point3D(7.0, 8.0, 9.0, "Point4")
point5 = Point3D(2.0, 3.0, 4.0, "Point5")

# Insert points into the R-tree.
tree.insert(point1)
tree.insert(point2)
tree.insert(point3)
tree.insert(point4)
tree.insert(point5)

# Perform a kNN search.
neighbors = tree.knn_search(point1, 2)
print(f"kNN search results for {point1}: {neighbors}")

# Perform a range search with a radius of 5.0.
range_points = tree.range_search(point1, 5.0)
print(f"Range search results for {point1}: {range_points}")

# Remove a point from the tree.
tree.delete(point1)

R*-tree (3D)

from pyspart import RStarTree3D, Point3D

# Create a new R*-tree with a maximum capacity of 4 points per node.
tree = RStarTree3D(4)

# Define some 3D points.
point1 = Point3D(1.0, 2.0, 3.0, "Point1")
point2 = Point3D(3.0, 4.0, 5.0, "Point2")
point3 = Point3D(5.0, 6.0, 7.0, "Point3")
point4 = Point3D(7.0, 8.0, 9.0, "Point4")
point5 = Point3D(2.0, 3.0, 4.0, "Point5")

# Insert points into the R*-tree.
tree.insert(point1)
tree.insert(point2)
tree.insert(point3)
tree.insert(point4)
tree.insert(point5)

# Perform a kNN search.
neighbors = tree.knn_search(point1, 2)
print(f"kNN search results for {point1}: {neighbors}")

# Perform a range search with a radius of 5.0.
range_points = tree.range_search(point1, 5.0)
print(f"Range search results for {point1}: {range_points}")

# Remove a point from the tree.
tree.delete(point1)

Check out the examples directory for more examples.

Serialization

In Python, you can use the save and load methods to serialize and deserialize the tree to and from a file:

from pyspart import Quadtree, Point2D

# Create a Quadtree and insert some points
boundary = {"x": 0.0, "y": 0.0, "width": 100.0, "height": 100.0}
qt = Quadtree(boundary, 4)
qt.insert(Point2D(10.0, 20.0, "point1"))
qt.insert(Point2D(50.0, 50.0, "point2"))

# Save the tree to a file
qt.save("quadtree.spart")

# Load the tree from the file
loaded_qt = Quadtree.load("quadtree.spart")

License

PySpart is licensed under the MIT License.

Download files

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

Source Distribution

pyspart-0.6.1.tar.gz (174.9 kB view details)

Uploaded Source

Built Distributions

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

pyspart-0.6.1-cp310-abi3-win_arm64.whl (332.2 kB view details)

Uploaded CPython 3.10+Windows ARM64

pyspart-0.6.1-cp310-abi3-win_amd64.whl (362.0 kB view details)

Uploaded CPython 3.10+Windows x86-64

pyspart-0.6.1-cp310-abi3-musllinux_1_2_x86_64.whl (436.4 kB view details)

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

pyspart-0.6.1-cp310-abi3-musllinux_1_2_aarch64.whl (398.2 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

pyspart-0.6.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (437.6 kB view details)

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

pyspart-0.6.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (401.6 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

pyspart-0.6.1-cp310-abi3-macosx_11_0_arm64.whl (377.5 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

pyspart-0.6.1-cp310-abi3-macosx_10_12_x86_64.whl (403.6 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file pyspart-0.6.1.tar.gz.

File metadata

  • Download URL: pyspart-0.6.1.tar.gz
  • Upload date:
  • Size: 174.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.19

File hashes

Hashes for pyspart-0.6.1.tar.gz
Algorithm Hash digest
SHA256 60d42b8e662c9e43d39c6283442f953b7e4a3def0ac0a953b74fa7e4952d885e
MD5 9f5569d0d1c3a8765431b04cc7bf84e3
BLAKE2b-256 5fd2743d878fbb8c6d0d3372b46b005687f67c9c13896d8cfbf7995a91fb5ac9

See more details on using hashes here.

File details

Details for the file pyspart-0.6.1-cp310-abi3-win_arm64.whl.

File metadata

  • Download URL: pyspart-0.6.1-cp310-abi3-win_arm64.whl
  • Upload date:
  • Size: 332.2 kB
  • Tags: CPython 3.10+, Windows ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyspart-0.6.1-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 88e1e41f17d048e36d1b366a7a30390e242259b62d24809a58bb77367b259b01
MD5 3e6cc32ef7a2d30c163e2230f0b637fd
BLAKE2b-256 669fae9115e8253bc4c02904558486e7504ec7a0897859bd010e3925ae7f3125

See more details on using hashes here.

File details

Details for the file pyspart-0.6.1-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: pyspart-0.6.1-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 362.0 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyspart-0.6.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ca945658f1e9b6d239023ae831b92fe8c3620c74d8c8c22bfc37767ee0e25b59
MD5 aec061f802afcdc1f1817e0cea134e41
BLAKE2b-256 8676d4418530965537f68acf3f43d1776ebd18cf0fbbf7f68eaaa8587232e0a0

See more details on using hashes here.

File details

Details for the file pyspart-0.6.1-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

  • Download URL: pyspart-0.6.1-cp310-abi3-musllinux_1_2_x86_64.whl
  • Upload date:
  • Size: 436.4 kB
  • Tags: CPython 3.10+, musllinux: musl 1.2+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyspart-0.6.1-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1a30b5f4f2821be597c1f322db3b57d945ed2ccd38283d04b42d0afc11f129e7
MD5 b5e75f9779639ae5e6a44d99a925d04b
BLAKE2b-256 1918b1b6b4723b758116aaf3c804f935db394ed647a3e2c94f251ed226996b93

See more details on using hashes here.

File details

Details for the file pyspart-0.6.1-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

  • Download URL: pyspart-0.6.1-cp310-abi3-musllinux_1_2_aarch64.whl
  • Upload date:
  • Size: 398.2 kB
  • Tags: CPython 3.10+, musllinux: musl 1.2+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyspart-0.6.1-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 60046503e9b16d9fe8ed929eb782bf81030357cb3d1055639f87a1694079974d
MD5 96df5bd15ec2bf93d764e8244f016706
BLAKE2b-256 6a0cd3e06ba058b89bf016831f8c0306b11ac919f100690d1851e00d20c032c6

See more details on using hashes here.

File details

Details for the file pyspart-0.6.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: pyspart-0.6.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 437.6 kB
  • Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyspart-0.6.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e0fb5f74bd5e75f21c81e7b6666e2f590429fd6f4bfb1c3ef917b35c157a4f5b
MD5 07e00a4b30f6e8e8fa9ab6e1f634bed1
BLAKE2b-256 048a1914130654cd54cc4d7606ef3419e4feebbd1eae414a14ac3c737c4780b9

See more details on using hashes here.

File details

Details for the file pyspart-0.6.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

  • Download URL: pyspart-0.6.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
  • Upload date:
  • Size: 401.6 kB
  • Tags: CPython 3.10+, manylinux: glibc 2.17+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyspart-0.6.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 42deaf8ad26d5d241f57e343f0fa8d133299e241e9b63c09ffe67bb661dc8e0e
MD5 92f69fa75d36c53d9582290f759f86d0
BLAKE2b-256 46f5676c6dcac622a48c81431a9a3d9b8eea520acc55fd3b17559cfe100b35f1

See more details on using hashes here.

File details

Details for the file pyspart-0.6.1-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: pyspart-0.6.1-cp310-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 377.5 kB
  • Tags: CPython 3.10+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyspart-0.6.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 36ea90cda68a9a14d27911dd7cc2da8848578b6c4df0e5dca92d639e7e001a02
MD5 917f16d73056d54d29f4eed38fb13a16
BLAKE2b-256 bc1da21d9d45e8b01184038ff3f2e9215a0f8736612b59fb8ab62b9b8c0a859c

See more details on using hashes here.

File details

Details for the file pyspart-0.6.1-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

  • Download URL: pyspart-0.6.1-cp310-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 403.6 kB
  • Tags: CPython 3.10+, macOS 10.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyspart-0.6.1-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f4928530a838bfd9d371f8fefd0f0f8b716aa64937f3a47b916aec1c5838a685
MD5 c5bb6f9454e3ea6c72b80a4b62ee39e5
BLAKE2b-256 fa108fc66b58f107a9724d7c8e5b9d451eec1b6477f63461065117b0948f41ce

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.6.1 This release

9 files

0.6.0

9 files

0.5.1

3 files

0.5.0

3 files

0.4.2

1 file

0.4.1

1 file

0.3.0

1 file

0.2.0

1 file

0.1.1

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page