Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
たのしい FastAPI
Search
kimihiro_n
May 08, 2020
Programming
1
16k
たのしい FastAPI
社内勉強会用につくった FastAPI の布教資料です。
書けなかった内容は改めて会社ブログに書く予定です。
kimihiro_n
May 08, 2020
Tweet
Share
More Decks by kimihiro_n
See All by kimihiro_n
サービスへの影響を抑えてデータベースの移行を実施したはなしAurora MySQL -> Cloud SQL
pistatium
0
1.2k
新しいメンバーに Make debut してもらいやすくするための開発体制 with Python
pistatium
1
3.4k
すっきり分かる Python のログ
pistatium
6
2.9k
Other Decks in Programming
See All in Programming
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
220
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
340
useSyncExternalStoreを使いまくる
ssssota
6
1.1k
たのしいparse.y
ydah
3
120
バグを見つけた?それAppleに直してもらおう!
uetyo
0
180
Monixと常駐プログラムの勘どころ / Scalaわいわい勉強会 #4
stoneream
0
280
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
120
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
140
php-conference-japan-2024
tasuku43
0
310
情報漏洩させないための設計
kubotak
2
250
創造的活動から切り拓く新たなキャリア 好きから始めてみる夜勤オペレーターからSREへの転身
yjszk
1
130
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
Music & Morning Musume
bryan
46
6.2k
Automating Front-end Workflow
addyosmani
1366
200k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Fireside Chat
paigeccino
34
3.1k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Transcript
ͨͷ͍͠ രͰͭ͘ΕͯɺAPI༷ॻʹͳΔʂ @kimihiro_n 3μΠδΣετ൛
Hello FastAPI
FastAPI Ͱ HelloWorld from fastapi import FastAPI app = FastAPI()
@app.get("/") def hello(): return {"Hello": "World"} $ pip install fastapi uvicorn $ uvicorn main:app --reload ref. https://fastapi.tiangolo.com/
Hello World
FastAPIͷԿ͕͏Ε͍͔͠ • FlaskʹࣅͨγϯϓϧͳViewఆٛ • ϗοτϦϩʔυରԠ • ϦΫΤετɾϨεϙϯεͷܕఆٛ • υΩϡϝϯτࣗಈੜ •
ඇಉظ(asyncio)ରԠ
FastAPI Ͱܕఆٛ
FastAPI Ͱ ܕΛ͚ͭΔ from fastapi import FastAPI from pydantic import
BaseModel app = FastAPI() class Response(BaseModel): hello: str @app.get("/", response_model=Response) def hello(): return Response(hello="world")
FastAPI Ͱ ܕΛ͚ͭΔ from fastapi import FastAPI from pydantic import
BaseModel app = FastAPI() class Response(BaseModel): hello: str @app.get("/", response_model=Response) def hello(): return Response(hello="world") ϨεϙϯεͷܕΛఆٛ
FastAPI Ͱ ܕΛ͚ͭΔ from fastapi import FastAPI from pydantic import
BaseModel app = FastAPI() class Response(BaseModel): hello: str @app.get("/", response_model=Response) def hello(): return Response(hello="world") View ͷϨεϙϯε͕ ͜ͷܕͰ͋Δ͜ͱΛએݴ
FastAPI Ͱ ܕΛ͚ͭΔ from fastapi import FastAPI from pydantic import
BaseModel app = FastAPI() class Response(BaseModel): hello: str @app.get("/", response_model=Response) def hello(): return Response(hello="world") σʔλΛೖΕͯ ͦͷ··ฦ͢
ܕఆٛͰԿ͕ى͜Δͷ͔ • ࣙॻΛ͔ͭΘͳ͍҆શͳίʔσΟϯά • ϨεϙϯεͷܕͷνΣοΫ ◦ ܕ͕Ϛον͠ͳ͍߹Τϥʔʹ ◦ ͪΖΜϦΫΤετͷόϦσʔγϣϯ •
API υΩϡϝϯτө
API ఆٛͷࣗಈੜ
• APIͷୟ͖ํ͕Θ͔Βͳ͍ • APIఆٛͱϨεϙϯε͕߹ͬͯͳ͍ • ࠷৽ͷ༷ʹैͯ͠ͳ͍ • OpenAPI(Swagger)ͷYAML ਓྨ͕ॻ͘ͷ͡Όͳ͍ อक͕େม
APIυΩϡϝϯτͷΈ
Ͱ FastAPIͳΒ…ʁ
/doc ΞΫηε
OpenAPI ͷ༷ॻ͕ࣗಈੜ • ༷ͱ࣮͕ৗʹಉظ ◦ લड़ͷ௨ΓܕνΣοΫ͋ΔͷͰ҆৺ • SwaggerUI ্ͰAPIୟ͍ͯಈ࡞֬ೝͰ͖Δ •
ຊ൪ڥͰແޮԽ͢Δ͜ͱՄೳ
ຊʹඞཁͩͬͨͷ
• router ʹΑΔ View ϑΝΠϧׂ • asyncio ʹΑΔඇಉظॲཧ • middleware
Ͱڞ௨ͷॲཧΛՃ • Dependency ʹΑΔґଘೖ • 200 Ҏ֎ͷϨεϙϯεͷఆٛ ॻ͚ͳ͔ͬͨ͜ͱ ଓ͖ Web Ͱ(Ծ)
ThankYou!