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.1.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.1-py3-none-any.whl (26.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: archetype_py-0.2.1.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.1.tar.gz
Algorithm Hash digest
SHA256 9d5fd7b547377dafd4231818cc6d20007a1441a723a42caf3758ee8c95646073
MD5 7bd85e047927bc283d166730ec8bafa4
BLAKE2b-256 f6f7ac5522fb2c89cb9458b6861e2283be5b692ef80af3c5fc954b684d952d45

See more details on using hashes here.

File details

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

File metadata

  • Download URL: archetype_py-0.2.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 86c3212cfb84dc9ed7452eedef89055fe7b1e05d53faf6ece431a62895993447
MD5 91a10fe95b88c4ba1c4be58049a6d784
BLAKE2b-256 62dddb5af2540de9d5666fdd38a343f953e6027f5b960352184cf042597d0c3f

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