python-patterns

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

2|Updated May 30, 2026
One-click install
npx skills add https://github.com/virahitvin8/crafty-gis --skill python-patterns-virahitvin8
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-patterns
Source: https://github.com/virahitvin8/crafty-gis/tree/main/GIT_STAR/.agent/skills/python-patterns
Command: npx skills add https://github.com/virahitvin8/crafty-gis --skill python-patterns-virahitvin8

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 provides decision-making principles for choosing the right framework, concurrency model, and project layout for each specific situation. ## Core Features & Use Cases - Framework Selection Guidance: Decision trees and comparison tables for choosing between FastAPI, Django, and Flask based on project requirements like API-only vs full-stack, admin needs, and team async familiarity. - Async vs Sync Strategy: Clear rules for when to use async (I/O-bound work) versus sync (CPU-bound work), plus the right async libraries such as httpx, asyncpg, and aiofiles. - Type Hints and Validation: Patterns for typing function signatures, using Optional and Union types, and applying Pydantic for request validation and configuration. - Use Case: When starting a new microservice, use this Skill to decide between FastAPI and Django, plan the project structure by feature or layer, and set up dependency injection and background task handling with Celery or FastAPI BackgroundTasks. ## Quick Start Ask the AI to help you choose between FastAPI, Django, and Flask for your new project and recommend an appropriate project structure and async strategy.

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 microservices needing async support, Django for full-stack applications requiring a built-in admin and ORM, and Flask for simple scripts or learning projects. Consider whether you need an admin interface, async support, and your team's familiarity with each framework.

When should I use async def versus def in FastAPI?

Use async def when performing I/O-bound operations like async database queries with asyncpg or HTTP calls with httpx. Use def for blocking operations, sync database drivers, or CPU-bound work, since FastAPI runs sync endpoints in a threadpool automatically.

What async libraries should I use for Python databases and HTTP?

Use httpx for async HTTP clients, asyncpg for PostgreSQL, redis-py async or aioredis for Redis, aiofiles for file I/O, and SQLAlchemy 2.0 async or Tortoise for ORM needs. Never use sync libraries inside async code paths.

Does Django support async views and ORM operations?

Django 5.0 and later supports async views, async middleware, and limited async ORM operations with ASGI deployment. Use async in Django for external API calls, WebSockets via Channels, and high-concurrency views.

When should I use Celery instead of FastAPI BackgroundTasks?

Use FastAPI BackgroundTasks for quick fire-and-forget operations in the same process without persistence. Choose Celery or ARQ for long-running tasks, retry logic, distributed workers, persistent queues, and complex workflows.

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

Calling blocking sync libraries inside async functions blocks the event loop and destroys concurrency benefits. Keep I/O-bound work async with async-native libraries, and offload CPU-bound work to multiprocessing instead of forcing async.