Python example

AGENTS.md Template for Python

Copy a Python AGENTS.md example with virtual environment, dependency, typing, formatting, pytest, migrations, and package-layout instructions.

Last verifiedAugust 13, 2026
When to use it

Use this for a Python application or package after matching it to the repository's environment and dependency manager.

Full version

Copy the AGENTS.md template

Replace every bracketed value and delete any rule you cannot verify in the repository.

AGENTS.md
# Python Repository Instructions

## Runtime
- Supported Python: `[version from pyproject.toml]`
- Environment and dependency manager: `[uv/Poetry/pip/other]`
- Package layout: `[src layout/flat layout]`

## Commands
- Create/sync environment: `[exact command]`
- Run application: `[exact command]`
- Focused test: `[exact pytest command with path]`
- Full tests: `[exact command]`
- Lint: `[exact command]`
- Format check: `[exact command]`
- Type-check: `[exact command]`
- Build package: `[exact command or remove]`

## Python Rules
- Use the Python version and dependency manager declared by the repository.
- Follow the existing package layout and import style; do not modify sys.path to hide packaging errors.
- Add type hints to changed public interfaces and keep return types explicit.
- Raise or translate specific exceptions; do not catch broad Exception unless adding context and preserving failure semantics.
- Use timezone-aware datetimes and avoid mutable default arguments.
- Do not edit generated lockfiles manually.

## Data and Migrations
- Treat schema and data migrations as separate, reviewable changes.
- Do not generate, apply, or roll back migrations without explicit task scope.
- Never use production credentials or production data in local tests.

## Testing
- Put tests in the repository's existing test tree and mirror its naming conventions.
- Cover the success path, invalid input, and the most important exception path.
- Prefer deterministic fixtures; freeze time and mock only external boundaries when needed.
- Run focused pytest during iteration, then lint, types, and the required full suite.

Do not copy blindly: Do not mix commands from uv, Poetry, pip, Hatch, or Conda; keep only the toolchain the project actually uses.

Minimal version

Start smaller when the repository is simple

AGENTS.md
# Python Repository Instructions

## Commands
- Install: `[uv sync | poetry install | pip install -e .]`
- Test: `[uv run pytest | poetry run pytest | pytest]`
- Lint: `[ruff check .]`
- Format check: `[ruff format --check .]`
- Type-check: `[mypy src | pyright]`

## Rules
- Preserve the existing package and dependency manager.
- Add type hints to changed public interfaces.
- Test success, invalid input, and important exception paths.
- Do not create or run migrations without explicit approval.

Customize each field

Dependency manager

Select one toolchain from repository evidence and delete every alternative.

Python version

Read pyproject.toml, runtime files, and CI; do not assume the locally installed version is authoritative.

Migrations

Keep this section only for projects with a database, and name the actual migration framework.

Type checks

Use the configured checker and its real target paths.

Validate the instructions

  1. Create a clean environment using the documented command.
  2. Install from the lockfile or declared project metadata.
  3. Run one focused pytest command and confirm test discovery.
  4. Run formatting, linting, and type checks using repository configuration.
  5. Build the package if it is distributed as a library or artifact.

Common mistakes

Listing several mutually exclusive package managers

Choose the one demonstrated by lockfiles and CI.

Using the system Python implicitly

Document the supported version and environment activation or run prefix.

Broad exception handling

Name expected failures and preserve actionable error context.

Interactive tool

Generate a repository-specific starting file.

Choose your framework, real commands, paths, and approval boundaries, then copy or download the result.

Open AGENTS.md Generator

Related templates

All templates

Official sources

Instruction discovery and scope behavior were checked on August 13, 2026. Recheck product documentation when standardizing these files across a team.