Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions python-project-for-agentic-coding/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copy this file to .env and fill in the values your project needs.
# .env is git-ignored, so real secrets never reach the repository.
API_KEY=your-api-key-here
16 changes: 16 additions & 0 deletions python-project-for-agentic-coding/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Python-generated files
__pycache__/
*.py[oc]
build/
dist/
wheels/
*.egg-info

# Virtual environments
.venv

# Environment variables
.env

# Coverage
.coverage
10 changes: 10 additions & 0 deletions python-project-for-agentic-coding/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.21
hooks:
- id: ruff-check
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v2.3.0'
hooks:
- id: mypy
18 changes: 18 additions & 0 deletions python-project-for-agentic-coding/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# `AGENTS.md`

## Development workflow

- This project is typed. Run mypy after adding or modifying code:
- `uv run mypy .`
- Use Ruff for formatting and linting:
- `uv run ruff format .`
- `uv run ruff check .`
- Run the full test suite after modifying code:
- `uv run pytest`
- Add or update tests when changing behavior.
- Before committing, run:
- `uv run pre-commit run --all-files`
- Prefer small, focused functions.

## Documentation
- Update documentation when public behavior changes.
45 changes: 45 additions & 0 deletions python-project-for-agentic-coding/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# How to Set Up a Python Project for Agentic Coding

This folder contains the sample code for the Real Python tutorial
[How to Set Up a Python Project for Agentic Coding](https://realpython.com/python-project-for-agentic-coding/).

It is the finished project from the tutorial: a small Python package wired up
with the automated feedback an AI coding agent needs, namely Ruff for linting
and formatting, mypy in strict mode for type checking, pytest with a coverage
gate for behavior, and pre-commit to run those checks before every commit.

## Setup

Install [uv](https://docs.astral.sh/uv/#installation), then install the
dependencies and the pre-commit hooks:

```console
$ uv sync
$ uv run pre-commit install
```

## Running the checks

Each tool can be run on its own:

```console
$ uv run ruff check .
$ uv run mypy .
$ uv run pytest
```

Or run everything the way the agent is told to in `AGENTS.md`:

```console
$ uv run pre-commit run --all-files
```

## What each file is for

| File | Purpose |
| --- | --- |
| `pyproject.toml` | Dependencies plus the Ruff, mypy, and pytest configuration |
| `AGENTS.md` | Workflow conventions an agent should follow |
| `.pre-commit-config.yaml` | Checks that run before each commit |
| `tests/` | Executable specification of the expected behavior |
| `.env.example` | Documents required environment variables without exposing secrets |
30 changes: 30 additions & 0 deletions python-project-for-agentic-coding/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[project]
name = "ai-agent-project"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.14"
dependencies = []

[build-system]
requires = ["uv_build>=0.11.26,<0.12.0"]
build-backend = "uv_build"

[dependency-groups]
dev = [
"mypy>=2.3.1",
"pre-commit>=4.6.2",
"pytest>=9.1.1",
"pytest-cov>=7.1.0",
"ruff>=0.16.7",
]

[tool.ruff]
line-length = 80

[tool.mypy]
strict = true

[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = "--cov=src --cov-report=term-missing --cov-fail-under=90"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def double(value: int) -> int:
return value * 2
5 changes: 5 additions & 0 deletions python-project-for-agentic-coding/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from ai_agent_project import double


def test_double_returns_twice_the_input() -> None:
assert double(4) == 8
Loading