Skip to main content

archetype-py

Enforce architectural rules as code. Catch structural violations before they merge.

GitHub Repository
Documentation

Why archetype-py

Most tooling checks formatting, typing, and tests, but not architecture drift.
archetype-py lets you codify structural boundaries and enforce them in local runs, CI, and pytest.

When to use / When not to use

Use archetype-py when:

  • You want architecture rules to run automatically in CI and pytest.
  • You need to prevent forbidden imports, layer violations, or import cycles.
  • You are adopting architecture checks incrementally in a legacy codebase (baseline mode).

Do not use archetype-py when:

  • You only need style/type checks (linters and type checkers are enough).
  • Your project is a very small script with no meaningful module boundaries.
  • You are looking for runtime policy enforcement instead of static import-graph checks.

Install

pip install archetype-py

Quick Start

archetype init .
archetype check .

Create an architecture.py file and define your rules:

from archetype import rule
from archetype.rules import layers

@rule("layers are ordered")
def layer_order() -> None:
    layers(["myapp.api", "myapp.services", "myapp.db"]).are_ordered()

Core Features

  • Architecture rules for forbidden imports, allowlisted imports, and protected boundaries
  • Transitive dependency checks with must_not_depend_on
  • Layer order enforcement with layers(...).are_ordered(), and strict no-skipping mode with .are_adjacent()
  • Import cycle detection with no_cycles(...)
  • Public API enforcement from a package's declared __all__ with public_api(...).enforce()
  • Import depth limits and fan-in/fan-out coupling thresholds with imports(...).max_depth(n), .fan_in_at_most(n), .fan_out_at_most(n)
  • Deprecated-module sunset warnings with deprecated(pattern, sunset=..., reason=...)
  • Rule decorators: @rule, @warn, @skip, @since
  • Rule grouping via group("...") and targeted execution with --group
  • archetype init scaffolding for starter architecture.py
  • JSON and text reporting (--format json|text) with stable JSON contract versioning
  • Quiet output mode (--quiet) for CI-friendly logs
  • Import graph caching for faster repeated runs (--cache, --no-cache)
  • Parallel execution control with --workers
  • Baseline adoption for legacy codebases (--write-baseline, --baseline)
  • Changed-files scope mode (--changed-from <git-ref>)
  • GitHub Actions inline PR annotations (--github-annotations)
  • Project diagnostics with archetype doctor
  • Import graph export with archetype graph --format mermaid|json
  • Unmatched pattern warnings with suggestions for likely misspellings
  • Path exclusions via CLI (--exclude) and config
  • Project config defaults through archetype.toml
  • Git pre-commit hook installer (archetype install-hook)
  • Project layout support for flat, src/, namespace packages (PEP 420), and monorepos
  • CLI command and pytest plugin support for local and CI enforcement

CI Example

- run: archetype check .

For full guides, examples, and release notes, use the GitHub README and changelog.

Metadata

Release files for archetype-py 0.5.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 archetype-py 0.5.0
File Size Uploaded
archetype_py-0.5.0.tar.gz 7.6 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for archetype-py 0.5.0
File Interpreter ABI Platform
archetype_py-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.7 MB

Release files / archetype_py-0.5.0.tar.gz

Download URL archetype_py-0.5.0.tar.gz
Size 7.6 MB
Tags Source
SHA-256 checksum
How to use checksums
3d839f64942fbcd83c8cafe8a44c9102c318445fcfd5f111e85a100f778218fc
BLAKE2b-256 checksum
How to use checksums
49da9385d7eae9389d40fc59f459745ddbd1fa4ec43a765332da217700d8daeb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 29, 2026.

Transparency log

Release files / archetype_py-0.5.0-py3-none-any.whl

Download URL archetype_py-0.5.0-py3-none-any.whl
Size 58.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
02c4a4ccf55433cb7f1330e3c8f9a3eb34d9b0ae0a7a554624161cc97811a965
BLAKE2b-256 checksum
How to use checksums
4e50d326d0b9685259dcaad8a06f4974fb66e49be7a3689fb2542c7054445e55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 29, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

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