{"id":615,"date":"2026-07-25T05:56:25","date_gmt":"2026-07-24T20:56:25","guid":{"rendered":"https:\/\/www.marchboy.xyz\/wordpress\/archives\/615"},"modified":"2026-07-25T05:56:25","modified_gmt":"2026-07-24T20:56:25","slug":"pydantic%e3%82%b9%e3%82%ad%e3%83%bc%e3%83%9e%e3%81%a8%e3%81%af%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.marchboy.xyz\/wordpress\/archives\/615","title":{"rendered":"Pydantic\u30b9\u30ad\u30fc\u30de\u3068\u306f\uff1f"},"content":{"rendered":"<h2>Pydantic\u30b9\u30ad\u30fc\u30de\u3068\u306f<\/h2>\n<p>Pydantic\u306fPython\u3067\u30c7\u30fc\u30bf\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3068\u8a2d\u5b9a\u7ba1\u7406\u3092\u884c\u3046\u305f\u3081\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002\u305d\u306e\u6838\u5fc3\u6a5f\u80fd\u3067\u3042\u308b<strong>\u30b9\u30ad\u30fc\u30de<\/strong>\u306f\u3001\u30c7\u30fc\u30bf\u69cb\u9020\u3092\u30af\u30e9\u30b9\u3068\u3057\u3066\u5b9a\u7fa9\u3057\u3001\u578b\u30c1\u30a7\u30c3\u30af\u3084\u5909\u63db\u3001\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u81ea\u52d5\u3067\u884c\u3044\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001API\u306e\u30ea\u30af\u30a8\u30b9\u30c8\/\u30ec\u30b9\u30dd\u30f3\u30b9\u3084\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306a\u3069\u3001\u5916\u90e8\u30c7\u30fc\u30bf\u3068\u306e\u3084\u308a\u53d6\u308a\u3092\u5b89\u5168\u304b\u3064\u7c21\u6f54\u306b\u5b9f\u88c5\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3>\u4e3b\u306a\u7279\u5fb4<\/h3>\n<ul>\n<li>Python\u306e\u578b\u30d2\u30f3\u30c8\u3092\u305d\u306e\u307e\u307e\u5229\u7528\u3067\u304d\u308b<\/li>\n<li>\u5ba3\u8a00\u7684\u306b\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30ed\u30b8\u30c3\u30af\u3092\u8a18\u8ff0\u53ef\u80fd<\/li>\n<li>\u30c7\u30fc\u30bf\u306e\u81ea\u52d5\u5909\u63db\uff08\u4f8b: \u6587\u5b57\u5217 \u2192 datetime\uff09<\/li>\n<li>\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u304c\u8a73\u7d30\u304b\u3064\u69cb\u9020\u5316\u3055\u308c\u3066\u3044\u308b<\/li>\n<li>\u9ad8\u901f\u306a\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\uff08Cython\u30d9\u30fc\u30b9\u306e\u5b9f\u88c5\uff09<\/li>\n<\/ul>\n<h3>\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9<\/h3>\n<p>\u307e\u305a\u306fPydantic\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002<\/p>\n<pre><code>pip install pydantic<\/code><\/pre>\n<p>\u6b21\u306b\u3001<code>BaseModel<\/code>\u3092\u7d99\u627f\u3057\u305f\u30af\u30e9\u30b9\u3092\u5b9a\u7fa9\u3057\u307e\u3059\u3002<\/p>\n<pre><code>from pydantic import BaseModel, EmailStr\nfrom datetime import datetime\n\nclass User(BaseModel):\n    id: int\n    name: str\n    email: EmailStr\n    joined_at: datetime = datetime.utcnow()\n\n# \u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3068\u5909\u63db\u306e\u4f8b\ninput_data = {\n    \"id\": \"123\",\n    \"name\": \"Taro Yamada\",\n    \"email\": \"taro@example.com\"\n}\n\nuser = User(**input_data)\nprint(user)\n<\/code><\/pre>\n<p>\u4e0a\u8a18\u306e\u3088\u3046\u306b\u3001<code>id<\/code>\u306f\u6587\u5b57\u5217\u3067\u6e21\u3055\u308c\u307e\u3057\u305f\u304c\u3001<code>int<\/code>\u3078\u81ea\u52d5\u5909\u63db\u3055\u308c\u3001<code>joined_at<\/code>\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u73fe\u5728\u6642\u523b\u304c\u8a2d\u5b9a\u3055\u308c\u307e\u3059\u3002\u307e\u305f\u3001<code>EmailStr<\/code>\u306f\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u5f62\u5f0f\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3057\u307e\u3059\u3002<\/p>\n<h3>\u30cd\u30b9\u30c8\u3057\u305f\u30b9\u30ad\u30fc\u30de<\/h3>\n<p>\u8907\u96d1\u306a\u30c7\u30fc\u30bf\u69cb\u9020\u3082\u3001\u30b9\u30ad\u30fc\u30de\u3092\u5165\u308c\u5b50\u306b\u3059\u308b\u3053\u3068\u3067\u7c21\u6f54\u306b\u5b9a\u7fa9\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre><code>class Address(BaseModel):\n    street: str\n    city: str\n    zip_code: str\n\nclass UserProfile(BaseModel):\n    user: User\n    address: Address\n\nprofile_data = {\n    \"user\": {\"id\": 1, \"name\": \"Hanako\", \"email\": \"hanako@example.com\"},\n    \"address\": {\"street\": \"1-2-3 Sakura\", \"city\": \"Tokyo\", \"zip_code\": \"100-0001\"}\n}\n\nprofile = UserProfile(**profile_data)\nprint(profile)\n<\/code><\/pre>\n<p>\u3053\u306e\u3088\u3046\u306b\u3001Pydantic\u30b9\u30ad\u30fc\u30de\u306f\u5165\u308c\u5b50\u69cb\u9020\u3067\u3082\u540c\u69d8\u306b\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3068\u5909\u63db\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n<h3>\u8a2d\u5b9a\u7ba1\u7406\u3078\u306e\u5fdc\u7528<\/h3>\n<p>\u74b0\u5883\u5909\u6570\u3084\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3080\u969b\u306b\u3082\u3001Pydantic\u306e<code>BaseSettings<\/code>\u3092\u6d3b\u7528\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre><code>from pydantic import BaseSettings\n\nclass Settings(BaseSettings):\n    debug: bool = False\n    database_url: str\n\n    class Config:\n        env_file = \".env\"\n\nsettings = Settings()\nprint(settings.debug, settings.database_url)\n<\/code><\/pre>\n<p><code>.env<\/code> \u30d5\u30a1\u30a4\u30eb\u306b\u8a18\u8ff0\u3055\u308c\u305f\u8a2d\u5b9a\u304c\u81ea\u52d5\u3067\u8aad\u307f\u8fbc\u307e\u308c\u3001\u578b\u5909\u63db\u3068\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u304c\u9069\u7528\u3055\u308c\u307e\u3059\u3002<\/p>\n<h3>\u307e\u3068\u3081<\/h3>\n<ul>\n<li>Pydantic\u30b9\u30ad\u30fc\u30de\u306fPython\u306e\u578b\u30d2\u30f3\u30c8\u3092\u6d3b\u7528\u3057\u305f\u30c7\u30fc\u30bf\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306e\u4e2d\u5fc3\u6982\u5ff5\u3067\u3059\u3002<\/li>\n<li>\u30b7\u30f3\u30d7\u30eb\u306a\u5ba3\u8a00\u3067\u81ea\u52d5\u5909\u63db\u30fb\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u304c\u884c\u308f\u308c\u3001\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3082\u5206\u304b\u308a\u3084\u3059\u3044\u3067\u3059\u3002<\/li>\n<li>\u30cd\u30b9\u30c8\u69cb\u9020\u3084\u8a2d\u5b9a\u7ba1\u7406\u306b\u3082\u67d4\u8edf\u306b\u5bfe\u5fdc\u3067\u304d\u3001FastAPI\u306a\u3069\u306e\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3068\u7d44\u307f\u5408\u308f\u305b\u3066\u9ad8\u54c1\u8cea\u306aAPI\u3092\u69cb\u7bc9\u3067\u304d\u307e\u3059\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Pydantic\u30b9\u30ad\u30fc\u30de\u3068\u306f Pydantic\u306fPython\u3067\u30c7\u30fc\u30bf\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3068\u8a2d\u5b9a\u7ba1\u7406\u3092\u884c\u3046\u305f\u3081\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002\u305d\u306e\u6838\u5fc3\u6a5f\u80fd\u3067\u3042\u308b\u30b9\u30ad\u30fc\u30de\u306f\u3001\u30c7\u30fc\u30bf\u69cb\u9020\u3092\u30af\u30e9\u30b9\u3068\u3057\u3066\u5b9a\u7fa9\u3057\u3001\u578b\u30c1\u30a7\u30c3\u30af\u3084\u5909\u63db\u3001\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u81ea\u52d5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-615","post","type-post","status-publish","format-standard","hentry","category-web"],"_links":{"self":[{"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/posts\/615","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/comments?post=615"}],"version-history":[{"count":0,"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/posts\/615\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/media?parent=615"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/categories?post=615"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/tags?post=615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}