Quick Reference
Tools
Ruff
Ruff is an extremely fast Python linter and formatter, replacing Black, isort, flake8, and more.Formatting
Formatting
Ruff formats code to a consistent style:Configuration in
pyproject.toml:Linting
Linting
Ruff checks for code quality issues:Enabled rule sets:
F- PyflakesE,W- pycodestyleI- isort (import sorting)N- pep8-namingUP- pyupgradeS- flake8-bandit (security)B- flake8-bugbearDJ- flake8-djangoPT- flake8-pytest-stylePL- PylintRUF- Ruff-specific rules
pyproject.toml for the full list.Per-File Ignores
Per-File Ignores
Some rules are disabled for specific files:
pyproject.toml
mypy
Static type checker for Python:Configuration
pyproject.toml
mypy uses Django-specific plugins (
mypy_django_plugin and mypy_drf_plugin) to understand Django models and DRF serializers.Pre-commit Hooks
Pre-commit hooks automatically run checks before each commit:Setup
Configured Hooks
From.pre-commit-config.yaml:
Standard Checks
Standard Checks
Django Upgrade
Django Upgrade
Automatically upgrade Django code to target version:
Ruff
Ruff
djLint (Template Linter)
djLint (Template Linter)
Formats and lints Django templates:
Code Quality Standards
Line Length
Import Sorting
Ruff automatically sorts imports (replaces isort):Naming Conventions
- Classes:
PascalCase - Functions/methods:
snake_case - Constants:
UPPER_SNAKE_CASE - Private methods:
_leading_underscore
Django Best Practices
Ruff includes Django-specific rules (DJ rules):
DJ001- Avoid usingnull=Trueon string-based fieldsDJ006- Do not useexcludeinModelFormDJ008- Model does not define__str__method- And more!
Security
Ruff includes security checks from Bandit (S rules):
S105- Hardcoded password stringS106- Hardcoded password function argumentS108- Hardcoded/tmpdirectoryS301- Pickle usage
CI/CD Integration
Code quality checks run automatically on GitHub Actions:.github/workflows/ci.yml (example)
IDE Integration
VS Code
Install the Ruff extension:settings.json
PyCharm
Configure external tools for Ruff and mypy:Add Ruff as External Tool
Settings → Tools → External Tools → Add
- Program:
ruff - Arguments:
check . --fix
Running All Quality Checks
Before committing, run all checks:Next Steps
Running Tests
Test suite and coverage
Project Structure
Understanding the codebase
Contributing
Contribution guidelines