pytest-archon
Rule your architecture like a real developer
What it is and what it does
Pytest-archon is a pytest plugin that lets you write tests to enforce architectural rules in your Python codebase. Instead of relying on informal conventions, you define explicit boundaries—specifying which modules can import from which others—and verify them as part of your test suite. It catches circular dependencies, prevents unintended coupling, and makes your project structure explicit for new team members.
You write rules using a fluent API that matches module patterns (via fnmatch or regex), excludes specific modules, and specifies allowed or forbidden imports. The check method can inspect toplevel imports only, skip TYPE_CHECKING blocks, or include transitive dependencies, giving you fine-grained control over what gets validated. Rules are tied directly to your codebase, so they stay in sync with actual application structure.
Use it for:
- Enforce that a domain model layer has no dependencies on other submodules, keeping it reusable and decoupled.
- Verify that utility or common modules are actually used by multiple parts of the codebase, preventing dead code.
- Prevent circular imports between major architectural layers (e.g., controllers cannot import from views).
- Document and test the intended module hierarchy for new team members through executable rules.
- Catch unintended coupling between components during development before it becomes entrenched.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Pytest-archon lets you define and test architectural boundaries in Python projects by specifying which modules can import from which others, catching circular dependencies and enforcing structure through test rules.
Yes, if you want to enforce architectural boundaries in a growing Python project. The low install friction, permissive license, and stable API make it straightforward to adopt. The aging maintenance status (329 days since last release) is a minor concern but not a blocker—the repository is active and the package is marked Production/Stable. Use it when you need testable, explicit rules about module dependencies rather than informal conventions.
Install
pytest-archon on PyPI
pip
pip install pytest-archonuv
uv add pytest-archonpoetry
poetry add pytest-archonInstalling pytest-archon
Before you install
Low friction install with a single runtime dependency on pytest. Maintenance status is aging—last release was 329 days ago—but the repository is active and not archived, with a stable development status classifier.
License in practice
Licensed under Apache Software License (permissive), so you can use, modify, and distribute it freely in commercial and private projects with minimal restrictions.
Quickstart
pip install pytest-archon
from pytest_archon import archrule
def test_rule_basic():
(
archrule("name", comment="some comment")
.match("pytest_archon.col*")
.exclude("pytest_archon.colgate")
.should_not_import("pytest_archon.import_finder")
.should_import("pytest_archon.core*")
.check("pytest_archon")
)
Requires Python 3.8 or later; pytest must be installed.
Verify before relying
- Whether the aging maintenance status (329 days since last release) affects stability or security for new Python versions.
- Performance characteristics when checking large codebases or deeply nested dependency graphs.
Package facts
| License | Apache Software License (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — pytest |
| Maintenance | aging — 329 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 83,877/month — #14,043 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_archon-0.0.7-py3-none-any.whl
Tags
More Quality Assurance packages
Coverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
ruffRuff is a Python linter and code formatter…
permissive · top 1,000 on PyPI
pexpectPexpect spawns and controls interactive console…
permissive · top 1,000 on PyPI
blackBlack reformats Python source code to a…
permissive · top 1,000 on PyPI
pytest-xdistpytest-xdist distributes pytest tests across…
permissive · top 1,000 on PyPI
cfn-lintValidates AWS CloudFormation templates in YAML…
permissive · top 1,000 on PyPI
PyTestArchPyTestArch lets you define and test…
permissive · top 15,000 on PyPI
tachTach enforces module boundaries, dependency…
permissive · top 5,000 on PyPI
import-linterImport Linter enforces architectural…
permissive · top 5,000 on PyPI
import-depsAnalyzes Python module imports statically using…
permissive · top 5,000 on PyPI
omnibase_spiDefines runtime-checkable Protocol contracts…
permissive · top 15,000 on PyPI
pytest-isortA pytest plugin that automatically checks…
permissive · top 15,000 on PyPI
coverage-conditional-pluginA coverage.py plugin that applies conditional…
permissive · top 15,000 on PyPI
rulesrules provides object-level permission checking…
permissive · top 15,000 on PyPI
mo-importsProvides patterns to resolve circular module…
copyleft · top 15,000 on PyPI
uncalledDetects unused functions in Python projects…
permissive · top 15,000 on PyPI