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
pydanticの紹介
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
mizzsugar
February 13, 2020
Programming
700
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
pydanticの紹介
mizzsugar
February 13, 2020
More Decks by mizzsugar
See All by mizzsugar
自分のPCにPython環境を用意して_VSCodeでStreamlitアプリを動かすまでの8ステップ.pdf
mizzsugar
0
96
Colabのみで初心者向けPythonハンズオン.pdf
mizzsugar
0
78
厳しさとゆるさの間で迷う人に捧げる個人開発記
mizzsugar
0
73
SQLModel入門〜クエリと型〜
mizzsugar
3
1.6k
フルリモート向いてないと思っていた私が、なんだかんだ健やかに 1年半フルリモート出来ている話
mizzsugar
1
160
Djangoでのプロジェクトだって型ヒントを運用出来る!
mizzsugar
4
9.1k
「動くものは作れる」の一歩先へ 〜「自走プログラマー」の紹介〜
mizzsugar
0
660
pytestの第一歩 〜「テスト駆動Python」の紹介〜
mizzsugar
3
490
データ分析ツール開発でpoetryを使う選択肢
mizzsugar
1
1.2k
Other Decks in Programming
See All in Programming
書籍「プロフェッショナルAI駆動開発」紹介スライド
juntaromatsumoto
0
770
Cloudflare is Agents
chimame
0
180
AI駆動開発にグラフDBを重ねてみた
satoshi256kbyte
0
360
S3 を使うアプリケーションをローカル完結で動かすことに全力を注いでみた / Running S3 Apps Offline
contour_gara
0
660
仕様駆動開発へのトライを機に チームに適合する手法を模索し続けている話
freee
PRO
0
640
tsc.rip を支える技術 / Kyoto.なんか #8
susisu
0
3.8k
複数の Claude Code が"放置"されてしまう問題をCLI ダッシュボードを自作して解決した話
sumihiro3
1
740
Press start. Python's next generation.
willingc
PRO
3
250
ソフトウェアラスタライザ
fadis
1
720
freee が目指す データ マネジメント戦略 AI-Ready 時代を支える 攻めのガバナンスとは
freee
PRO
0
520
進化を続けるGo toolsの現在地 / The Current State of Ever-Evolving Go Tools
hond0413
0
270
Go 1.27からのGODEBUG / Go 1.27 リリースパーティ #go127party
mazrean
0
250
Featured
See All Featured
Claude Code のすすめ
schroneko
67
230k
Building an army of robots
kneath
306
46k
The Limits of Empathy - UXLibs8
cassininazir
1
620
Faster Mobile Websites
deanohume
310
32k
Everyday Curiosity
cassininazir
0
300
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
550
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
950
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
390
Designing for humans not robots
tammielis
254
26k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
480
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
430
Transcript
今いち推しのバリデーター pydanticの紹介 20200213 Stapy @mizzsugar0424
お前、誰よ • Twitter : @mizzsugar0425 • 仕事:データ分析基盤の開発、運用 ◦ GCP, BigQuery
• 前の仕事はDjango。今でも追いかけてる。 • 趣味:PythonでWeb開発 ◦ Pyramid, Nuxt.js, TypeScript, PostgreSQL • 2/29にPyCon mini Shizuokaに登壇予定 ◦ unittest.mockの話です • ゆるく転職活動 ◦ 面接中に水をガブガブ飲む人間でも良いという企業様、ぜひ
# type: ignore
それは、 静的型付けとPythonの両方を 愛する者たちを苦しめる コメント
従来のバリデーターだとTypingのサポートがない import colander class Item(colander.MappingSchema): # type: ignore name =
colander.SchemaNode(colander.String()) price = colander.SchemaNode(colander.Integer())
Typingサポートのあるバリデーター、pydantic • 2017年爆誕 • Typingサポートあり • Python製WebフレームワークFastAPIでも紹介されている • mypy pluginあり
https://pydantic-docs.helpmanual.io/
基本的な書き方 import pydantic class Item(pydantic.BaseModel): name: str price: int
基本的な書き方 external_data = { 'name': 'chocolate', 'price': 500 } try:
item = Item(**external_data) except ValueError e: e.json() # エラー内容が返される
まるでオブジェクトを扱うよう class User(pydantic.BaseModel): name: str birthday: datetime.date friends: List[int] favorite_color:
Optional[str] int, str, List, Optional, datetime… などわりと使う型はサポートされている
楽々json! user = User.parse_raw('{"id": 123,"signup_ts":1234567890,"name":"John Doe"}') print(user) #> id=123 signup_ts=datetime.datetime(2009,
2, 13, 23, 31, 30, #> tzinfo=datetime.timezone.utc) name='John Doe'
快く使うために: mypy pluginのページは読んでね error: Module 'pydantic' has no attribute 'BaseModel'
[attr-defined] ↑mypy から注意されたけど ドキュメントのmypy pluginの設定を追加したら解消されたので 良く読もう https://pydantic-docs.helpmanual.io/mypy_plugin/
さらば、 # type: ignore
ありがとうございました。