CLAUDE.md Python FastAPI Backend

FastAPI — CLAUDE.md

FastAPIフレームワークのCLAUDE.md。非同期対応・自動OpenAPIドキュメント生成のPython高速WebフレームワークAI向けガイド。

CLAUDE.md · 55 lines
# FastAPI — CLAUDE.md

## Project Overview

FastAPI is a modern, fast (high-performance) web framework for building APIs with Python based on standard Python type hints.

## Development

```bash
# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run with coverage
pytest --cov=fastapi

# Lint
ruff check .
mypy fastapi
```

## Code Principles

- All code must have type annotations.
- Use `async def` for I/O-bound operations.
- Pydantic models for request/response validation.
- Prefer `Annotated` for dependency injection.
- Never break backwards compatibility without a major version bump.

## Testing Requirements

- Every new feature needs tests.
- Use `httpx.AsyncClient` with `TestClient` pattern.
- Test both sync and async endpoints.
- Coverage must not decrease.

## Documentation

- All public functions/classes need docstrings.
- Examples in docstrings should be runnable.
- Update `docs/` for any user-facing changes.

## Dependency Injection

- Use `Depends()` for injectable dependencies.
- Type dependencies with `Annotated` (preferred over old style).
- Keep dependency functions small and focused.

## Error Handling

- Raise `HTTPException` for expected HTTP errors.
- Use `RequestValidationError` for input validation failures.
- Always include meaningful error messages.
Share on X

こちらもおすすめ

Backend カテゴリの他のルール

もっとルールを探す

CLAUDE.md、.cursorrules、AGENTS.md、Image Prompts の全 223 ルールをチェック。