Nox
Nox is a command-line tool that automates development tasks like testing and linting across multiple Python environments. It utilizes a standard Python file (`noxfile.py`) for configuration, creating isolated virtual environments for each defined session. This approach provides programmatic control and reproducibility, installing specified dependencies and running commands within each isolated environment. As of version 2026.2.9, Nox is actively maintained with a regular release cadence, often following a calendar versioning scheme.
Warnings
- breaking The library's package name changed from `nox-automation` to `nox`, and the configuration file from `nox.py` to `noxfile.py`. Support for Python 2.7 was dropped, and session actions shifted from declarative to imperative.
- gotcha Nox is designed to be installed globally (or via `pipx`) in your system's Python environment, *not* within a project's virtual environment. It manages its own isolated virtual environments for each session it runs.
- gotcha Each Nox session runs in a freshly created, isolated virtual environment. Any dependencies required for a session's commands (e.g., `pytest`, `flake8`) must be explicitly installed within that session using `session.install()`.
- breaking When using `uv` as a backend, `uv` version 0.10.0 and later now require the `--clear` flag to clear an environment.
Install
-
pip install nox -
pipx install nox
Imports
- nox
import nox
- session
@nox.session
- Session
def my_session(session: nox.Session):
Quickstart
# noxfile.py
import nox
@nox.session(python=["3.9", "3.10", "3.11"])
def tests(session):
"""Run the test suite with pytest."""
session.install("pytest")
session.run("pytest", "tests/")
@nox.session
def lint(session):
"""Lint source code with Flake8 and Black."""
session.install("flake8", "black")
session.run("flake8", "src/", "tests/", "noxfile.py")
session.run("black", "--check", "src/", "tests/", "noxfile.py")
# To run these sessions, save the above as noxfile.py in your project root
# and execute 'nox' in your terminal. For specific sessions, use 'nox -s tests' or 'nox -s lint'.
# To run multiple Python versions, nox will create virtualenvs for each specified version.
# Make sure you have python3.9, python3.10, python3.11 interpreters available on your PATH.