Skip to main content

Architecture validation library for Python projects

Project description

PyArchRules Logo

License: MIT Python 3.12+ Status: Beta Documentation

PyArchRules

Architecture linter for Python.

Define your project's folder structure and import rules in pyproject.toml (or in Python) and enforce them in CI or from your test suite.

📚 Full documentation

Key features

  • Folder structure validation.
  • Directional dependency rules between modules.
  • Isolation between services and layers.
  • Circular import detection.

Quick start

1. Install

pip install pyarchrules

2. Define your rules

Option A — pyproject.toml (recommended)

# pyproject.toml
[tool.pyarchrules.services.backend]
path = "src/backend"

# Required folder structure
tree      = ["api", "domain", "infra"]
tree_mode = "strict"                       # exists / strict / exact

# Allowed import directions
dependencies = [
    "api -> domain",
    "domain -> infra",
]

# Prevent circular imports
no_circular_imports = true

Run it:

pyarchrules check

Option B — Python DSL (great for tests)

# tests/test_architecture.py
from pyarchrules import PyArchRules


def test_backend_architecture():
    rules = PyArchRules()
    (
        rules.for_service("backend")
             .tree_structure(["api", "domain", "infra"], mode="strict")
             .dependencies(["api -> domain", "domain -> infra"])
             .no_circular_imports()
    )
    rules.validate()

Run it:

pytest tests/test_architecture.py

Next steps

  • Configuration — full [tool.pyarchrules] reference.
  • Python DSL — every rule available as a fluent method.
  • Use Cases — monorepo and Clean Architecture patterns.

Contributing

See CONTRIBUTING.md.

License

MIT

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

pyarchrules-0.1.0b2.tar.gz (37.0 kB view details)

Uploaded Source

Built Distribution

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

pyarchrules-0.1.0b2-py3-none-any.whl (47.6 kB view details)

Uploaded Python 3

File details

Details for the file pyarchrules-0.1.0b2.tar.gz.

File metadata

  • Download URL: pyarchrules-0.1.0b2.tar.gz
  • Upload date:
  • Size: 37.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pyarchrules-0.1.0b2.tar.gz
Algorithm Hash digest
SHA256 580f62c1abf6655d91a96cf53e57d6ebf4728ba7c3829a84952fa0f71833f38c
MD5 bcb05c03c0973c4f5e16184a86d66b2e
BLAKE2b-256 b7c604fa7459a1644eb5576a5d055604e785b6b1c032c5c550676817bab2afa6

See more details on using hashes here.

File details

Details for the file pyarchrules-0.1.0b2-py3-none-any.whl.

File metadata

  • Download URL: pyarchrules-0.1.0b2-py3-none-any.whl
  • Upload date:
  • Size: 47.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pyarchrules-0.1.0b2-py3-none-any.whl
Algorithm Hash digest
SHA256 7cf5565213b1d8973786ba924dbc2799ccdf8f60418f07f58424cad2f94cc06c
MD5 3f35fe114788f07e46304d122a7f4d21
BLAKE2b-256 8d6b11fd7e17a31950b9e286cfebe5a1764f237712e43c358a0b4337afbdcd3f

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