본문 바로가기

Fastapi

(13)
내맘대로 Fastapi Document summary[5] # You only give Depends a single parameter. # This parameter must be something like a function. # async 안에 def or def 안에 async 다 가능 from typing import Optional from fastapi import Depends, FastAPI app = FastAPI() async def common_parameters(q: Optional[str] = None, skip: int = 0, limit: int = 100): return {"q": q, "skip": skip, "limit": limit} @app.get("/items/") async def read_items(commons: di..
내맘대로 Fastapi Document summary[4] @app.get("/users/", tags=["users"] summary="Create an item", description="", response_description="" deprecated=True, ) async def read_users(): return [{"username": "johndoe"}] # tags, summary, description, response_description, deprecated 등은 docs swagger에 보여준다. # description이 너무 길 경우 @app.post("/items/", response_model=Item, summary="Create an item") async def create_item(item: Item): """ Creat..
내맘대로 Fastapi Document summary[3] $ pip install python-multipart from fastapi import FastAPI, File, UploadFile app = FastAPI() @app.post("/files/") async def create_file(file: bytes = File(...)): return {"file_size": len(file)} @app.post("/uploadfile/") async def create_upload_file(file: UploadFile = File(...)): return {"filename": file.filename} # To declare File bodies, you need to use File, because otherwise # the parameters ..
내맘대로 Fastapi docs 정리(Response Model, Extra Model) from typing import Optional from fastapi import FastAPI from pydantic import BaseModel, EmailStr app = FastAPI() class UserIn(BaseModel): username: str password: str email: EmailStr full_name: Optional[str] = None class UserOut(BaseModel): username: str email: EmailStr full_name: Optional[str] = None @app.post("/user/", response_model=UserOut) async def create_user(user: UserIn): return user use..
내맘대로 Fastapi docs 정리(Path, query parameters, request body) Fastapi document를 보고 메모하는 블로그입니다. fastapi document : https://fastapi.tiangolo.com/ FastAPI FastAPI FastAPI framework, high performance, easy to learn, fast to code, ready for production Documentation: https://fastapi.tiangolo.com Source Code: https://github.com/tiangolo/fastapi FastAPI is a modern, fast (high-performance), web framework for buil fastapi.tiangolo.com my_awesome_api=FastAPI() in m..