본문 바로가기

개발

Fast API 업데이트 소식 (0.60.0 ~ 0.64.0)

반응형

Fast API의 최근 주요 업데이트 소식을 요약해서 알려드립니다.

0.60.2

  • Async 테스트 관련 문서를 추가했습니다.(#1691)
  • python-multipart를 설치하지 않고 form 데이터 (Form, File)을 사용할 때 예외를 발생시킵니다. (#1851)
  • 응답을 serialize 해주는 jsonable\_encode의 로직은 단순화하고 개선했습니다.(#1754)
  • Jinja templates 예제 개선 (#1690)

0.61.0

  • HTTPConnection (Request, Websocket)을 dependency injection할 수 있는 기능을 추가합니다. 이 덕분에 dependencies에서 app의 상태를 공유할 수 있습니다. (#1827)
  • WebSocketDisconnect 예외를 핸들링 할 수 있습니다. 관련 문서도 추가했습니다. (#1822)
  • Test-Drivend Development with FastAPI and Docker 문서에 대한 링크를 추가합니다. (#1860)

0.62.0

  • FastAPI, APIRouterinclude_router에서 최상위 매개 변수(dependencies, tag 등)를 설정할 수 있습니다. (#2434)
    • 아래와 같이 FastAPI에 공유 dependency를 추가할 수 있습니다.
# in FastAPI

from fastapi import FastAPI, Depends

async def some_dependency():
     return

app = FastAPI(dependencies=[Depends(some_dependency)])
# in APIRouter

from fastapi import APIRouter, Depends

async def some_dependency():
    return

router = APIRouter(prefix="/users", dependencies=[Depends(some_dependency)])

0.64.0

  • OpenAPI에서 examples를 여러 개 추가할 수 있습니다. (저는 example을 추가할 수 있다는 것도 이제 알게 됐네요.) 아래 문서를 참고해주세요. (#1267)

from typing import Optional

from fastapi import Body, FastAPI
from pydantic import BaseModel

app = FastAPI()


class Item(BaseModel):
    name: str
    description: Optional[str] = None
    price: float
    tax: Optional[float] = None


@app.put("/items/{item_id}")
async def update_item(
    *,
    item_id: int,
    item: Item = Body(
        ...,

        examples={

            "normal": {

                "summary": "A normal example",

                "description": "A **normal** item works correctly.",

                "value": {

                    "name": "Foo",

                    "description": "A very nice Item",

                    "price": 35.4,

                    "tax": 3.2,

                },

            },

            "converted": {

                "summary": "An example with converted data",

                "description": "FastAPI can convert price `strings` to actual `numbers` automatically",

                "value": {

                    "name": "Bar",

                    "price": "35.4",

                },

            },

            "invalid": {

                "summary": "Invalid data is rejected with an error",

                "value": {

                    "name": "Baz",

                    "price": "thirty five point four",

                },

            },

        },

    ),
):
    results = {"item_id": item_id, "item": item}
    return results

Exxamples in the docs UI

이상입니다. 다음에도 주요 업데이트를 요약해서 알려드리겠습니다. 감사합니다 :)

참조

반응형