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.

Production readyPython projectsMIT

PyPI

pip install archunitpython
test_architecture.py
from 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.

01

Cycle and internal-dependency rules

02

Named layers and forbidden external imports

03

Counting, cohesion, and distance metrics

04

pytest, unittest, and framework-neutral checks

05

Ignore files and JSON-configured common rules

06

Dependency graph snapshots and exports

Current maturity

Production ready

Published on PyPI, designed with zero runtime dependencies, and compatible with ordinary Python testing workflows.

LanguagePython
ReleasePublished package
RuntimePython projects
LicenseMIT

Where it fits

Put boundaries next to the code they protect.

Common starting points for ArchUnitPython include the following project shapes.

Django boundariesFastAPI servicesData platformsRAG pipelines

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 ↗