hatch
hatch is a Python project management tool maintained by the Python Packaging Authority (PyPA). It combines virtual environment management, dependency handling, project scaffolding, and publishing capabilities in a unified interface that follows Python packaging standards. Its build backend, hatchling, is one of the most widely used on PyPI.
Note
uv covers much of the same ground — project management, environment creation, script running — with faster performance. Hatch differentiates through its environment matrix system and official PyPA backing.
Core Functionality
- Project Creation: Scaffolds new Python projects with standardized structure
- Environment Management: Creates and controls isolated virtual environments
- Build Backend: Provides a compliant PEP 517 build backend (hatchling)
- Version Management: Handles version bumping and release tracking
- Script Execution: Runs commands in project environments
Configuration
Hatch projects use pyproject.toml with hatchling as the build backend:
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "my-package"
version = "0.1.0"
dependencies = ["requests"]Command Examples
# Create a new project
hatch new my-project
# Run a command in project environment
hatch run pytest
# Build distribution packages
hatch build
# Publish to PyPI
hatch publish
# Create a specific environment
hatch env create docsEnvironment Matrix
Hatch’s environment matrix system is its primary differentiator. It allows defining a single environment that expands across multiple Python versions or dependency sets. For example, to run tests across several Python versions:
[tool.hatch.envs.test]
dependencies = ["pytest"]
[[tool.hatch.envs.test.matrix]]
python = ["3.10", "3.11", "3.12"]Running hatch run test:pytest then executes the test suite in each Python version defined in the matrix. This provides tox-like multi-version testing without a separate tool.
Advantages
- Full support for modern Python packaging standards (PEP 517, PEP 621)
- Handles the complete project lifecycle from scaffolding to publishing
- Environment matrix system enables multi-version testing without extra tools
- Plugin system allows extending functionality for custom workflows
Limitations
- More complex than single-purpose tools, with a steeper learning curve
- No built-in lockfile generation
Learn More
- Hatch Documentation
- GitHub Repository
- Example Hatch Package
- pyproject.toml — the configuration file hatch uses
- setuptools — the traditional build backend for comparison
Also Mentioned In
- uv 0.8 Release: Automatic Python Installation to PATH
- The uv build backend is now stable
- Why uv makes Make less essential for Python projects
- build
- How to write self-contained Python scripts using PEP 723 inline metadata
- pyproject.toml
- setuptools
- Twine
- What is a build backend?
- What is a build frontend?
- What is a Python package?
- What is PEP 621 compatibility?
- What is PEP 660?
- Wheel
- Why are there so many Python packaging tools?
- Why does uv Use Hatch as a backend?
- Why Should I Choose pyproject.toml over requirements.txt for managing dependencies?
- Why You Should Try uv if You Use Python