Cycle and internal-dependency rules
Architecture testing for Python
ArchUnitPython
Turn imports and source structure into rules that run beside pytest or unittest. ArchUnitPython checks boundaries, cycles, layers, external dependencies, code metrics, and architecture diagrams without becoming a production dependency.
PyPI
pip install archunitpythonfrom archunitpython import project_files, assert_passes
def test_domain_stays_independent():
rule = (
project_files('src/')
.in_folder('**/domain/**')
.should_not()
.depend_on_files()
.in_folder('**/infrastructure/**')
)
assert_passes(rule)Capabilities
What ArchUnitPython brings to the test suite.
The family shares a recognizable architecture vocabulary while each implementation stays honest about its language, toolchain, and maturity.
Named layers and forbidden external imports
Counting, cohesion, and distance metrics
pytest, unittest, and framework-neutral checks
Ignore files and JSON-configured common rules
Dependency graph snapshots and exports
Current maturity
Production ready
Published on PyPI, designed with zero runtime dependencies, and compatible with ordinary Python testing workflows.
Where it fits
Put boundaries next to the code they protect.
Common starting points for ArchUnitPython include the following project shapes.
More ecosystems
The same intent, expressed natively.
Explore sibling implementations and carry the architecture vocabulary across a polyglot system.
Make the first boundary executable.
Add one meaningful rule, run it with the existing tests, and grow the architecture suite as the system reveals where it needs protection.
Start with ArchUnitPython ↗
