Windsurf rules for Python: formatter-enforced PEP 8, modern type hints, src-layout packages, async HTTP with timeouts, and behaviour-focused pytest tests.
.devin/rules/python-development-in-windsurf.md. Downloaded files need to be placed in that repository path.---
trigger: glob
globs: "**/*"
---
Apply these rules to Python code in this workspace.
## Code style
- Follow PEP 8 through the project's formatter and linter (for example Ruff); do not hand-format against them.
- Type-annotate all function signatures. Write docstrings for public modules, classes and functions.
- Keep functions focused on one task; split when a function mixes I/O with logic or needs comments to separate its steps.
## Type hints
```python
from dataclasses import dataclass
from typing import Any
import aiohttp
@dataclass(frozen=True)
class User:
id: str
email: str
name: str | None = None
def get_users(repo: "UserRepository", limit: int = 10) -> list[User]:
"""Return up to `limit` users."""
return repo.list(limit=limit)
async def fetch_json(session: aiohttp.ClientSession, url: str) -> dict[str, Any]:
"""Fetch a JSON object from `url`, raising for HTTP errors."""
timeout = aiohttp.ClientTimeout(total=10)
async with session.get(url, timeout=timeout) as response:
response.raise_for_status()
return await response.json()
```
- Use built-in generics and `X | None` (Python 3.10+); `typing.List`/`Dict`/`Optional` are older forms.
- Reuse one `ClientSession` per application instead of creating one per request; always set timeouts and check status codes.
## Project structure
```
pyproject.toml
src/
my_package/
__init__.py
main.py
config.py
models/
services/
api/
tests/
```
- Use the src layout with a named package (`src/my_package/`), not `src/__init__.py`, so tests run against the installed package.
## Testing
- Write tests with pytest; use fixtures for test data and `pytest.mark.parametrize` for input tables.
- Mock external services at their boundary (HTTP, cloud SDKs); test pure logic without mocks.
- Use coverage reports to find untested branches in changed code rather than chasing a fixed percentage.
Cursor rule for FastAPI projects using Pydantic v2 schemas, SQLAlchemy 2 async_sessionmaker, lifespan cleanup, explicit commits and 409 conflict handling.
Cursor rule for Express 5 APIs in TypeScript with createApp structure, no try/catch boilerplate, Zod 4 validation into res.locals and a safe central error handler.
Cursor rule for Next.js Route Handlers with Zod 4 safeParse validation, auth and ownership checks, awaited params, bounded pagination and one consistent JSON error shape.
Windsurf
backend
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
A Windsurf Python project has src/__init__.py as its package, typing.List/Optional everywhere, an aiohttp call without timeout or status check, and a CI rule demanding 80% coverage.
Restructure the project and update src/services/users.py following the Python development rule.
A src/my_package/ layout with pyproject.toml, built-in generic hints and str | None, fetch_json with a ClientTimeout and raise_for_status using a shared session, pytest tests with fixtures and parametrize, and coverage used to find gaps rather than as a fixed gate.
Windsurf's rules documentation (docs.windsurf.com/windsurf/cascade/memories) now redirects to Devin documentation, which describes rules for the Devin Local agent in Devin Desktop. Current rules live in .devin/rules/*.md with a trigger setting, and the legacy Windsurf files (.windsurf/rules/*.md, .windsurf/global_rules.md and .windsurfrules) are still imported by default. AGENTS.md files are read as always-on rules.
.devin/rules/python-development-in-windsurf.mdStarting point, not a tested configuration for your repository. Applied when files matching globs are involved (trigger: glob). Review the instructions, adapt the file paths and run your project's existing checks.
---
trigger: glob
globs: "**/*"
---
Apply these rules to Python code in this workspace.
## Code style
- Follow PEP 8 through the project's formatter and linter (for example Ruff); do not hand-format against them.
- Type-annotate all function signatures. Write docstrings for public modules, classes and functions.
- Keep functions focused on one task; split when a function mixes I/O with logic or needs comments to separate its steps.
## Type hints
```python
from dataclasses import dataclass
from typing import Any
import aiohttp
@dataclass(frozen=True)
class User:
id: str
email: str
name: str | None = None
def get_users(repo: "UserRepository", limit: int = 10) -> list[User]:
"""Return up to `limit` users."""
return repo.list(limit=limit)
async def fetch_json(session: aiohttp.ClientSession, url: str) -> dict[str, Any]:
"""Fetch a JSON object from `url`, raising for HTTP errors."""
timeout = aiohttp.ClientTimeout(total=10)
async with session.get(url, timeout=timeout) as response:
response.raise_for_status()
return await response.json()
```
- Use built-in generics and `X | None` (Python 3.10+); `typing.List`/`Dict`/`Optional` are older forms.
- Reuse one `ClientSession` per application instead of creating one per request; always set timeouts and check status codes.
## Project structure
```
pyproject.toml
src/
my_package/
__init__.py
main.py
config.py
models/
services/
api/
tests/
```
- Use the src layout with a named package (`src/my_package/`), not `src/__init__.py`, so tests run against the installed package.
## Testing
- Write tests with pytest; use fixtures for test data and `pytest.mark.parametrize` for input tables.
- Mock external services at their boundary (HTTP, cloud SDKs); test pure logic without mocks.
- Use coverage reports to find untested branches in changed code rather than chasing a fixed percentage.
Ask for a small change to one matching file. Check the tool's loaded context or instruction view, inspect the diff for the requested convention, and run the relevant build or test. A well-formatted file does not guarantee the model follows every instruction.
The docs recommend keeping rules short and specific. The current docs say AGENTS.md, AGENTS.local.md and AGENT.md are read as always-on rules, including files in subdirectories. Use .devin/rules/ when you need glob, model-decision or manual triggers.
Documentation checked 2026-11-05: Devin docs: Local customizations (redirect target of Windsurf memories docs)Windsurf docs: Cascade memories (redirects)
Cursor rule for FastAPI projects using Pydantic v2 schemas, SQLAlchemy 2 async_sessionmaker, lifespan cleanup, explicit commits and 409 conflict handling.
Cursor rule for Express 5 APIs in TypeScript with createApp structure, no try/catch boilerplate, Zod 4 validation into res.locals and a safe central error handler.
Cursor rule for Next.js Route Handlers with Zod 4 safeParse validation, auth and ownership checks, awaited params, bounded pagination and one consistent JSON error shape.