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.

More: all Python rules · all GitHub Copilot rules

Related rules

Modern Python project (uv + ruff) rules

Cursor rules for Python 3.12+ projects managed with uv, ruff, and pyright or mypy: typing, layout, and tooling.

CursorPython

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

ASP.NET Core Copilot instructions

Copilot instructions for ASP.NET Core on .NET 9/10: minimal APIs, EF Core, nullable types, and xUnit tests.

GitHub Copilot.NET / ASP.NET Core

Go Copilot path instructions

Path-specific Copilot instructions (.instructions.md) for Go 1.27 code: errors, context, stdlib routing, and tests.

GitHub CopilotGo

Java + Gradle Copilot path instructions

Path-specific Copilot instructions for Java 25 LTS code built with Gradle: records, null safety, and JUnit 5 tests.

GitHub CopilotJava

Laravel Copilot instructions

GitHub Copilot instructions for Laravel 11+ apps with Eloquent, Pest, and Form Requests.

GitHub CopilotLaravel

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.