Skip to main content

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

Project description

PyPI version Python 3.11+ License: MIT CI

archetype-py logo

archetype-py

Enforce architectural boundaries in Python before they become technical debt.

archetype-py lets teams define architecture rules like:

  • “API must not depend on infrastructure”
  • “No cycles between services”
  • “Only repositories can access the database”

…and automatically enforce them in CI, locally, and in pytest.


Why Developers Use archetype-py

Most Python tooling checks:

  • formatting
  • typing
  • linting
  • correctness

But almost nothing protects system structure.

As projects grow, architecture drifts silently:

  • layers start leaking
  • imports become tangled
  • boundaries disappear
  • coupling spreads

archetype-py turns architectural intent into executable checks.


See It In Action

Define architecture 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()

Run checks

archetype check .

Get actionable feedback

✖ API cannot depend on DB internals

app.api.users
└── imports app.db.internal.session

Quick Start

1. Install

pip install archetype-py

2. Generate a starter architecture file

archetype init .

3. Define your rules

Edit:

architecture.py

4. Run checks

archetype check .

5. Add to CI

- run: archetype check .

Done.


Features

Architecture Rules

  • Forbidden imports
  • Allowlisted imports
  • Layer enforcement
  • Import cycle detection
  • Protected module boundaries

Workflow Features

  • Rule grouping
  • Warning-level rules
  • Temporary rule skips with context
  • Changed-file enforcement (since)
  • Pytest integration
  • CI-friendly exit codes

Perfect For

  • Growing Python monoliths
  • Modular backends
  • Clean Architecture projects
  • Hexagonal Architecture
  • Domain-driven design
  • Teams scaling beyond “tribal knowledge”

Installation

pip install archetype-py

Requires Python 3.11+.


CI Integration

archetype-py is designed for automation.

Run it:

  • locally
  • in pre-commit
  • in GitHub Actions
  • inside pytest
  • in your CI pipeline

Architecture checks become part of your delivery workflow.


Roadmap

Planned improvements include:

  • Graph visualization
  • Architecture diffing
  • IDE integrations
  • Rich HTML reports
  • More built-in rule primitives

Contributing

Contributions are welcome:

  • bug fixes
  • rule ideas
  • docs improvements
  • integrations
  • performance work

See CONTRIBUTING.md.


Support The Project

If archetype-py helps your team:

⭐ Star the repository
🐛 Open issues
🧠 Share feedback
🔧 Contribute improvements

Every star genuinely helps the project grow.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

archetype_py-0.2.2.tar.gz (2.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

archetype_py-0.2.2-py3-none-any.whl (26.1 kB view details)

Uploaded Python 3

File details

Details for the file archetype_py-0.2.2.tar.gz.

File metadata

  • Download URL: archetype_py-0.2.2.tar.gz
  • Upload date:
  • Size: 2.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for archetype_py-0.2.2.tar.gz
Algorithm Hash digest
SHA256 6b9cbbca5d2ff653346c47aa546aa579d2077cdda353904435a6f1895fdf95a3
MD5 cfdd2600866d82da7466b22a73ad4053
BLAKE2b-256 f19e9911c55313f319739b8258f41cd56c5dc860337924266904f06e247354d0

See more details on using hashes here.

File details

Details for the file archetype_py-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: archetype_py-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 26.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for archetype_py-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f6b5de7430366f679e98b688d4967963eb58b0056e644e6a40632f96e22bd211
MD5 059b51961194c6cd3f3065711168c05d
BLAKE2b-256 86b3090335aab625577759a99e871636cacb2b5a0cc4345344143f0f8bd78491

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page