Home › Python › Python Copilot path instructions

Python Copilot path instructions

Path-specific Copilot instructions for Python 3.12+ files: typing, error handling, uv/ruff tooling, and pytest.

GitHub CopilotPython

How to use

Save this as .github/instructions/python.instructions.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

.github/instructions/python.instructions.mdDownload  
---
applyTo: "**/*.py"
description: Python conventions
---

# Python

- Tooling: `uv run ruff format`, `uv run ruff check --fix`, `uv run pyright` (or mypy), `uv run pytest -q`. Add deps with `uv add`, never `pip install`.
- Type hints on all function signatures; modern syntax (`list[int]`, `str | None`). Avoid `Any`; use `TypedDict`, dataclasses, or Pydantic models for structured data.
- Raise specific exceptions with useful messages; never bare `except:` or `except Exception: pass`.
- `pathlib.Path` for files, `encoding="utf-8"` on every open.
- `logging.getLogger(__name__)` in modules; `print` only in CLI output.
- No mutable default arguments; no module-level side effects (network, DB) at import time.
- Keep functions short with early returns; prefer comprehensions for simple transforms, loops when logic grows.
- Timezone-aware datetimes (`datetime.now(tz=UTC)`).
- Secrets and config from environment via a settings object (pydantic-settings or the repo's equivalent).

## Tests
pytest functions with fixtures and `parametrize`; mock only external boundaries.

Related rules

Angular 20 Copilot instructions

Copilot instructions for Angular 20 apps using standalone components, signals, and the new control flow.

GitHub CopilotAngular

Code review Copilot instructions

Copilot instructions focused on pull request review: what to flag, severity labels, and how to word comments.

GitHub CopilotAgent workflows

C# / .NET Copilot path instructions

Path-specific Copilot instructions for C# files on .NET 10: nullable types, async, records, and logging.

GitHub Copilot.NET / ASP.NET Core

Dockerfile Copilot path instructions

Path-specific Copilot instructions for Dockerfiles and compose files: multi-stage builds, non-root, and pinned images.

GitHub CopilotDocker

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.