skillfed

PyTestArch

Test framework for software architecture based on imports between modules

pytestarch v4.0.1 219.6K downloads/30d#9,323 on PyPI170
Permissive license Apache-2.0 Active released

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 pytestarch

uv

uv add pytestarch

poetry

poetry add pytestarch

Installing 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

Intended Audience :: DevelopersLicense :: OSI Approved :: Apache Software LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.9Topic :: Software Development :: TestingTopic :: Software Development :: Testing :: Unit

Tags

architecture testing frameworkmodule dependency rulesimport constraint validationcode architecture verificationpytest architecture rulesdependency graph testingmodule import policies
architecture-testingimport-validationpytest-plugin

More Testing packages