본문 바로가기

전체 글

(67)
03. Fast API, Pydantic을 이용한 Type Hinting 기존의 Flask나 Django와는 달리 Fast API는 Type Hints를 사용하고 있다. Type Hints는 파라미터 값이어떤 자료형이 들어와야하는 지 코드 상에서 명시하는 것이다. 아래의 예를 보자. from pydantic import BaseModel from typing import Optional class User(BaseModel): id: int name = 'Jane Doe' age : Optional[str] = None pydantic의 BaseModel을 상속받은 User 클래스에 id 필드를 int 형식으로, name은 Default 값으로 'Jane Doe'를 주어 type annotation이 불필요하다. user = User(id='123') assert user.i..
02. Fast API 프로젝트 생성 및 실행 Installation $ pip install fastapi $ pip install uvicorn[standard] Create App from typing import Optional from fastapi import FastAPI app = FastAPI() @app.get("/") def read_root(): return {"Hello": "World"} Run $ uvicorn main:app --reload INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) INFO: Started reloader process [28720] INFO: Started server process [28722] INFO: Waiting..
01. Fast API란? https://fastapi.tiangolo.com/ Fast API는 현재 파이썬 웹 프레임워크 중 가장 빠른 것 중 하나이며, type hints를 제공한다. 주요 특징은 아래와 같다. Fast: NodeJS 및 Go와 동등한 높은 성능. 가장 빠른 Python 프레임워크 중 하나. ⇒ Starlette 및 Pydantic Fast to code Fewer bugs Intuitive Easy: 배우기 쉽고, 문서를 쉽게 읽을 수 있음 Short: 코드 중복 적음. 파라미터 정의에 다양한 기능 제공 Robust: 문서 자동화 및 쉬운 배포 Standards-based: 개방형 API 표준, JSON Schema를 기반 Automatic Documentation Fast API의 장점 중 하나는 자동으로..