Python development principles and decision-making. Framework selection, async patterns, type hints, project structure. Use this skill whenever the user is building Python applications, choosing frameworks, applying type hints, or designing project structure. Triggers on Python, FastAPI, Django, asyncio, type hints, Pydantic, pip, virtual environment.
Python development principles and decision-making for 2025. Learn to THINK, not memorize patterns.
| Need | File |
|---|---|
| Choose framework | framework-selection.md |
| Async vs sync decision | async-patterns.md |
| FastAPI patterns |
| fastapi-guide.md |
| Django patterns | django-guide.md |
| Background tasks | background-tasks.md |
| Testing strategy | testing-guide.md |
Always type:
├── Function parameters
├── Return types
├── Class attributes
├── Public APIs
Can skip:
├── Local variables (let inference work)
├── One-off scripts
├── Tests (usually)
# Optional → might be None
from typing import Optional
def find_user(id: int) -> Optional[User]: ...
# Union → one of multiple types
def process(data: str | dict) -> None: ...
# Generic collections
def get_items() -> list[Item]: ...
def get_mapping() -> dict[str, int]: ...
Use Pydantic when:
├── API request/response models
├── Configuration/settings
├── Data validation
└── Serialization
Benefits:
├── Runtime validation
├── Auto-generated JSON schema
├── Works with FastAPI natively
└── Clear error messages
Small project / Script:
├── main.py
├── utils.py
└── requirements.txt
Medium API:
├── app/
│ ├── main.py
│ ├── models/
│ ├── routes/
│ ├── services/
│ └── schemas/
├── tests/
└── pyproject.toml
Large application:
├── src/
│ └── myapp/
│ ├── core/
│ ├── api/
│ ├── services/
│ └── models/
├── tests/
└── pyproject.toml
In FastAPI:
├── Create custom exception classes
├── Register exception handlers
├── Return consistent error format
└── Log without exposing internals
Pattern:
├── Raise domain exceptions in services
├── Catch and transform in handlers
└── Client gets clean error response
Include:
├── Error code (programmatic)
├── Message (human readable)
├── Details (field-level when applicable)
└── NOT stack traces (security)
Before implementing:
Remember: Python patterns are about decision-making for YOUR specific context. Don't copy code — think about what serves your application best.