Skip to main content

grid-pathfinding

High-performance 3D grid pathfinding with A* and HPA* algorithms.

Features

  • A* - Optimal pathfinding with heuristic search
  • HPA* (Hierarchical Pathfinding A*) - Fast pathfinding on large grids
  • Dynamic Replanning - Handle temporary obstacles during path execution
  • Custom Heuristics - Manhattan, Euclidean, or create your own
  • Movement Patterns - 6-directional (3D) or custom patterns
  • Cost Functions - Support for terrain costs, congestion, etc.
  • Path Caching - LRU cache with automatic invalidation
  • Pure Python - No external dependencies (NumPy optional for dense storage)

Installation

pip install grid-pathfinding

Or with uv:

uv pip install grid-pathfinding

Quick Start

from grid_pathfinding import Grid, find_path

# Create a 10x10x1 grid
grid = Grid(10, 10, 1)

# Find a path from (0, 0, 0) to (9, 9, 0)
path = find_path(grid, (0, 0, 0), (9, 9, 0))

# Iterate over waypoints
for pos in path:
    print(pos)

# Get path statistics
print(f"Cost: {path.total_cost}")
print(f"Time: {path.computation_time_ms}ms")
print(f"Nodes explored: {path.nodes_explored}")

Examples

With Obstacles

from grid_pathfinding import Grid, find_path

grid = Grid(20, 20, 1)

# Add some obstacles
for x in range(5, 15):
    grid.set_obstacle(x, 10, 0)

path = find_path(grid, (0, 10, 0), (19, 10, 0))
# Path navigates around the wall

Using HPA* for Large Grids

from grid_pathfinding import Grid, find_path

# Large grid - HPA* is faster
grid = Grid(200, 200, 10)

path = find_path(grid, (0, 0, 0), (199, 199, 9), algorithm="hpastar")

Dynamic Replanning

from grid_pathfinding import Grid, find_path
from grid_pathfinding.algorithms import DynamicReplanner, ReplanStrategy

grid = Grid(50, 50, 1)
replanner = DynamicReplanner(strategy=ReplanStrategy.REPAIR)

# Get initial path
path = find_path(grid, (0, 0, 0), (49, 49, 0))

# New obstacle appears during execution
grid.set_obstacle(25, 25, 0, True)

# Replan from current position
new_path = replanner.replan(grid, path, (24, 25, 0))

With Path Caching

from grid_pathfinding import Grid, find_path
from grid_pathfinding.cache import PathCache

grid = Grid(100, 100, 10)
cache = PathCache(max_size=100)

# First call computes the path
path1 = cache.get_or_compute(grid, (0, 0, 0), (99, 99, 9))

# Second call returns cached result (much faster)
path2 = cache.get_or_compute(grid, (0, 0, 0), (99, 99, 9))

print(cache.stats)
# {'hits': 1, 'misses': 1, 'evictions': 0, 'size': 1, 'hit_rate': 0.5}

API Reference

Core Classes

Grid

grid = Grid(width, height, depth, storage_type=StorageType.SPARSE)
  • is_obstacle(x, y, z) - Check if a cell is blocked
  • set_obstacle(x, y, z, is_obstacle=True) - Set obstacle state
  • get_cost(x, y, z) - Get movement cost for a cell
  • set_cost(x, y, z, cost) - Set movement cost
  • memory_usage - Property: memory used in bytes

Path

# Result from find_path()
path.waypoints        # List of (x, y, z) tuples
path.total_cost       # Total path cost
path.computation_time_ms  # Time to find path (ms)
path.nodes_explored  # Nodes searched

# Path operations
len(path)            # Number of waypoints
for pos in path: ... # Iterate waypoints
path.compress()      # Remove collinear waypoints
path.segments()      # Get as list of segments

Algorithms

AStar

from grid_pathfinding import AStar, ManhattanDistance, Cardinal3D

algo = AStar(
    heuristic=ManhattanDistance(),
    movement=Cardinal3D()
)
path = algo.find_path(grid, start, goal)

HPAStar

from grid_pathfinding import HPAStar

algo = HPAStar(cluster_size=(10, 10, 2))
path = algo.find_path(grid, start, goal)

Heuristics

  • ManhattanDistance(use_3d=True) - L1 distance (6-dir movement)
  • EuclideanDistance(use_3d=True) - L2 distance (26-dir movement)

Movement Patterns

  • Cardinal3D - 6 directions (±X, ±Y, ±Z)

Performance

Benchmarks on typical hardware:

Grid Size Algorithm Time Memory
100×100×10 A* ~1.5ms <1MB
200×200×10 HPA* ~2-3ms <2MB

Requirements

  • Python 3.9+
  • No external dependencies for sparse grids
  • NumPy (optional) for dense grid storage

Development

# Install dev dependencies
uv pip install -e ".[dev]"

# Run tests
uv run pytest

# Run tests with coverage
uv run pytest --cov=grid_pathfinding

# Run benchmarks
uv run pytest --benchmark-only

License

MIT

Metadata

Release files for wareflow-grid-pathfinding 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wareflow-grid-pathfinding 0.1.0
File Size Uploaded
wareflow_grid_pathfinding-0.1.0.tar.gz 95.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wareflow-grid-pathfinding 0.1.0
File Interpreter ABI Platform
wareflow_grid_pathfinding-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 122.2 kB

Release files / wareflow_grid_pathfinding-0.1.0.tar.gz

Download URL wareflow_grid_pathfinding-0.1.0.tar.gz
Size 95.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7c3f122fac625948f00fc6bea472836f7ed5e9d575df6d20edac3cad792b7652
BLAKE2b-256 checksum
How to use checksums
d6c556321f3a7754dd889d1db0d68810d191d150bd8a47af15d86ae563ff3a2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / wareflow_grid_pathfinding-0.1.0-py3-none-any.whl

Download URL wareflow_grid_pathfinding-0.1.0-py3-none-any.whl
Size 26.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a521d8c07719e87d7dec5ea0097636208f0aca838fad9355b1f866a8531b8497
BLAKE2b-256 checksum
How to use checksums
3f48fd30f50280387488f2a15853186b93cd105e138a10ef9a76371eacd9c40a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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