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
130
12年前のAndroidアプリを蘇らせた話
yuukis
0
81
EventBridgeで地域イベントのイベントストリームを作ってみた
yuukis
0
150
2025年 山梨の技術コミュニティを振り返る
yuukis
0
520
サイトを作ったらNFCタグキーホルダーを爆速で作れ!
yuukis
0
1.3k
Perlで痩せる
yuukis
1
940
Pythonで遊べるLEDボードの紹介
yuukis
0
180
今話題のMCPサーバーをFastAPIでサッと作ってみた
yuukis
0
770
地域ITコミュニティの活性化とAWSに移行してみた話
yuukis
0
660
Other Decks in Programming
See All in Programming
複雑なUIコンポーネントとの ⻑い付き合い⽅:波及するバグからテスト戦略を経て、安全な再設計へ
mixplace
0
460
AIで開発が速くなった先で、開発チームは何を目指すか
shihochan
1
1.8k
Optunaを作ったときにやりたかったこと、その後 (2026/10/16, Optuna Meetup #3)
iwiwi
4
1.3k
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
35
17k
Apple Intelligenceとオンデバイス時代の到来
yahir0
0
150
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Kaigi on Rails 2026, Tokyo, Japan
marcoroth
2
340
学びを記事・スライド・Xへ高速展開する― AI-assisted Learning Loopで回すコンテンツ生成術
ochtum
0
150
golang-bob.pdf
iwatsukayura
0
140
SFCで実現する病院・医療システムの動的組み立て式UI
koukimiura
1
120
phperだってパンチカードでコーディングしたい
o0h
PRO
0
460
Coding with AI: How to trust the storyteller (AWS Community Day Adria, Ljubljana 2026)
slobodan
0
120
見えないものを探る要求要件定義に必要な基本的思考 / invisible-requirement-thinking
minodriven
15
8.8k
Featured
See All Featured
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.2k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
650
Mobile First: as difficult as doing things right
swwweet
225
10k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
330
SEO for Brand Visibility & Recognition
aleyda
0
4.8k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
610
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
710
Building an army of robots
kneath
307
47k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
310
How to make the Groovebox
asonas
2
2.5k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
500
The SEO Collaboration Effect
kristinabergwall1
1
600
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 ΦεεϝͷԹઘࢪઃ͕͋ͬͨΒ
ੋඇڭ͍͑ͯͩ͘͞ʂ