Python checklist¶
Copy this list into a pull request, design review or project kickoff and tick what applies. Rules are grouped by level and sorted by score (criteria). Each links to the file that explains it and cites its sources. Automatable names tools that can check the rule in CI (see the file's "How to enforce" section).
Also apply the general checklist.
This file is generated by python3 scripts/rank.py fix from the guidelines. Don't edit it by hand.
Strongly recommended (9–10)¶
-
PY-12(9) In Django, never enableDEBUGin production, loadSECRET_KEYand other secrets from the environment or a file, and runmanage.py check --deployagainst the production settings. (specific/python) Automatable:manage.py check --deploy. -
PY-14(9) Never pass untrusted data topickle,eval(),exec()oryaml.load(), or into a shell command withshell=True. (specific/python) Automatable: Ruff flake8-bandit (S) rules.
Recommended (6–8)¶
-
PY-1(8) Run a Python version that still receives fixes, and upgrade before its end-of-life date. (specific/python) -
PY-2(8) Commit a lock file that pins every direct and transitive dependency, install exactly what it lists in CI and deployments, and audit it for known vulnerabilities in CI. (specific/python) Automatable: pip hash-checking mode, pip-audit. -
PY-7(8) Validate all external input at runtime where it enters the application, with Pydantic models (as FastAPI does for request bodies) or with Django forms or Django REST framework serializers, and use only the validated data. (specific/python) -
PY-9(8) Inasynccode, don't call blocking I/O or CPU-heavy functions directly: use async libraries, run blocking calls in a thread withasyncio.to_thread()(in Django,sync_to_async()), and run CPU-heavy work in an executor such as a process pool. (specific/python) Automatable: Ruff flake8-async (ASYNC) rules. -
PY-8(7) Annotate the code with type hints and run a type checker, such as mypy or Pyright, in CI, pinned with the other development dependencies. (specific/python) Automatable: mypy--strict. -
PY-10(7) Run concurrent tasks in anasyncio.TaskGroup, or keep a reference to every task you start withasyncio.create_task()until it finishes. (specific/python) Automatable: Ruff flake8-async (ASYNC) rules. -
PY-3(6) Install each application's dependencies into its own virtual environment, not into the Python that the operating system manages, and treat the environment as disposable. (specific/python) -
PY-4(6) Describe the project inpyproject.toml, use the src layout, and keep tests in a separatetests/directory. (specific/python) -
PY-5(6) When the domain has real business logic, keep it in plain Python modules that import neither the web framework nor the ORM, and let views, routers, tasks and commands call it through a service layer. (specific/python) Automatable: Import Linter forbidden contracts. -
PY-6(6) In FastAPI, split path operations intoAPIRoutermodules by area, and provide shared resources such as database sessions, settings and the current user through dependencies (Depends). (specific/python) -
PY-13(6) Load configuration into one typed settings object, such as apydantic-settingsBaseSettingsclass, so that missing or malformed values raise a validation error when the settings load. (specific/python) -
PY-15(6) Lint and format with Ruff, and runruff checkandruff format --checkin CI and in a pre-commit hook. (specific/python) Automatable: Ruff linter exit codes.
Conditional (1–5)¶
-
PY-11(5) Write async code only where a service waits on many I/O operations at once, such as long-lived connections or calls fanned out to other services. Otherwise keep it synchronous. (specific/python)