python-patterns

Guides Python framework selection, async decisions, type hints, and project structure for 2025 development.

Updated Aug 5, 2026
One-click install
npx skills add https://github.com/pd-phuc/laravel-template --skill python-patterns-pd-phuc
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: python-patterns
Source: https://github.com/pd-phuc/laravel-template/tree/main/.agent/skills/python-patterns
Command: npx skills add https://github.com/pd-phuc/laravel-template --skill python-patterns-pd-phuc

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Python developers often default to the same framework or pattern regardless of context, leading to mismatched architectures, async/sync conflicts, and poorly structured projects. This Skill teaches decision-making principles so you choose the right framework, concurrency model, and structure for each specific project. ## Core Features & Use Cases - Framework Selection Guidance: Decision trees and comparison tables for choosing between FastAPI, Django, and Flask based on project type (API-first, full-stack, scripts, AI/ML serving). - Async vs Sync Strategy: Rules for when to use async def, which async libraries to pick (httpx, asyncpg, aiofiles), and how to avoid mixing sync and async carelessly. - Type Hints, Structure & Testing: Patterns for type annotations, Pydantic validation, project layout by layer or feature, background task selection (Celery, ARQ, BackgroundTasks), and pytest async testing. - Use Case: When starting a new microservice, use this Skill to decide between FastAPI and Django, plan your async database access with SQLAlchemy 2.0, define Pydantic schemas, and structure routes, services, and tests correctly. ## Quick Start Ask the AI to help you choose a Python framework and design the project structure for your new API or web application.

Frequently Asked Questions about python-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I choose between FastAPI, Django, and Flask?▼

Choose FastAPI for API-first services and microservices with native async support, Django for full-stack applications needing a built-in admin and ORM, and Flask for simple scripts or learning projects. Base the decision on whether you need an admin interface, async support, and your team's familiarity.

When should I use async def versus def in Python?▼

Use async def for I/O-bound operations like database queries, HTTP calls, and high-concurrency endpoints. Use regular def for CPU-bound work, simple scripts, or when using blocking libraries that have no async version.

Does Django support async views and ORM?▼

Django 5.0+ supports async views, async middleware, and limited async ORM operations with ASGI deployment. Async in Django is most useful for external API calls, WebSockets via Channels, and high-concurrency views.

What background task library should I use with FastAPI?▼

Use FastAPI's built-in BackgroundTasks for simple fire-and-forget in-process work. Choose Celery for distributed long-running tasks with retries, ARQ for async Redis-based queues, or Dramatiq for a simpler actor-based alternative.

Why is mixing sync and async code a problem in Python?▼

Calling blocking sync libraries inside async code blocks the event loop, destroying concurrency benefits. Use async-native libraries like httpx, asyncpg, and aiofiles, or run sync work in a threadpool instead.

How do I test async FastAPI endpoints with pytest?▼

Use pytest-asyncio with the httpx AsyncClient to test async endpoints. Mark tests with @pytest.mark.asyncio and create an AsyncClient bound to your app to send requests and assert on responses.