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 . --infer
archetype check .

init --infer reads your import graph and writes rules that already pass: layers, independent packages, protected internals, and cycle checks. Existing problems are added as warnings, so the first run is green and later runs catch new drift.

Or write rules yourself in architecture.py:

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()
  • Sibling package independence with independent([...])
  • 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 --infer generates passing rules from the existing import graph; archetype init scaffolds a starter file
  • 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.6.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.6.0
File Size Uploaded Provenance Actions
archetype_py-0.6.0.tar.gz 7.6 MB With provenance Details for archetype_py-0.6.0.tar.gz

Built distribution (wheel)

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

Total release size: 7.7 MB

Release files / archetype_py-0.6.0.tar.gz

Download URL archetype_py-0.6.0.tar.gz
Size 7.6 MB
Tags Source
SHA-256 checksum
How to use checksums
9c58df2653a178ef605c491baef8fcc47a148a6a3efd464fb1c3a6b05c72df9e
BLAKE2b-256 checksum
How to use checksums
f3717748f8ec0da10636f80dae54e4e1e60fc40236bc0bdf220bed52efb22f38
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 Oct 23, 2026.

Transparency log

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

Download URL archetype_py-0.6.0-py3-none-any.whl
Size 71.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b5bf6848a492417c01cb3437e67b8bdccc3c681bdf36280c125fe86d4fb87afa
BLAKE2b-256 checksum
How to use checksums
0401dc9673ead37defc4f2553f385fb8778742b53f65c9e271640d821470f022
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 Oct 23, 2026.

Transparency log

Security for archetype-py 0.6.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 archetype_py-0.6.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 Oct 23, 2026.

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.

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