{
 "kind": "tool",
 "slug": "pydantic",
 "path": "tools/pydantic/",
 "name": "Pydantic",
 "maker": null,
 "density": "full",
 "crumbs": [
  [
   "Tools",
   "tools/"
  ],
  [
   "Forms, validation and schemas",
   "tools/forms-validation/"
  ]
 ],
 "lead": "Check incoming data in Python apps.",
 "chips": [
  {
   "label": "Forms, validation and schemas",
   "path": "tools/forms-validation/"
  },
  {
   "label": "PYPI"
  }
 ],
 "primary": {
  "label": "Copy install command",
  "copy": "pip install pydantic"
 },
 "links": [
  {
   "label": "GitHub",
   "href": "https://github.com/pydantic/pydantic"
  },
  {
   "label": "Website",
   "href": "https://github.com/pydantic/pydantic"
  }
 ],
 "track": "New versions, deprecation and license changes on your dashboard",
 "verdicts": [
  {
   "key": "license",
   "label": "License",
   "value": "MIT",
   "status": "yes",
   "sub": "Use it in paid apps",
   "quote": "to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software",
   "note": "MIT allows use in paid and closed-source products.",
   "src": "https://github.com/pydantic/pydantic/blob/main/LICENSE"
  },
  {
   "key": "maint",
   "label": "Maintained",
   "value": "Maintained",
   "status": "yes",
   "sub": "Last change Nov 23, 2026",
   "note": "Latest GitHub release Nov 19, 2026. ",
   "src": "https://github.com/pydantic/pydantic"
  },
  {
   "key": "pop",
   "label": "Used by agents' projects",
   "value": "538 projects",
   "status": "info",
   "sub": "#3 of 63 in its category",
   "note": "Dependency in 538 public GitHub projects set up for AI coding agents that we scanned (8.6%).",
   "src": null
  },
  {
   "key": "agent",
   "label": "Agent access",
   "value": "Docs for agents",
   "status": "yes",
   "sub": "llms.txt",
   "note": "Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.",
   "src": "https://pydantic.dev/docs/validation/llms.txt"
  }
 ],
 "vfoot": "From the package registry and GitHub, checked daily; card checked Nov 10, 2026.",
 "blocks": [
  {
   "id": "overview",
   "nav": "Overview",
   "h2": "What Pydantic does",
   "parts": [
    {
     "t": "prose",
     "text": "Pydantic is a free Python library that checks data before your app uses it. You describe what a sign-up form, a file or a reply from another service should look like. Pydantic accepts the data, fixes simple things like the text \"34\" into the number 34, or lists exactly what is wrong. Many Python tools, including FastAPI, are built on it."
    },
    {
     "t": "h3",
     "text": "What people build with it"
    },
    {
     "t": "uses",
     "items": [
      {
       "title": "Check sign-up forms before saving",
       "text": "A new user types a name, an email and an age; your app saves only data that fits and shows a clear message for each wrong field.",
       "idea": false
      },
      {
       "title": "Notice when another service changes",
       "text": "Your app reads orders or prices from someone else's service; a check on each reply tells you the day its format changes, instead of saving broken data.",
       "idea": false
      },
      {
       "title": "Read uploaded data files safely",
       "text": "People upload a file with contacts or settings; your app checks every entry and reports the missing or wrong ones by name.",
       "idea": false
      },
      {
       "title": "Describe your data to other tools",
       "text": "The same description can be turned into a standard format file, so documentation pages, form builders and AI models know which fields you expect.",
       "idea": false
      },
      {
       "title": "Load app settings from the server",
       "text": "Database address, upload limit and secret keys come from the server's settings; the app refuses to start if one is missing or wrong.",
       "idea": false
      },
      {
       "title": "Check an AI model's answer",
       "text": "You ask an AI model to fill in a support ticket; your app accepts the answer only if every field is there and in range.",
       "idea": true
      }
     ]
    }
   ]
  },
  {
   "id": "popularity",
   "nav": "Popularity",
   "h2": "Pydantic popularity",
   "parts": [
    {
     "t": "stats",
     "items": [
      {
       "n": "86",
       "of": "/ 100",
       "l": "Gid Score, #31 overall"
      },
      {
       "n": "292M",
       "l": "downloads a week, pypi"
      },
      {
       "n": "29.6K",
       "l": "GitHub stars"
      },
      {
       "n": "538",
       "l": "agent projects use it"
      }
     ]
    },
    {
     "t": "small",
     "text": "Gid Score measures public popularity and activity, not quality.",
     "link": "How the Gid Score is calculated",
     "path": "tools/top/"
    }
   ]
  },
  {
   "id": "usage",
   "nav": "How it is used",
   "h2": "How Pydantic is used",
   "parts": [
    {
     "t": "list",
     "items": [
      "Pydantic is a dependency in 538 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (33.1% of the 1,623 Python ones), #3 of 63 in forms, validation and schemas.",
      "Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 3,899; those are left out of every share on this page.",
      "The most used alternative in our scan is jsonschema (104 projects).",
      "Projects that use it most often also use Uvicorn (55.0%), FastAPI (54.8%), python-dotenv (52.0%).",
      "It is more common in projects set up for OpenClaw (9.6%) than for OpenAI Codex (5.1%)."
     ]
    },
    {
     "t": "h3",
     "text": "By coding agent"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "282 projects, 9.3%",
       "v": "GitHub Copilot",
       "path": "agents/github-copilot/"
      },
      {
       "l": "272 projects, 8.3%",
       "v": "Claude Code",
       "path": "agents/claude-code/"
      },
      {
       "l": "203 projects, 8.3%",
       "v": "Cursor",
       "path": "agents/cursor/"
      },
      {
       "l": "32 projects, 9.6%",
       "v": "OpenClaw",
       "path": "agents/openclaw/"
      },
      {
       "l": "31 projects, 6.5%",
       "v": "Gemini CLI",
       "path": "agents/gemini-cli/"
      },
      {
       "l": "24 projects, 5.1%",
       "v": "OpenAI Codex",
       "path": "agents/openai-codex/"
      },
      {
       "l": "23 projects, 8.2%",
       "v": "Devin Desktop",
       "path": "agents/devin-desktop/"
      },
      {
       "l": "19 projects, 5.5%",
       "v": "OpenCode",
       "path": "agents/opencode/"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Often used with"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "In 55.0% of its projects",
       "v": "Uvicorn",
       "path": "tools/uvicorn/"
      },
      {
       "l": "In 54.8% of its projects",
       "v": "FastAPI",
       "path": "tools/fastapi/"
      },
      {
       "l": "In 52.0% of its projects",
       "v": "python-dotenv",
       "path": "tools/python-dotenv/"
      },
      {
       "l": "In 34.8% of its projects",
       "v": "Requests",
       "path": "tools/requests-py/"
      },
      {
       "l": "In 34.4% of its projects",
       "v": "Pydantic Settings",
       "path": "tools/pydantic-settings/"
      },
      {
       "l": "In 34.0% of its projects",
       "v": "PyYAML",
       "path": "tools/pyyaml/"
      },
      {
       "l": "In 33.8% of its projects",
       "v": "Model Context Protocol SDK (Python)",
       "path": "tools/mcp/"
      },
      {
       "l": "In 29.7% of its projects",
       "v": "NumPy",
       "path": "tools/numpy/"
      }
     ]
    }
   ]
  },
  {
   "id": "profile",
   "nav": "Profile",
   "h2": "Pydantic in practice",
   "parts": [
    {
     "t": "h3",
     "text": "Strengths"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "The schema is the type hints",
       "v": "Fields are declared with standard annotations. The site says this means \"less to learn, less code to write\", and it points to integration with IDEs and static analysis tools."
      },
      {
       "l": "Most validation runs in Rust",
       "v": "Validation for most types is implemented in Rust inside <code>pydantic-core</code>. The docs say this puts Pydantic \"among the fastest data validation libraries for Python.\""
      },
      {
       "l": "Docs benchmark beats hand-written parsing",
       "v": "The docs include a benchmark that parses JSON from GitHub's emoji API and validates the URLs. They note that dedicated code \"should be much faster than a general-purpose validator\" in general, but say Pydantic is \"&gt;300% faster\" in this example. The printed output reads \"Pydantic 3.45x faster\"."
      },
      {
       "l": "Strict mode that still works on JSON",
       "v": "Strict mode refuses to convert types, but JSON has no datetime, UUID or bytes types. <code>model_validate_json</code> parses and validates JSON in one step, so a string can still become a <code>datetime</code> under strict rules."
      }
     ]
    },
    {
     "t": "h3",
     "text": "Watch out for"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "V2 renamed the model methods",
       "v": "<code>dict()</code>, <code>json()</code>, <code>parse_obj()</code> and <code>copy()</code> became <code>model_dump()</code>, <code>model_dump_json()</code>, <code>model_validate()</code> and <code>model_copy()</code>. The old names still work where possible, but they emit <code>DeprecationWarning</code>s."
      },
      {
       "l": "The migration tool is beta",
       "v": "The maintainers provide <code>bump-pydantic</code> to rewrite v1 code. They write that it is \"still in beta\"."
      },
      {
       "l": "Coercion is on by default",
       "v": "Pydantic converts common wrong types instead of rejecting them. For example, a numeric string passed to an <code>int</code> field is parsed as an int. If you need exact types, turn on strict mode."
      }
     ]
    },
    {
     "t": "h3",
     "text": "Validate and coerce external data into a model"
    },
    {
     "t": "tabs",
     "label": "Example",
     "items": [
      {
       "tab": "Python",
       "code": "from datetime import datetime\nfrom typing import Optional\nfrom pydantic import BaseModel\n\nclass User(BaseModel):\n    id: int\n    name: str = 'John Doe'\n    signup_ts: Optional[datetime] = None\n    friends: list[int] = []\n\nexternal_data = {'id': '123', 'signup_ts': '2017-06-01 12:22', 'friends': [1, '2', b'3']}\nuser = User(**external_data)\nprint(user)\n#> User id=123 name='John Doe' signup_ts=datetime.datetime(2017, 6, 1, 12, 22) friends=[1, 2, 3]\nprint(user.id)\n#> 123"
      }
     ]
    }
   ]
  },
  {
   "id": "more",
   "nav": null,
   "spy_as": "profile",
   "h2": "More about Pydantic",
   "parts": [
    {
     "t": "more",
     "items": [
      {
       "title": "Funding",
       "path": "tools/funding/",
       "items": [
        "GitHub Sponsors: https://github.com/samuelcolvin",
        "21 GitHub sponsors"
       ]
      },
      {
       "title": "Agent Skills for it",
       "path": "skills/",
       "items": [
        "pydantic-ai: Build production-ready AI agents with PydanticAI — type-safe tool use, structured outputs, dependency injection, and multi-model support.",
        "pydantic: Python data validation using type hints and runtime type checking with Pydantic v2's Rust-powered core for high-performance validation in Fa",
        "pydantic-models-py: Create Pydantic models following the multi-model pattern with Base, Create, Update, Response, and InDB variants. Use when defining API reque"
       ]
      },
      {
       "title": "Head to head",
       "items": [
        {
         "text": "Pydantic vs jsonschema",
         "note": "used together in 71 projects",
         "path": "tools/compare/pydantic-vs-jsonschema/"
        }
       ]
      },
      {
       "title": "Packages around it",
       "items": [
        "python-dotenv: .env file loader",
        "uvicorn: ASGI server",
        "fastapi: Web API framework",
        "requests: HTTP client",
        "numpy: Numeric arrays",
        "pydantic-settings: Settings from env vars"
       ]
      },
      {
       "title": "More in Forms, validation and schemas",
       "path": "tools/forms-validation/",
       "items": [
        {
         "text": "Zod",
         "path": "tools/zod/"
        },
        {
         "text": "React Hook Form",
         "path": "tools/react-hook-form/"
        },
        {
         "text": "React Hook Form Resolvers",
         "path": "tools/hookform/"
        },
        {
         "text": "Ajv",
         "path": "tools/ajv/"
        },
        {
         "text": "ajv-formats",
         "path": "tools/ajv-formats/"
        },
        {
         "text": "zod-to-json-schema",
         "path": "tools/zod-to-json-schema/"
        },
        {
         "text": "Protocol Buffers",
         "path": "tools/protobuf/"
        },
        {
         "text": "email-validator",
         "path": "tools/email-validator/"
        }
       ]
      }
     ]
    }
   ]
  },
  {
   "id": "alternatives",
   "nav": "Alternatives",
   "h2": "Alternatives",
   "parts": [
    {
     "t": "alts",
     "items": [
      {
       "name": "Pydantic",
       "me": true,
       "facts": [
        "MIT",
        "Gid 86",
        "292M/wk"
       ]
      },
      {
       "name": "Zod",
       "why": "Pick Zod when your app is written in TypeScript or JavaScript rather than Python; it is a TypeScript-first schema validation library.",
       "path": "tools/zod/",
       "facts": []
      },
      {
       "name": "jsonschema",
       "why": "Pick jsonschema when you already have JSON Schema files and only need to check data against them in Python.",
       "path": "tools/jsonschema/",
       "facts": [
        "MIT",
        "Gid 75",
        "164M/wk"
       ]
      },
      {
       "name": "email-validator",
       "why": "Pick email-validator alone when all you need is to check email addresses; Pydantic's EmailStr uses it anyway.",
       "path": "tools/email-validator/",
       "facts": []
      },
      {
       "name": "marshmallow",
       "why": "Lightweight library for converting complex datatypes to and from native Python datatypes.",
       "path": "tools/marshmallow/",
       "facts": [
        "MIT",
        "Gid 70",
        "22.4M/wk"
       ]
      },
      {
       "name": "fastjsonschema",
       "why": "Fast JSON schema validation for Python with optimized performance.",
       "path": "tools/fastjsonschema/",
       "facts": [
        "BSD",
        "Gid 57",
        "30M/wk"
       ]
      },
      {
       "name": "cattrs",
       "why": "Structured data serialization for attrs and dataclasses with composition support.",
       "path": "tools/cattrs/",
       "facts": [
        "MIT",
        "Gid 50",
        "8.5M/wk"
       ]
      },
      {
       "name": "msgspec",
       "why": "Fast serialization and validation for JSON, MessagePack, YAML, TOML with schemas.",
       "path": "tools/msgspec/",
       "facts": [
        "BSD-3-Clause",
        "Gid 58",
        "9.8M/wk"
       ]
      },
      {
       "name": "schema",
       "why": "Lightweight Python library for validating data structures against defined schemas.",
       "path": "tools/schema/",
       "facts": [
        "MIT",
        "Gid 55",
        "5.3M/wk"
       ]
      }
     ],
     "more": "Compare Pydantic with another tool",
     "more_path": "tools/compare/"
    }
   ]
  },
  {
   "id": "start",
   "nav": "Get started",
   "h2": "Get started",
   "parts": [
    {
     "t": "prompt",
     "text": "Use the Python library Pydantic v2 (pin pydantic[email]==2.14.3, Python 3.10+) to check the sign-up form data with a BaseModel and model_validate, and return the messages from ValidationError.errors() for each wrong field."
    },
    {
     "t": "steps",
     "items": [
      {
       "text": "Install Pydantic into your project's Python environment (Python 3.10 or newer). Add the email extra if you check email addresses.",
       "code": "pip install pydantic\n# with the `email` extra:\npip install 'pydantic[email]'\n",
       "src": "https://pydantic.dev/docs/validation/latest/get-started/install/"
      },
      {
       "text": "Describe your data as a class with typed fields and pass the incoming data to it.",
       "code": "from datetime import datetime\nfrom typing import Optional\nfrom pydantic import BaseModel\n\nclass User(BaseModel):\n    id: int\n    name: str = 'John Doe'\n    signup_ts: Optional[datetime] = None\n    friends: list[int] = []\n\nexternal_data = {'id': '123', 'signup_ts': '2017-06-01 12:22', 'friends': [1, '2', b'3']}\nuser = User(**external_data)\n",
       "src": "https://github.com/pydantic/pydantic/blob/main/README.md"
      },
      {
       "text": "Catch ValidationError to show the user what to fix; e.errors() gives one entry per wrong field.",
       "code": null,
       "src": "https://pydantic.dev/docs/validation/latest/get-started/"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Rules for your agent"
    },
    {
     "t": "rules",
     "label": "Paste into AGENTS.md or CLAUDE.md",
     "text": "## Pydantic\n- Write V2 code. Use `model_dump()`, `model_dump_json()`, `model_validate()`, `model_copy()` and `model_json_schema()`, not the V1 names `dict()`, `json()`, `parse_obj()` or `copy()`.\n- For raw JSON input, call `Model.model_validate_json(data)` instead of the deprecated `parse_raw`/`parse_file`. Otherwise, load the data first and pass it to `model_validate`.\n- To build models from ORM objects, set `from_attributes=True` in the model config and use `model_validate`, not `from_orm`.\n- Lax mode coerces input by default. Pass `strict=True` to `model_validate` when inputs must match the declared types exactly.\n- Catch `ValidationError` and read `e.errors()` for per-field `type`, `loc` and `msg`.\n- Validation uses aliases by default (`validate_by_alias` is True, `validate_by_name` is False). Enable `validate_by_name` if callers pass field names.\n- Use `@field_serializer` or `@model_serializer` for custom output. `json_encoders` in the model config is deprecated.\n"
    },
    {
     "t": "h3",
     "text": "Mistakes to avoid"
    },
    {
     "t": "mistakes",
     "items": [
      {
       "dont": "Model.parse_obj(data), model.dict(), model.json(), Model.schema() (Pydantic 1 names)",
       "fix": "Model.model_validate(data), model.model_dump(), model.model_dump_json(), Model.model_json_schema()",
       "why": "Version 2 renamed these methods; the old ones still run but warn (our run printed PydanticDeprecatedSince20 for parse_obj and dict)."
      },
      {
       "dont": "from pydantic import BaseSettings",
       "fix": "pip install pydantic-settings, then from pydantic_settings import BaseSettings",
       "why": "BaseSettings left the main package in version 2."
      },
      {
       "dont": "@validator('x') and class Config: orm_mode = True",
       "fix": "@field_validator('x') and model_config = ConfigDict(from_attributes=True)",
       "why": "The old decorator is deprecated and orm_mode was renamed."
      },
      {
       "dont": "Using EmailStr after plain pip install pydantic",
       "fix": "pip install 'pydantic[email]'",
       "why": "In our run the class definition failed with ImportError: email-validator is not installed."
      },
      {
       "dont": "note: Optional[str] (expecting the field to be optional)",
       "fix": "note: Optional[str] = None, or note: str | None = None",
       "why": "Without a default the field is still required; Optional only allows None as a value."
      }
     ]
    }
   ]
  },
  {
   "id": "faq",
   "nav": "Questions",
   "h2": "Questions",
   "parts": [
    {
     "t": "faq",
     "items": [
      {
       "q": "Can I use it in a paid, closed-source app?",
       "a": "Yes. It is MIT-licensed; keep the copyright and license notice with its files.",
       "evidence": {
        "url": "https://github.com/pydantic/pydantic/blob/main/LICENSE",
        "quote": "The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software."
       }
      },
      {
       "q": "My code uses parse_obj() and .dict(). Is that still right?",
       "a": "Those are Pydantic 1 names. In version 2 they are model_validate() and model_dump(); the old names still run but warn that they are deprecated.",
       "evidence": {
        "url": "https://pydantic.dev/docs/validation/latest/get-started/migration/",
        "quote": "Where possible, we have retained the deprecated methods with their old names to help ease migration, but calling them will emit DeprecationWarning s."
       }
      },
      {
       "q": "Is there a tool to move old code to version 2?",
       "a": "Yes, bump-pydantic. The docs say it is still in beta.",
       "evidence": {
        "url": "https://pydantic.dev/docs/validation/latest/get-started/migration/",
        "quote": "We have created a tool to help you migrate your code. This tool is still in beta, but we hope it will help you to migrate your code more quickly."
       }
      },
      {
       "q": "Will a minor update break my code?",
       "a": "The project says it will not break things on purpose in 2.x minor releases, but error message texts may change; check the error type, not the message.",
       "evidence": [
        {
         "url": "https://pydantic.dev/docs/validation/latest/get-started/version-policy/",
         "quote": "We will not intentionally make breaking changes in minor releases of V2."
        },
        {
         "url": "https://pydantic.dev/docs/validation/latest/get-started/version-policy/",
         "quote": "type will not change — if you’re programmatically parsing error messages, you should use type ."
        }
       ]
      },
      {
       "q": "Does it send my data anywhere?",
       "a": "No. Checks run inside your app; sending failed checks to Logfire is a separate, optional service.",
       "evidence": {
        "url": "https://pydantic.dev/docs/validation/latest/concepts/pydantic_settings/",
        "quote": "Logfire can record failed validations and their structured errors, so you can see which setting failed and why."
       }
      }
     ]
    }
   ]
  }
 ],
 "glance": [
  [
   "Package",
   "pypi pydantic"
  ],
  [
   "Category",
   "Forms, validation and schemas"
  ],
  [
   "License",
   "MIT"
  ],
  [
   "Latest version",
   "v2.14.0, October 8, 2026"
  ],
  [
   "On GitHub since",
   "May 2017"
  ],
  [
   "Gid Score",
   "86.0"
  ],
  [
   "Rank in category",
   "#3 of 63"
  ],
  [
   "GitHub",
   "pydantic/pydantic"
  ],
  [
   "Last change",
   "Nov 23, 2026"
  ]
 ],
 "good": [
  "It needs Python 3.10 or newer.",
  "Version 2 was rewritten from scratch and renamed many functions. Old tutorials and old AI answers often show version 1 code.",
  "By default it quietly converts close matches, like the text \"1\" into the number 1. Turn on strict mode if you want such input refused."
 ],
 "checked_line": "Read by AgentGid from 13 official pages, card checked Nov 10, 2026; numbers update daily.",
 "logo": "https://agentgid.com/media/avatars/pydantic.png"
}