PyTestArch
Test framework for software architecture based on imports between modules
What it is and what it does
PyTestArch is a testing framework that lets you codify architectural rules for Python projects and verify that your codebase respects them. It scans your source code to build a dependency graph, then lets you write rules declaratively (e.g., "module B should never be imported by module A") and assert those rules hold. It's inspired by ArchUnit and integrates naturally with pytest.
The package depends only on networkx for graph operations and optionally matplotlib for visualization. It supports Python 3.9 through 3.13 and has been actively maintained since its initial release in 2022, with a recent update in August 2025.
Use it for:
- Enforce layered architecture by preventing lower layers from importing upper layers in a multi-tier application.
- Prevent circular dependencies between modules by defining rules that catch them during test runs.
- Document and validate that certain modules remain isolated (e.g., internal utilities not imported by external code).
- Catch accidental cross-team dependencies in large codebases by defining import policies per module group.
- Integrate architecture checks into CI/CD pipelines as part of your test suite alongside unit and integration tests.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
PyTestArch lets you define and test architectural rules for Python code by analyzing module imports and dependencies, catching violations where modules import from places they shouldn't.
Yes. PyTestArch is actively maintained, has no known vulnerabilities, installs with minimal friction, and solves a real problem—catching architectural violations early. It's well-suited for teams that want to enforce module-level design constraints. The permissive Apache-2.0 license poses no barrier. Start with the basic rule DSL shown in the docs; optional visualization requires matplotlib.
Install
pytestarch on PyPI
pip
pip install pytestarchuv
uv add pytestarchpoetry
poetry add pytestarchInstalling PyTestArch
Before you install
Low friction install with a single runtime dependency (networkx). Active maintenance with recent commits and a stable release cadence; last release was 371 days ago and the repository remains actively developed.
License in practice
Licensed under Apache-2.0 (permissive), so you can use it freely in commercial and private projects with minimal restrictions.
Quickstart
from pytestarch import get_evaluable_architecture, Rule
evaluable = get_evaluable_architecture("/path/to/project", "/path/to/project/src")
rule = Rule().modules_that().are_named("project.src.moduleB").should_not().be_imported_by_modules_that().are_sub_modules_of("project.src.moduleA")
rule.assert_applies(evaluable)
Requires Python 3.9 or later; matplotlib is optional but needed only if you want to visualize dependency graphs.
Verify before relying
- Whether the package handles large codebases efficiently or has known performance limits.
- Whether visualization output (with matplotlib) is publication-ready or primarily for debugging.
- How well the rule DSL scales for complex architectural policies across many modules.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — networkx |
| Maintenance | actively maintained — 371 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 219,634/month — #9,323 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytestarch-4.0.1-py3-none-any.whl
Keywords: architecture, test
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
import-linterImport Linter enforces architectural…
permissive · top 5,000 on PyPI
pytest-archonPytest-archon lets you define and test…
permissive · top 15,000 on PyPI
pytest-beartype-testsA pytest plugin that automatically applies…
permissive · top 15,000 on PyPI
pymarkdownlntPyMarkdown is a GitHub Flavored Markdown linter…
permissive · top 5,000 on PyPI
tachTach enforces module boundaries, dependency…
permissive · top 5,000 on PyPI
pytest-isortA pytest plugin that automatically checks…
permissive · top 15,000 on PyPI
plyaraParses YARA rule files into Python dictionary…
permissive · top 15,000 on PyPI
pytest-blackA pytest plugin that runs black format checks…
permissive · top 15,000 on PyPI
j2lintj2lint validates Jinja2 template syntax and…
permissive · top 15,000 on PyPI