Skip to main content

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.

Release files for clean-architecture-linter-plugin 1.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for clean-architecture-linter-plugin 1.2.2
File Size Uploaded
clean_architecture_linter_plugin-1.2.2.tar.gz 27.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for clean-architecture-linter-plugin 1.2.2
File Interpreter ABI Platform
clean_architecture_linter_plugin-1.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 59.7 kB

Release files / clean_architecture_linter_plugin-1.2.2.tar.gz

Download URL clean_architecture_linter_plugin-1.2.2.tar.gz
Size 27.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b5254b28b280ff8d93d2d199e32f07246eb3616f44a8e279e434c976af6d9058
BLAKE2b-256 checksum
How to use checksums
0dc5e8467be4b146adc430ccd92956cc65016ec0c05a9a632bac51dade41b6ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Jan 12, 2026.

Transparency log

Release files / clean_architecture_linter_plugin-1.2.2-py3-none-any.whl

Download URL clean_architecture_linter_plugin-1.2.2-py3-none-any.whl
Size 31.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1f17b7811b266c53280d85c1de139915d1143fedfc366808dd7275625b7a7e01
BLAKE2b-256 checksum
How to use checksums
52b689246dec1248300abdad504b7d0d25d9d865e2a34d8ee9f93574c9c282a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Jan 12, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.2.2 This release

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.2

2 release files

1.1.1

2 release files

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