A Python toolkit to help developers write professional-grade, maintainable, and clean code following clean code principles.
pycleancode is a professional-grade Python toolkit that helps developers write clean, maintainable, and scalable code following clean code principles.
Build multiple code quality tools under a single unified package architecture.
Unlike traditional linters that only focus on style violations, pycleancode implements advanced rule engines that target deeper structural and maintainability aspects of your code.
While tools like flake8, pylint, ruff, and black are excellent, most focus heavily on surface-level syntax or style violations.
pycleancode is different:
- π Designed for professional teams writing critical Python codebases.
- π€ Rule-based pluggable architecture to extend new structural checks.
- π AST-powered deep nesting detection.
- π‘ Focused on long-term maintainability.
- π¦ OSS-grade code architecture.
pycleancode 1.1.0 β "Output teams can use" β adds a unified pycleancode check CLI, JSON and Markdown reports, severity-aware exit codes for CI, and pyproject.toml configuration on top of the brace_linter module.
- Unified CLI β
pycleancode check <path>replacespycleancode-brace-linter(the old command still works and prints a deprecation notice; removal planned for 2.0). - Report formats β
--format text|json|markdownwith optional--output <file>. JSON carries a stableschemaVersion: 1for CI integrations; Markdown is ready to paste into a pull request. - Exit codes for CI β
0clean or warnings-only,1error violations,2usage/config/parse failure. Builds can finally fail on maintainability regressions. - Per-rule severity β set
severity: warningon a rule to report without failing the build, then tighten toerrorwhen the team is ready. - Layered configuration β
--config <path>β./pybrace.ymlβ[tool.pycleancode]inpyproject.tomlβ built-in defaults. Fresh installs run with zero setup.
The brace_linter module focuses on structural code depth and complexity. It analyzes Python code for excessive nesting and deeply nested functions that often make code harder to read, maintain, and extend.
-
Max Depth Rule
- Enforces maximum logical nesting depth.
- Helps prevent pyramid-of-doom structures.
-
Nested Function Rule
- Enforces maximum levels of nested function definitions.
- Prevents excessive local function scoping that can reduce readability.
-
Structural Reporting
- Full structural report of nesting tree.
- Emoji + ASCII visualization of code structure.
- Summary chart output for quick depth evaluation.
sandbox/test_sample.py:2: Nested functions depth 2 exceeds allowed 1
sandbox/test_sample.py:3: Depth 4 exceeds max 3
π Structural Report:
πΎ ROOT (Line 0, Depth 1)
β πΉ FunctionDef (Line 1, Depth 2)
β β πΉ FunctionDef (Line 2, Depth 3)
β β β πΉ FunctionDef (Line 3, Depth 4)- β Supported Python versions: 3.9, 3.10, 3.11, 3.12
- β Python 3.13+ is not yet supported (due to upstream Rust dependencies)
Install via PyPI:
pip install pycleancodeOr using Poetry:
poetry add pycleancodeRun directly via CLI:
pycleancode check path/to/your/code.py --reportGenerate machine-readable or review-friendly reports:
pycleancode check src --format json --output report.json
pycleancode check src --format markdown --output report.mdExit codes: 0 = clean or warnings-only Β· 1 = error-severity violations Β· 2 = usage/config/parse failure.
The legacy
pycleancode-brace-lintercommand still works with its original arguments and prints a deprecation notice. Migrate scripts topycleancode check.
Configuration is discovered in this order: --config <path> β ./pybrace.yml β [tool.pycleancode] in pyproject.toml β built-in defaults.
Via pybrace.yml:
rules:
max_depth:
enabled: true
max_depth: 3
nested_function:
enabled: true
max_nested: 1
severity: warning # report, but do not fail the buildOr via pyproject.toml:
[tool.pycleancode.rules.max_depth]
enabled = true
max_depth = 3
[tool.pycleancode.rules.nested_function]
enabled = true
max_nested = 1
severity = "warning"Each rule accepts enabled, its thresholds, and an optional severity (error by default, warning to report without failing CI).
git clone git@github.com:YOUR_USERNAME/pycleancode.git
cd pycleancode
poetry install
pre-commit installRun full tests:
poetry run pytest --cov=pycleancode --cov-report=term-missingRun pre-commit:
poetry run pre-commit run --all-files| Module / Feature | Description | Status |
|---|---|---|
brace_linter |
Structural depth analysis (nesting, functions) | β Completed |
| Team-usable output | JSON/Markdown reports, exit codes, pyproject config | β v1.1.0 |
| Regression diff mode | diff --base main: fail CI only on regressions |
β³ Planned (v1.2) |
| Baseline & ratchet | Adopt on legacy codebases without fixing old debt | β³ Planned (v1.3) |
| GitHub Action | PR comments, status checks, annotations | β³ Planned (v1.4) |
| Full documentation site | OSS-grade docs & API reference | β Live |
Released under the MIT License. See LICENSE.
Please see our CODE_OF_CONDUCT.md
We welcome OSS contributions. Please read our full CONTRIBUTING.md to get started!
- Clean Code Principles
- 100% Test Coverage Required
- Pre-commit Hooks Required
- Conventional Commits Required
- GitHub Discussions (coming soon)
- Issues and PRs welcomed
- PyPI release v1.1.0 adds team-usable output: reports, exit codes, and pyproject configuration
π Pycleancode: Clean Code. Professional Quality. OSS-Grade Python. Unified Modular Clean Code Toolkit.

