Skip to main content

Welcome to PyTestArch

PyTestArch is an open source library that allows users to define architectural rules and test their code against them. It is generally inspired by ArchUnit.

Installation Guide

PyTestArch is available via PyPI and can be installed e.g. via pip: pip install pytestarch. To also install the optional dependency matplotlib, which is required to draw the created dependency graphs, install pytestarch[visualization]

Usage Guide

Three steps are required to test an architectural rule:

  1. Create an evaluable representation of the source code you want to test
from pytestarch import get_evaluable_architecture

evaluable = get_evaluable_architecture("/home/dummy/project", "/home/dummy/project/src")

This will scan all python files under /home/dummy/project/src for imports and build an internal representation that can later be queried. The first parameter /home/dummy/project helps PyTestArch to differentiate between internal and external dependencies. This evaluable can be used for multiple architectural rule checks; if you are using pytest, you could use a fixture for this evaluable object.

  1. Define an architectural rule
from pytestarch import Rule

rule = (
    Rule() 
    .modules_that() 
    .are_named("project.src.moduleB") 
    .should_not() 
    .be_imported_by_modules_that() 
    .are_sub_modules_of("project.src.moduleA") 
)

This rule represents the architectural requirements that a module named "project.src.moduleB" should not be imported by any module that is a submodule of "project.src.moduleA", excluding "project.src.moduleA" itself.

  1. Evaluate your code against this rule
rule.assert_applies(evaluable)

That's it!

Metadata

Release files for PyTestArch 4.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PyTestArch 4.0.0
File Size Uploaded Provenance Actions
pytestarch-4.0.0.tar.gz 42.7 kB With provenance Details for pytestarch-4.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for PyTestArch 4.0.0
File Interpreter ABI Platform Actions
pytestarch-4.0.0-py3-none-any.whl Python 3 none any Details for pytestarch-4.0.0-py3-none-any.whl

Total release size: 104.7 kB

Release files / pytestarch-4.0.0.tar.gz

Download URL pytestarch-4.0.0.tar.gz
Size 42.7 kB
Tags Source
SHA-256 checksum
How to use checksums
eb0cf9e105ec976374976cddc164c7eee8e2d5fcd4a97463d8534194c668a4a2
BLAKE2b-256 checksum
How to use checksums
b92879d7544f592d88faedd5a505ad85cfc768077f77eb84d96176f582243207
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 1, 2025.

Transparency log

Release files / pytestarch-4.0.0-py3-none-any.whl

Download URL pytestarch-4.0.0-py3-none-any.whl
Size 62.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e497c2e5e91ed933a389bab97ee52e66d45aab08bd42e0232ff208d5c18d6cc5
BLAKE2b-256 checksum
How to use checksums
ab89c39a7b9a76c0900a200561404c6ebcff8b73310a92e2facebed033dc330b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 1, 2025.

Transparency log

Security for PyTestArch 4.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pytestarch-4.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 1, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

4.0.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page