skills/python-conventions/SKILL.md
Python coding standards including PEP 8, type hints, modern syntax (3.11+), ruff formatting, uv package management, and best practices. Use when writing, reviewing, or refactoring Python code, setting up Python projects, or managing dependencies.
npx skillsauth add rory-data/copilot python-conventionsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
uv for dependency and environment managementruff (replaces flake8, isort, pylint, Black)list[str], dict[str, int])ty for type checkingprek for pre-commit hookslist[str], dict[str, int]) for Python 3.9+ collections; only use typing module for complex types like Union, Optional, Protocol, TypedDict, Genericpathlib.Path over os.path for file system operationsSelf type for method chaining and builder patterns (from typing_extensions if needed)def or class keywordruff for both formatting and linting - it replaces flake8, isort, pylint, and Blackfrom typing_extensions import Self
def calculate_area(radius: float) -> float:
"""Calculate the area of a circle given the radius.
Args:
radius: The radius of the circle.
Returns:
The area of the circle, calculated as π * radius².
Raises:
ValueError: If radius is negative.
"""
if radius < 0:
raise ValueError("Radius cannot be negative")
import math
return math.pi * radius ** 2
class CircleCalculator:
"""Calculator for circle-related operations."""
def __init__(self, precision: int = 2) -> None:
"""Initialise the calculator with specified precision.
Args:
precision: Number of decimal places for results.
"""
self.precision = precision
def area(self, radius: float) -> Self:
"""Calculate area and return self for method chaining."""
self._last_result = calculate_area(radius)
return self
def get_result(self) -> float:
"""Get the last calculated result."""
return round(self._last_result, self.precision)
uv for package management and virtual environment managementpyproject.toml for project configuration and dependenciesAlways check project setup first: Look for .venv/, uv.lock, or pyproject.toml with [tool.uv] section
If uv-managed project detected:
uv run for executing Python scripts: uv run python script.pyuv run for tests: uv run pytest or uv run pytest -vuv add for adding dependencies: uv add package-nameuv sync to synchronise environment with lock fileIf standard venv detected (no uv):
source .venv/bin/activate && pytestFor new projects: Prefer uv init and uv venv for environment setup
[project]
name = "my-project"
version = "0.1.0"
description = "Project description"
requires-python = ">=3.11"
dependencies = [
"httpx>=0.25.0",
"pydantic>=2.0.0",
]
[project.optional-dependencies]
dev = [
"pytest>=7.4.0",
"ruff>=0.1.0",
"mypy>=1.5.0",
]
[tool.ruff]
line-length = 88
target-version = "py311"
[tool.ruff.lint]
select = ["E", "F", "I", "N", "W", "UP"]
dict, set, deque) for speedcProfile, line_profiler, or Py-Spymultiprocessing or asyncio for parallelism if appropriatelru_cache for memoisation# Handle multiple exceptions at once
try:
raise ExceptionGroup("multiple errors", [
ValueError("invalid value"),
TypeError("wrong type"),
])
except* ValueError as eg:
# Handle all ValueErrors in the group
for exc in eg.exceptions:
print(f"ValueError: {exc}")
except* TypeError as eg:
# Handle all TypeErrors in the group
for exc in eg.exceptions:
print(f"TypeError: {exc}")
def process_response(response: dict) -> str:
match response:
case {"status": 200, "data": data}:
return f"Success: {data}"
case {"status": 404}:
return "Not found"
case {"status": code} if code >= 500:
return "Server error"
case _:
return "Unknown response"
# Use | for unions instead of Union
def process(value: str | int) -> bool:
return isinstance(value, str)
# Use Self for return types
class Builder:
def add_item(self, item: str) -> Self:
return self
Refer to the python-testing-patterns skill for comprehensive testing guidance.
tools
Queries, manages, and troubleshoots Apache Airflow using the af CLI. Covers listing DAGs, triggering runs, reading task logs, diagnosing failures, debugging DAG import errors, checking connections, variables, pools, and monitoring health. Also routes to sub-skills for writing DAGs, debugging, deploying, and migrating Airflow 2 to 3. Use when user mentions "Airflow", "DAG", "DAG run", "task log", "import error", "parse error", "broken DAG", or asks to "trigger a pipeline", "debug import errors", "check Airflow health", "list connections", "retry a run", or any Airflow operation. Do NOT use for warehouse/SQL analytics on Airflow metadata tables — use analyzing-data instead.
tools
Build Airflow 3.1+ plugins that embed FastAPI apps, custom UI pages, React components, middleware, macros, and operator links directly into the Airflow UI. Use this skill whenever the user wants to create an Airflow plugin, add a custom UI page or nav entry to Airflow, build FastAPI-backed endpoints inside Airflow, serve static assets from a plugin, embed a React app in the Airflow UI, add middleware to the Airflow API server, create custom operator extra links, or call the Airflow REST API from inside a plugin. Also trigger when the user mentions AirflowPlugin, fastapi_apps, external_views, react_apps, plugin registration, or embedding a web app in Airflow 3.1+. If someone is building anything custom inside Airflow 3.1+ that involves Python and a browser-facing interface, this skill almost certainly applies.
data-ai
Use when the user needs human-in-the-loop workflows in Airflow (approval/reject, form input, or human-driven branching). Covers ApprovalOperator, HITLOperator, HITLBranchOperator, HITLEntryOperator, HITLTrigger. Requires Airflow 3.1+. Does not cover AI/LLM calls (see airflow-ai).
development
Detects and fixes common code smells during review or refactoring. Invoke whenever reviewing code for quality issues, before merging a PR, when refactoring legacy code, or when the user asks about code quality, anti-patterns, or technical debt. Detects: over-abstraction, complex inheritance, large functions, tight coupling, hidden dependencies, magic numbers, boolean traps, swallowed exceptions, global state, and duplicate code. Provides specific fixes with before/after examples. Also invoke when someone says "review this code", "is this clean?", "can I improve this?", "this feels messy", or "find problems in my code".