python-patterns
What it does
This guide helps you make important decisions about how to build Python programs. It teaches the principles behind choosing tools and organizing your code, so you learn to think about development instead of just copying examples.
When to use it
- βWhen choosing which 'tool' (framework) to use for your project.
- βWhen deciding if your program needs to be fast at many tasks simultaneously (asynchronous).
- βWhen organizing your Python project's files and folders.
Skill link
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/python-patterns/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βHow should I structure my Python project for an API?β
5 new skills a week. 1 minute to read.
How it works
This guide presents principles and questions to guide your decisions. It doesn't provide ready-made code, but rather a thought process for you to apply.
Technical content (original SKILL.md)
Original text by the author, straight from 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
β¦
FAQ
What is a framework?
A framework is like a skeleton or a set of pre-built tools that help build a program faster, following certain rules and structures.
What does 'asynchronous' mean?
It means a program can do multiple things at the same time, without waiting for one task to finish before starting the next. It's useful for programs that need to respond quickly to many requests.
What are 'Type Hints'?
These are annotations you add to your code to indicate the type of data a variable or function expects or returns (e.g., number, text). This helps prevent errors and makes the code easier to understand.
Details
Original description by the author
Python development principles and decision-making. Framework selection, async patterns, type hints, project structure. Teaches thinking, not copying.
Popularity
- GitHub stars
- 48k
- Ranking position
- #5549
- License
- MIT
- Updated
- 10/15/2026
Comments
- β¦
More skills from this repository
00-andruia-consultant
48kHelps your agent start or improve AI projects. It analyzes code, suggests tools, and creates action plans in Spanish.
007
48kLets your agent perform security audits and threat modeling. It's useful for protecting projects against attacks and vulnerabilities.
10-andruia-skill-smith
48kHelps your agent create or improve AI tools. It defines how tools work, writes documentation, and validates the structure.
20-andruia-niche-intelligence
48kLets your agent create a summary about a specific industry. It's useful for understanding the context, rules, usage patterns, and risks of a project, using reliable sources.
Similar skills
diffs
394kLets your agent produce a real, shareable diff of edits as a viewer link or image file, instead of a hand-written summary.
coding-agent
394kHelps your agent hand a larger coding job to Codex, Claude Code, or OpenCode as a background worker, then check on its progress.
gh-issues
394kHelps your agent find GitHub issues, pick the ones to work on, and open pull requests with fixes, including follow-up on review comments.