python-patterns

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

Updated Jul 29, 2026
One-click install
npx skills add https://github.com/MaiconGambini/opencode-harness-guide --skill python-patterns-maicongambini
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-patterns
Source: https://github.com/MaiconGambini/opencode-harness-guide/tree/main/skills/python-patterns
Command: npx skills add https://github.com/MaiconGambini/opencode-harness-guide --skill python-patterns-maicongambini

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Choosing the right Python framework, async strategy, and project structure is error-prone when developers default to familiar tools instead of context-driven decisions. This Skill provides decision frameworks and principles for Python architecture so you pick FastAPI, Django, or Flask based on actual requirements rather than habit. ## Core Features & Use Cases - Framework Selection Guidance: Decision trees and comparison tables for FastAPI, Django, and Flask based on project type, async needs, and admin requirements. - Async vs Sync Strategy: Rules for choosing async def versus def, plus async library selection (httpx, asyncpg, aiofiles) and the I/O-bound versus CPU-bound golden rule. - Type Hints and Validation: Patterns for typing function signatures, generics, and when to use Pydantic for runtime validation. - Project Structure and Testing: Layout principles for small scripts through large applications, background task selection (Celery, ARQ, BackgroundTasks), error handling, and pytest async testing patterns. - Use Case: You are starting a new microservices API and are unsure whether to use Django or FastAPI, whether endpoints should be async, and how to structure the codebase. This Skill walks you through the decision checklist to reach a justified architecture. ## Quick Start Ask the assistant to help you choose between FastAPI and Django for a new API project and recommend an async strategy and project structure.

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 for a new project?

Choose FastAPI for API-first microservices needing native async and Pydantic validation, 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 FastAPI?

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

FastAPI vs Django for building REST APIs, which is better?

FastAPI is generally better for API-only services due to native async support, automatic Pydantic validation, and lower overhead. Django with DRF suits projects that also need an admin panel, built-in ORM, and batteries-included features alongside the API.

Does Django support async views and ORM operations?

Django 5.0+ supports async views, async middleware, and ASGI deployment, with limited async ORM support. 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, stalling all concurrent requests. The rule is to use async libraries for I/O-bound work and keep CPU-bound work in sync code with multiprocessing, never forcing async onto CPU-heavy tasks.