--- id: pytestarch version: "4.0.1" license: Apache-2.0 license_treatment: permissive maintenance: active --- # PyTestArch — Test framework for software architecture based on imports between modules License: permissive · Maintenance: active · Downloads: 219.6K/mo ## 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 above — 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 pip install pytestarch uv add pytestarch 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_current - Install friction: low - Maintenance: active - Downloads: 219.6K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags architecture testing framework, module dependency rules, import constraint validation, code architecture verification, pytest architecture rules, dependency graph testing, module import policies, architecture-testing, import-validation, pytest-plugin [View on SkillFed](https://skillfed.io/packages/pytestarch) · [View on PyPI](https://pypi.org/project/pytestarch/)