Community코딩 & 개발github.com

mindrally/fastapi-python

FastAPI Python 개발 전문가: API 및 비동기 작업을 위한 모범 사례 제공

fastapi-python란 무엇인가요?

이 스킬은 FastAPI Python 개발에 특화된 AI 에이전트를 위한 것입니다. FastAPI의 강력한 기능인 비동기(async) 지원, 자동 API 문서화(Swagger/OpenAPI), Pydantic 기반 데이터 검증 등을 활용하여 고성능 RESTful API를 구축하는 방법을 안내합니다. 또한 의존성 주입, 라우팅, 미들웨어, 예외 처리 등 FastAPI의 핵심 개념과 함께 SQLAlchemy, Alembic, pytest 등을 이용한 데이터베이스 통합 및 테스트 전략도 포함됩니다. 이 스킬을 통해 개발자는 모범 사례를 적용한 견고하고 확장 가능한 FastAPI 애플리케이션을 빠르게 설계하고 구현할 수 있습니다.

지원 대상~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/mindrally/skills/tree/main/skills/fastapi-python

Installed? Explore more 코딩 & 개발 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

즐겨 사용하는 AI에게 물어보기

이 에이전트 스킬이 미리 로드된 새 채팅을 엽니다.

문서

fastapi-python은(는) 무엇을 하나요?

FastAPI Python 개발 전문가: API 및 비동기 작업을 위한 모범 사례 제공

개요

이 스킬은 FastAPI 프레임워크를 사용하여 Python으로 웹 API를 개발하는 AI 에이전트를 위한 것입니다. FastAPI의 주요 기능과 모범 사례를 활용하여 고성능, 확장 가능한 API를 구축하는 방법을 제공합니다.

주요 특징

  • 비동기 지원: async def를 사용한 비동기 엔드포인트 작성
  • 자동 문서화: Swagger UI 및 ReDoc을 통한 대화형 API 문서 자동 생성
  • 데이터 검증: Pydantic 모델을 이용한 요청/응답 데이터 검증
  • 의존성 주입: 의존성 주입 시스템을 통한 모듈성 향상
  • 타입 힌트: Python 타입 힌트를 활용한 코드 안정성 보장

시작하기

설치

pip install fastapi uvicorn

기본 예제

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
async def root():
    return {"message": "Hello World"}

서버 실행

uvicorn main:app --reload

엔드포인트 정의

FastAPI는 다양한 HTTP 메서드를 지원합니다:

  • @app.get(): GET 요청
  • @app.post(): POST 요청
  • @app.put(): PUT 요청
  • @app.delete(): DELETE 요청
  • @app.patch(): PATCH 요청

경로 매개변수와 쿼리 매개변수

from fastapi import FastAPI

app = FastAPI()


@app.get("/items/{item_id}")
async def read_item(item_id: int, q: str = None):
    return {"item_id": item_id, "q": q}

요청 본문

Pydantic 모델을 사용하여 요청 본문을 정의합니다:

from pydantic import BaseModel


class Item(BaseModel):
    name: str
    price: float
    is_offer: bool = False


@app.post("/items/")
async def create_item(item: Item):
    return item

의존성 주입

의존성 주입을 통해 코드의 재사용성과 테스트 용이성을 높입니다:

from fastapi import Depends, FastAPI

app = FastAPI()


def get_db():
    db = Database()
    try:
        yield db
    finally:
        db.close()


@app.get("/users/")
async def read_users(db=Depends(get_db)):
    return db.get_users()

데이터베이스 통합

SQLAlchemy와 함께 사용하는 방법:

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

SQLALCHEMY_DATABASE_URL = "sqlite:///./test.db"
engine = create_engine(SQLALCHEMY_DATABASE_URL)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

테스트

FastAPI는 TestClient를 제공하여 간편한 테스트를 지원합니다:

from fastapi.testclient import TestClient

client = TestClient(app)


def test_read_main():
    response = client.get("/")
    assert response.status_code == 200
    assert response.json() == {"message": "Hello World"}

배포

Uvicorn, Gunicorn, 또는 Docker를 사용하여 배포할 수 있습니다:

uvicorn main:app --host 0.0.0.0 --port 8000

추가 자료

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

mindrally/accessibility-a11y

Implement web accessibility (a11y) best practices following WCAG guidelines to create inclusive, accessible user interfaces.

mindrally/chrome-extension-development

Expert guidelines for Chrome extension development with Manifest V3, covering security, performance, and best practices. Use when building browser extensions, creating popup UIs, implementing content scripts, working with Chrome APIs, managing extension permissions, or publishing to Chrome Web Store.

mindrally/computer-vision-opencv

Expert guidance for computer vision development using OpenCV, PyTorch, and modern deep learning techniques for image and video processing.

mindrally/data-analysis-jupyter

Expert guidance for data analysis, visualization, and Jupyter Notebook development with pandas, matplotlib, seaborn, and numpy.

mindrally/deep-learning-pytorch

Expert guidance for deep learning, transformers, diffusion models, and LLM development with PyTorch, Transformers, Diffusers, and Gradio.

mindrally/expo-react-native-typescript

Expert in Expo React Native TypeScript mobile development with best practices

mindrally/framer-motion

Expert guidelines for building performant animations with Framer Motion/Motion library in React applications

mindrally/htmx

HTMX development guidelines for building dynamic web applications with minimal JavaScript using HTML attributes.

mindrally/jwt-security

Guidelines for implementing JWT authentication with security best practices for token creation, validation, and storage

mindrally/machine-learning

Machine learning development with JAX, functional programming patterns, and high-performance computing.

mindrally/mysql-best-practices

MySQL development best practices for schema design, query optimization, and database administration

mindrally/nextjs-react-typescript

Expert in TypeScript, Node.js, Next.js App Router, React, Shadcn UI, Radix UI and Tailwind

mindrally/nextjs-typescript-tailwindcss-supabase

Full-stack Next.js 14 development with TypeScript, TailwindCSS, and Supabase for building production-ready web applications.

mindrally/odoo-development

Expert guidance for Odoo ERP development including Python ORM, XML views, and module architecture

mindrally/puppeteer-automation

Expert guidance for browser automation using Puppeteer with best practices for web scraping, testing, screenshot capture, and JavaScript execution in headless Chrome.

mindrally/redis-best-practices

Redis development best practices for caching, data structures, and high-performance key-value operations

mindrally/scrapy-web-scraping

Expert guidance for building web scrapers and crawlers using the Scrapy Python framework with best practices for spider development, data extraction, and pipeline management.

mindrally/scss-best-practices

SCSS/Sassy CSS best practices and coding guidelines for maintainable, scalable stylesheets

mindrally/typeorm

Guidelines for developing with TypeORM, a full-featured ORM for TypeScript and JavaScript supporting multiple databases

mindrally/web-scraping

Expert in web scraping and data extraction with Python tools

관련 스킬