Skip to main content

A Pylint plugin for enforcing Clean Architecture principles and Design Patterns.

Project description

pylint-clean-architecture

Clean Architecture Linter Logo

A powerful, highly-opinionated Pylint plugin for enforcing Clean Architecture (The Onion Architecture) principles in Python projects.

This linter acts as a "GPS" for your codebase, preventing technical debt by strictly enforcing architectural boundaries, dependency rules, and design patterns.

Features

  • Layer Boundary Enforcement: Prevents inner layers (Domain, UseCase) from importing outer layers (Infrastructure, Interface).
  • Dependency Injection Checks: Forbids direct instantiation of infrastructure classes in UseCases.
  • Design Pattern Enforcement: Detects "naked returns" from repositories, delegation anti-patterns, and more.
  • Law of Demeter: Enforces loose coupling by flagging deep method chains.
  • Contract Integrity: Ensures Infrastructure classes correctly implement Domain Protocols.
  • Anti-Bypass Guard: Prevents "lazy" disabling of linter rules without justification.

Installation

pip install pylint-clean-architecture

Usage

Add the plugin to your pyproject.toml or Pylint configuration:

[tool.pylint.main]
load-plugins = ["clean_architecture_linter"]

Run Pylint as usual:

pylint src/

AI Coding Assistant Support

The clean-arch-init command generates architectural instructions for AI agents (like Cursor or GitHub Copilot) to prevent "Split Brain" issues by teaching the AI your project's rules before it writes code.

Usage:

clean-arch-init

Outcome: This creates a customized .agent/instructions.md file based on the layer names defined in the project's pyproject.toml.

Configuration

The linter is configured via [tool.clean-arch] in pyproject.toml.

[tool.clean-arch]
# 1. Project Type Presets (generic, cli_app, fastapi_sqlalchemy)
project_type = "generic"

# 2. Strict Visibility Enforcement
visibility_enforcement = true

# 3. Custom Layer Mapping (Map directory regex patterns to layers)
[tool.clean-arch.layer_map]
"services" = "UseCase"
"infrastructure/clients" = "Infrastructure"
"domain/models" = "Domain"

Rules

See RULES.md for a complete catalog of enforced rules and "Clean Fix" examples.

Contributing

  1. Fork the repo.
  2. Install dependencies: make install.
  3. Run tests: make test.
  4. Submit a PR.

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

clean_architecture_linter_plugin-1.2.2.tar.gz (27.8 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file clean_architecture_linter_plugin-1.2.2.tar.gz.

File metadata

File hashes

Hashes for clean_architecture_linter_plugin-1.2.2.tar.gz
Algorithm Hash digest
SHA256 b5254b28b280ff8d93d2d199e32f07246eb3616f44a8e279e434c976af6d9058
MD5 153d8f0e6dadb4411fca1b4c23bb0df4
BLAKE2b-256 0dc5e8467be4b146adc430ccd92956cc65016ec0c05a9a632bac51dade41b6ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for clean_architecture_linter_plugin-1.2.2.tar.gz:

Publisher: publish.yml on noah-goodrich/pylint-clean-architecture

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file clean_architecture_linter_plugin-1.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for clean_architecture_linter_plugin-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1f17b7811b266c53280d85c1de139915d1143fedfc366808dd7275625b7a7e01
MD5 a50e0f4b34359e876b7e5f8110873631
BLAKE2b-256 52b689246dec1248300abdad504b7d0d25d9d865e2a34d8ee9f93574c9c282a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for clean_architecture_linter_plugin-1.2.2-py3-none-any.whl:

Publisher: publish.yml on noah-goodrich/pylint-clean-architecture

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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