python-patterns
できること
このガイドは、Pythonプログラムをどのように構築するかという重要な判断を下す手助けをします。ツールの選び方やコードの整理方法の背景にある考え方を教えるので、例をコピーするだけでなく、開発について自分で考えられるようになります。
使う場面
- ✓プロジェクトで使う「ツール」(フレームワーク)を選ぶとき。
- ✓プログラムが同時に多くの処理を高速に行う必要があるか(非同期処理)を判断するとき。
- ✓Pythonプロジェクトのファイルやフォルダを整理するとき。
スキルのリンク
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/python-patterns/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“APIのためのPythonプロジェクトはどのように構成すればよいですか?”
毎週5つの新しいスキル。1分で読めます。
仕組み
このガイドは、判断を導くための原則や問いかけを示します。完成したコードは提供せず、あなたが適用するための思考の進め方を提供します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Python Patterns
Python development principles and decision-making for 2025. Learn to THINK, not memorize patterns.
When to Use
Use this skill when making Python architecture decisions, choosing frameworks, designing async patterns, or structuring Python projects.
⚠️ How to Use This Skill
This skill teaches decision-making principles, not fixed code to copy.
- ASK user for framework preference when unclear
- Choose async vs sync based on CONTEXT
- Don't default to same framework every time
1. Framework Selection (2025)
Decision Tree
What are you building?
│
├── API-first / Microservices
│ └── FastAPI (async, modern, fast)
│
├── Full-stack web / CMS / Admin
│ └── Django (batteries-included)
│
├── Simple / Script / Learning
│ └── Flask (minimal, flexible)
│
├── AI/ML API serving
│ └── FastAPI (Pydantic, async, uvicorn)
│
└── Background workers
└── Celery + any framework
Comparison Principles
| Factor | FastAPI | Django | Flask |
|---|---|---|---|
| Best for | APIs, microservices | Full-stack, CMS | Simple, learning |
| Async | Native | Django 5.0+ | Via extensions |
| Admin | Manual | Built-in | Via extensions |
| ORM | Choose your own | Django ORM | Choose your own |
| Learning curve | Low | Medium | Low |
Selection Questions to Ask:
- Is this API-only or full-stack?
- Need admin interface?
- Team familiar with async?
- Existing infrastructure?
2. Async vs Sync Decision
When to Use Async
async def is better when:
├── I/O-bound operations (database, HTTP, file)
├── Many concurrent connections
├── Real-time features
├── Microservices communication
└── FastAPI/Starlette/Django ASGI
def (sync) is better when:
├── CPU-bound operations
├── Simple scripts
├── Legacy codebase
├── Team unfamiliar with async
└── Blocking libraries (no async version)
The Golden Rule
I/O-bound → async (waiting for external)
CPU-bound → sync + multiprocessing (computing)
Don't:
├── Mix sync and async carelessly
├── Use sync libraries in async code
└── Force async for CPU work
Async Library Selection
| Need | Async Library |
|---|---|
| HTTP client | httpx |
| PostgreSQL | asyncpg |
| Redis | aioredis / redis-py async |
| File I/O | aiofiles |
| Database ORM | SQLAlchemy 2.0 async, Tortoise |
3. Type Hints Strategy
When to Type
Always type:
├── Function parameters
├── Return types
├── Class attributes
├── Public APIs
Can skip:
├── Local variables (let inference work)
├── One-off scripts
├── Tests (usually)
Common Type Patterns
# These are patterns, understand them:
# 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]: ...
# Callable
from typing import Callable
def apply(fn: Callable[[int], str]) -> str: ...
Pydantic for Validation
When to use Pydantic:
├── API request/response models
├── Configuration/settings
├── Data validation
├── Serialization
Benefits:
├── Runtime validation
├── Auto-generated JSON schema
├── Works with FastAPI natively
└── Clear error messages
4. Project Structure Principles
Structure Selection
Small project / Script:
├── main.py
├── utils.py
└── requirements.txt
Medium API:
├── app/
│ ├── __init__.py
│ ├── main.py
│ ├── models/
│ ├── routes/
│ ├── services/
│ └── schemas/
├── tests/
└── pyproject.toml
Large application:
├── src/
│ └── myapp/
│ ├── core/
│ ├── api/
│ ├── services/
│ ├── models/
│ └── ...
├── tests/
└── pyproject.toml
FastAPI Structure Principles
Organize by feature or layer:
By layer:
├── routes/ (API endpoints)
├── services/ (business logic)
├── models/ (database models)
├── schemas/ (Pydantic models)
└── dependencies/ (shared deps)
By feature:
├── users/
│ ├── routes.py
│ ├── service.py
│ └── schemas.py
└── products/
└── ...
5. Django Principles (2025)
Django Async (Django 5.0+)
Django supports async:
├── Async views
├── Async middleware
├── Async ORM (limited)
└── ASGI deployment
When to use async in Django:
├── External API calls
├── WebSocket (Channels)
├── High-concurrency views
└── Background task triggering
Django Best Practices
…
よくある質問
フレームワークとは何ですか?
フレームワークは、骨組みや、あらかじめ用意された一連のツールのようなものです。決まったルールと構造に従うことで、プログラムをより速く作る助けになります。
「非同期(asynchronous)」とはどういう意味ですか?
プログラムが、ある処理の完了を待たずに次の処理を始め、複数の処理を同時に行えることを意味します。多くのリクエストに素早く応答する必要があるプログラムに役立ちます。
「型ヒント(Type Hints)」とは何ですか?
変数や関数が受け取る、または返すデータの種類(数値、文字列など)を示すために、コードに追加する注釈です。エラーの防止に役立ち、コードがわかりやすくなります。
詳細
作者による元の説明
Python development principles and decision-making. Framework selection, async patterns, type hints, project structure. Teaches thinking, not copying.
人気
- GitHubのスター
- 48k
- ランキング
- #5549
- ライセンス
- MIT
- 更新日
- 2026/10/15
コメント
- …
このリポジトリの他のスキル
00-andruia-consultant
48kエージェントがAIプロジェクトの立ち上げや改善を支援します。コードを分析し、ツールを提案し、スペイン語で行動計画を作成します。
007
48kエージェントがセキュリティ監査と脅威モデリングを行えるようにします。攻撃や脆弱性からプロジェクトを守るのに役立ちます。
10-andruia-skill-smith
48kエージェントがAIツールの作成や改善を支援します。ツールの動作を定義し、ドキュメントを書き、構造を検証します。
20-andruia-niche-intelligence
48kエージェントが特定の業界に関する要約を作成できるようにします。信頼できる情報源を使って、プロジェクトの背景、ルール、利用パターン、リスクを把握するのに役立ちます。
似ているスキル
diffs
394k編集内容の実際の共有可能な差分を、手書きの要約ではなく、ビューアーのリンクや画像ファイルとして作成するようエージェントを支援します。
coding-agent
394kCodex、Claude Code、OpenCodeに大きめのコーディング作業をバックグラウンドのワーカーとして渡し、その進捗を確認するようエージェントを支援します。
gh-issues
394kGitHubのイシューを探し、取り組むものを選び、修正を含むプルリクエストを開くようエージェントを支援します。レビューコメントへの対応も含みます。