A Python package for generating and visualizing mazes
Project description
Mazewright
A Python package for generating and visualizing perfect mazes using various algorithms.
Features
- Multiple algorithms: Recursive Backtracker, Prim's, and Kruskal's algorithms
- Clean API: Simple, intuitive interface for maze generation
- Visualization: Built-in matplotlib rendering with customizable styling
- CLI tool: Generate mazes from the command line
- Type hints: Full type annotations for better IDE support
- Well-tested: Comprehensive test suite ensuring perfect maze generation
Installation
pip install -e .
For development:
pip install -e ".[dev]"
Quick Start (30 seconds)
Python API
from mazewright import generate
from mazewright.visualize import save
# Generate a 20x20 maze using Prim's algorithm
maze = generate(20, 20, algorithm="prim")
# Save to file
save(maze, "my_maze.png")
Command Line
# Generate a maze with default settings
python -m mazewright
# Customize size and algorithm
python -m mazewright --rows 30 --cols 30 --algo kruskal --out maze.png
# Fine-tune appearance
python -m mazewright --rows 15 --cols 20 --cell-size 25 --wall-width 3
API Reference
Core Functions
# Generate a maze
maze = generate(rows=10, cols=10, algorithm="backtracker")
# Available algorithms:
# - "backtracker": Recursive backtracker (DFS)
# - "prim": Prim's algorithm (frontier growth)
# - "kruskal": Kruskal's algorithm (union-find)
Maze Object
from mazewright import Maze, Wall
# Create empty maze
maze = Maze(rows=10, cols=10)
# Access cells
cell = maze[0, 0]
# Check walls
if cell.has_wall(Wall.NORTH):
print("Wall to the north")
# Carve passages manually
maze.carve(0, 0, 0, 1) # Connect (0,0) to (0,1)
Visualization
from mazewright.visualize import render, save
# Render to matplotlib figure
fig = render(maze, cell_size=1.0, wall_width=2.0)
# Save to file
save(maze, "output.png", cell_size=20, wall_width=2, dpi=100)
Example Output
Running python -m mazewright --rows 15 --cols 15 --algo prim generates mazes like:
Algorithms
Recursive Backtracker
- Produces long, winding passages
- Low branching factor
- Implemented as iterative DFS for efficiency
Prim's Algorithm
- More uniform branching
- Grows from a frontier of cells
- Good balance of corridors and branches
Kruskal's Algorithm
- Most uniform distribution
- Uses union-find data structure
- Treats maze as a graph problem
Development
Setup
# Install with dev dependencies
pip install -e ".[dev]"
# Install pre-commit hooks
pre-commit install
Testing
pytest
Code Quality
# Format code
black mazewright tests
# Lint
ruff check mazewright tests
Architecture
mazewright/
├── __init__.py # Public API
├── maze.py # Core data structures
├── visualize.py # Rendering engine
├── algorithms/
│ ├── backtracker.py # Recursive backtracker
│ ├── prim.py # Prim's algorithm
│ └── kruskal.py # Kruskal's with union-find
└── __main__.py # CLI entry point
Future Enhancements (v0.2+)
- Export formats: SVG, ASCII art
- Solver: Path-finding with visualization
- More algorithms: Wilson's, Aldous-Broder, Hunt-and-Kill
- Masks: Non-rectangular grids, shaped mazes
- Themes: Preset visual styles
- Animation: Step-by-step generation visualization
License
MIT
Version
v0.1.0 - Initial release with core functionality
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mazewright-0.1.0.tar.gz.
File metadata
- Download URL: mazewright-0.1.0.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c57e55c12f82fc3f446faeb78cf8e97a9e340b86d724fa35f21df481c528be4
|
|
| MD5 |
7c6cbd9b8bde7a7e4efe8d1a7fd4cd29
|
|
| BLAKE2b-256 |
6e5c9bd95aaf6c9239ec19f89a75de4b56aaad599e4eb546c4d766395d857638
|
Provenance
The following attestation bundles were made for mazewright-0.1.0.tar.gz:
Publisher:
publish.yml on sebastian-griego/Mazewright
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mazewright-0.1.0.tar.gz -
Subject digest:
9c57e55c12f82fc3f446faeb78cf8e97a9e340b86d724fa35f21df481c528be4 - Sigstore transparency entry: 453505555
- Sigstore integration time:
-
Permalink:
sebastian-griego/Mazewright@8ee1992a299b1d947ed5159ad0380e45fad6fe0b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/sebastian-griego
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8ee1992a299b1d947ed5159ad0380e45fad6fe0b -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file mazewright-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mazewright-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a73d0a5d50c540caa94b788ea9b4393338aa6d187b5d9efab9be8e7571cbfbe
|
|
| MD5 |
61ec8000fb8148920001f71fe28c1d54
|
|
| BLAKE2b-256 |
372e4dfecd2c8d78a6e533d60581934b27db7ac1263f2edd86dd22728f909623
|
Provenance
The following attestation bundles were made for mazewright-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on sebastian-griego/Mazewright
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mazewright-0.1.0-py3-none-any.whl -
Subject digest:
8a73d0a5d50c540caa94b788ea9b4393338aa6d187b5d9efab9be8e7571cbfbe - Sigstore transparency entry: 453505556
- Sigstore integration time:
-
Permalink:
sebastian-griego/Mazewright@8ee1992a299b1d947ed5159ad0380e45fad6fe0b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/sebastian-griego
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8ee1992a299b1d947ed5159ad0380e45fad6fe0b -
Trigger Event:
workflow_dispatch
-
Statement type: