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
17k
1
Share
たのしい FastAPI
社内勉強会用につくった FastAPI の布教資料です。
書けなかった内容は改めて会社ブログに書く予定です。
kimihiro_n
May 08, 2020
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.8k
すっきり分かる Python のログ
pistatium
6
3.1k
Other Decks in Programming
See All in Programming
Running Swift without an OS
kishikawakatsumi
0
850
クラウドネイティブなエンジニアに向ける Raycastの魅力と実際の活用事例
nealle
2
220
Swift Concurrency Type System
inamiy
1
540
AIと共に生きる技術選定 2026
sgash708
0
110
VueエンジニアがReactを触って感じた_設計の違い
koukimiura
0
180
AIエージェントで業務改善してみた
taku271
0
540
2026_04_15_量子計算をパズルとして解く
hideakitakechi
0
110
HTML-Aware ERB: The Path to Reactive Rendering @ RubyKaigi 2026, Hakodate, Japan
marcoroth
0
180
Kingdom of the Machine
yui_knk
2
850
アーキテクチャモダナイゼーションとは何か
nwiizo
19
5.4k
アクセシビリティ試験の"その後"を仕組み化する
yuuumiravy
1
170
Kubernetes上でAgentを動かすための最新動向と押さえるべき概念まとめ
sotamaki0421
3
630
Featured
See All Featured
Code Reviewing Like a Champion
maltzj
528
40k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.9k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
170
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
280
The Curse of the Amulet
leimatthew05
1
11k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.6k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.5k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
100
Ruling the World: When Life Gets Gamed
codingconduct
0
210
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.2k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Speed Design
sergeychernyshev
33
1.6k
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!