Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
FastAPIで始める やまなし温泉めぐり
Search
しみず ゆうき
July 15, 2021
Programming
520
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
FastAPIで始める やまなし温泉めぐり
2021.7.15
信玄パイ LT大会 みんなの FastAPI LT
しみず ゆうき
July 15, 2021
More Decks by しみず ゆうき
See All by しみず ゆうき
技術イベントの甲府一極集中問題をオープンデータで解決してみる
yuukis
0
99
12年前のAndroidアプリを蘇らせた話
yuukis
0
74
EventBridgeで地域イベントのイベントストリームを作ってみた
yuukis
0
140
2025年 山梨の技術コミュニティを振り返る
yuukis
0
480
サイトを作ったらNFCタグキーホルダーを爆速で作れ!
yuukis
0
1.3k
Perlで痩せる
yuukis
1
930
Pythonで遊べるLEDボードの紹介
yuukis
0
170
今話題のMCPサーバーをFastAPIでサッと作ってみた
yuukis
0
730
地域ITコミュニティの活性化とAWSに移行してみた話
yuukis
0
630
Other Decks in Programming
See All in Programming
速く作れる。その次は、速く確かめられる開発へ 〜AIネイティブ開発を支える、Shift Down〜 / Can build fast. Next, moving to development where we can verify fast.
rkaga
5
4.3k
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
500
Are APIs Still Relevant in the AI Era?
soyuka
0
300
Workers Cache を知る
syumai
0
210
Heart of Swift Concurrency
koher
0
960
Java 27新機能 / Java 27 new features
kishida
2
170
20260914 AIエージェント時代のPlatform Engineering LLM基盤とプロダクトの責務境界線
kanfab1
7
2.2k
WebRTC映像をAirPlayに対応させる挑戦.pdf
monolithic_adam
0
300
Security issues being discussed on Web Platforms
petamoriken
0
1.2k
What We Talk About When We Talk About XP
m_seki
2
680
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
290
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
2.9k
Featured
See All Featured
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
280
Testing 201, or: Great Expectations
jmmastey
46
8.3k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.8k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
500
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
290
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.7k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
470
How GitHub (no longer) Works
holman
316
150k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
440
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
280
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.8k
Transcript
2021. 7. 15 ͠Έͣ Ώ͏͖ 1 ʲ৴ݰύΠ LTେձ ΈΜͳͷ FastAPIʳ
FastAPI Ͱ࢝ΊΔ ·ͳ͠ ԹઘΊ͙Γ
͓·͑୭Αʁ ͠Έͣ Ώ͏͖ • Android / iOS ϓϩάϥϚ • ࢁསੜ·Ε
ࢁསҭͪ ˞ݱࡏ౦ژʹग़Ք͗த 5 2
͡Ίʹ ઌ݄։࠵͞Εͨ৴ݰύΠͷ FastAPI ษڧձ ʮFastAPI Ͱϋδϝϧ PythonʯͰֶΜͩ͜ͱ Λࢀߟʹɺࢼ͠ʹ API Λ࡞ͯ͠Έ·ͨ͠ͷͰ
൸࿐͠·͢ ʢษڧձۀͰࢀՃͰ͖ͳ͔ͬͨͷͰɺࣗश͖ͯ͠·͠ ͨɻࢿྉͷڞ༗͋Γ͕ͱ͏͍͟͝·͢ʂʣ 3
มΘΓ·͕͢ɺ օ͞Μɺ Թઘ ͖Ͱ͔͢ʁ 4
ࢁསԹઘ͕͍ͬͺ͍ʂ • ଟ༷ͳઘ࣭ ◦ “શ෦Ͱ10छྨ͋Δઘ࣭ͷ͏ͪɺࢁསʹ9छྨͷ ઘ࣭͕͋ΓɺશࠃͰτοϓϨϕϧ” • ܠ؍ͷྑ͞ ◦ “ૣே༦Ε࣌ʹଠཅͷޫͰߚ͘છ·Δ࢜ࢁɺ
ߕຍͷ༦Ε͔ΒܠʹҠΔॠؒͷඒ͍͠ܠ ৭ɺࣗવ๛͔ͳܢ୩ඒͳͲɺ༷ʑͳܠ৭ΛԹઘʹ ਁ͔Γͳ͕Βָ͠Ή͜ͱ͕Ͱ͖·͢” 5 ग़యɿ·ͳཱͪ͠دΓඦ໊౬ ؼলͷࡍʹΑཱͪ͘دͬͯ·͢
ࢁསͷԹઘࢪઃΛฦ٫͢ΔAPI Λ FastAPIͰ࡞ͬͯΈͨ 6
ࢁསݝͷΦʔϓϯσʔλΛར༻ 7
8 PDF !!
ં֯ͳͷͰ.... PDF Λͦͷ··ϩʔυͯ͠มޙɺ FastAPI Ͱฦ٫͢ΔΑ͏࣮͠·ͨ͠ 9 Python ศརͩͳʙ
chezou/tabula-py • PDF ϑΝΠϧͷදΛ pandas ͷ DataFrame ΦϒδΣΫτʹ ม͢ΔϥΠϒϥϦ ◦
CSVɺTSVɺJSON ϑΝΠϧʹม ͢Δ͜ͱՄೳ • OCR πʔϧͰͳ͍ • Java 8 Ҏ͕߱ඞཁ 10
main.py - ᶃ PDF ಡΈࠐΈ def check_columns(df, previous_df): difference1 =
set(df.keys()) - set(previous_df.keys()) difference2 = set(previous_df.keys()) - set(df.keys()) return (len(difference1) == 0 and len(difference2) == 0) 11 def get_data(pdf_path): previous_df = pd.DataFrame() dfs = tabula.read_pdf(pdf_path, lattice=True, pages = 'all') for df in dfs: # ෳϖʔδͷදΛ݁߹͢Δ if (check_columns(df, previous_df)): df = pd.concat([previous_df, df]) previous_df = df return previous_df PDFΛಡΈࠐΈɺDataFrame Φϒ δΣΫτΛฦ٫͢Δ ෳϖʔδʹ·͕ͨΔදͷ໊߲ Λൺֱ͠ɺಉ͡ද͔Ͳ͏͔Λఆ ͢Δʢ্ͷ͔ؔΒݺΕΔʣ
main.py - ᶄ API ࡞ 12 app = FastAPI() pdf_path
= "h3012011.pdf" @app.get("/") def read_root(): data = get_data(pdf_path) json_data = data.to_json(orient = 'records') return json.loads(json_data) @app.get("/area/{area}") def read_item(area: str): data = get_data(pdf_path) df_mask = data['市町村名'] == area data = data[df_mask] json_data = data.to_json(orient = 'records') return json.loads(json_data) [get] / શ݅ฦ٫͢Δ API [get] /area/{area} ࢦఆ͞ΕͨࢢொଜͷΈฦ٫͢Δ API
Docker ͍·ͨ͠ 13 Docker Host (VPS) Nginx ϦόʔεϓϩΩγ onsen.yamanashi.dev:443 App
Container FastAPI localhost:45280 main.py ࢁསݝ WebαΠτ PDF PDF tiangolo/uvicorn-gunicorn-fastapi :python3.8-alpine3.10 ্هͷΠϝʔδΛϕʔεʹ openjdk11 ΛΠϯετʔϧ ͨ͠ͷΛ༻ ࠓճݝαΠτʹෛՙ͕͔͔Βͳ͍Α͏ɺ PDFΛࣄલʹίϯςφʹίϐʔ
DEMO 14 https://onsen.yamanashi.dev
͍͞͝ʹ 15
ࡶײɾ·ͱΊ ʮFastAPI Ͱ࢝ΊΔ ·ͳ͠ ԹઘΊ͙Γʯ • FastAPI Φʔϓϯσʔλ͔Βखܰʹ API Λ࡞͢Δͷʹྑͦ͞͏
◦ Tabula ͱΈ߹ΘͤΔ͜ͱͰɺPDF ϑΝΠϧ FastAPI ʹࡌͤΔ͜ͱ͕Մೳ ◦ PDFϑΝΠϧͷมʹ͕͔͔͍࣌ؒͬͯΔͷͰɺதؒσʔλΛอଘ͢Δͷ ͕͍Δ͔ • ͓ؾʹೖΓͷԹઘࢪઃΛථ͢Δ API ͷ࡞ೝূࢼͯ͠Έ͍ͨ • ·ͩߦͬͨ͜ͱͷͳ͍ԹઘࢪઃΛ৭ʑΕͯྑ͔ͬͨʂ 16
ʲิʳ࠷ۙ ͓ؾʹೖΓͷؼΓԹઘ ᶃΈ͔͞ͷ౬ ԘαφͰ͓ഽεϕεϕʹʂ ᶄ࡚ѴԹઘ ମʹͼͬ͠Γ͘๐ͷࢎԹઘ ᶅ૿ͷ౬ ԹͷݯઘͰ࣌ؒΏͬ͘Γਁ͔ΕΔ 17 ΦεεϝͷԹઘࢪઃ͕͋ͬͨΒ
ੋඇڭ͍͑ͯͩ͘͞ʂ