🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 140 (from laksa064)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ℹ️ Skipped - page is already crawled

đź“„
INDEXABLE
âś…
CRAWLED
37 minutes ago
🤖
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0 months ago
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://docs.pydantic.dev/latest/
Last Crawled2026-04-09 08:38:00 (37 minutes ago)
First Indexed2023-04-29 15:54:42 (2 years ago)
HTTP Status Code200
Meta TitleWelcome to Pydantic - Pydantic Validation
Meta DescriptionData validation using Python type hints
Meta Canonicalnull
Boilerpipe Text
Documentation for version: v2.12.5 . Pydantic is the most widely used data validation library for Python. Fast and extensible, Pydantic plays nicely with your linters/IDE/brain. Define how data should be in pure, canonical Python 3.9+; validate it with Pydantic. Monitor Pydantic with Pydantic Logfire Pydantic Logfire is an application monitoring tool that is as simple to use and powerful as Pydantic itself. Logfire integrates with many popular Python libraries including FastAPI, OpenAI and Pydantic itself, so you can use Logfire to monitor Pydantic validations and understand why some inputs fail validation: Monitoring Pydantic with Logfire from datetime import datetime import logfire from pydantic import BaseModel logfire . configure () logfire . instrument_pydantic () # (1)! class Delivery ( BaseModel ): timestamp : datetime dimensions : tuple [ int , int ] # this will record details of a successful validation to logfire m = Delivery ( timestamp = '2020-01-02T03:04:05Z' , dimensions = [ '10' , '20' ]) print ( repr ( m . timestamp )) #> datetime.datetime(2020, 1, 2, 3, 4, 5, tzinfo=TzInfo(UTC)) print ( m . dimensions ) #> (10, 20) Delivery ( timestamp = '2020-01-02T03:04:05Z' , dimensions = [ '10' ]) # (2)! Set logfire record all both successful and failed validations, use record='failure' to only record failed validations, learn more . This will raise a ValidationError since there are too few dimensions , details of the input data and validation errors will be recorded in Logfire. Would give you a view like this in the Logfire platform: This is just a toy example, but hopefully makes clear the potential value of instrumenting a more complex application. Learn more about Pydantic Logfire Sign up for our newsletter, The Pydantic Stack , with updates & tutorials on Pydantic, Logfire, and Pydantic AI: Why use Pydantic? ¶ Powered by type hints — with Pydantic, schema validation and serialization are controlled by type annotations; less to learn, less code to write, and integration with your IDE and static analysis tools. Learn more… Speed — Pydantic's core validation logic is written in Rust. As a result, Pydantic is among the fastest data validation libraries for Python. Learn more… JSON Schema — Pydantic models can emit JSON Schema, allowing for easy integration with other tools. Learn more… Strict and Lax mode — Pydantic can run in either strict mode (where data is not converted) or lax mode where Pydantic tries to coerce data to the correct type where appropriate. Learn more… Dataclasses , TypedDicts and more — Pydantic supports validation of many standard library types including dataclass and TypedDict . Learn more… Customisation — Pydantic allows custom validators and serializers to alter how data is processed in many powerful ways. Learn more… Ecosystem — around 8,000 packages on PyPI use Pydantic, including massively popular libraries like FastAPI , huggingface , Django Ninja , SQLModel , & LangChain . Learn more… Battle tested — Pydantic is downloaded over 360M times/month and is used by all FAANG companies and 20 of the 25 largest companies on NASDAQ. If you're trying to do something with Pydantic, someone else has probably already done it. Learn more… Installing Pydantic is as simple as: pip install pydantic Pydantic examples ¶ To see Pydantic at work, let's start with a simple example, creating a custom class that inherits from BaseModel : Validation Successful from datetime import datetime from pydantic import BaseModel , PositiveInt class User ( BaseModel ): id : int # (1)! name : str = 'John Doe' # (2)! signup_ts : datetime | None # (3)! tastes : dict [ str , PositiveInt ] # (4)! external_data = { 'id' : 123 , 'signup_ts' : '2019-06-01 12:22' , # (5)! 'tastes' : { 'wine' : 9 , b 'cheese' : 7 , # (6)! 'cabbage' : '1' , # (7)! }, } user = User ( ** external_data ) # (8)! print ( user . id ) # (9)! #> 123 print ( user . model_dump ()) # (10)! """ { 'id': 123, 'name': 'John Doe', 'signup_ts': datetime.datetime(2019, 6, 1, 12, 22), 'tastes': {'wine': 9, 'cheese': 7, 'cabbage': 1}, } """ id is of type int ; the annotation-only declaration tells Pydantic that this field is required. Strings, bytes, or floats will be coerced to integers if possible; otherwise an exception will be raised. name is a string; because it has a default, it is not required. signup_ts is a datetime field that is required, but the value None may be provided; Pydantic will process either a Unix timestamp integer (e.g. 1496498400 ) or a string representing the date and time. tastes is a dictionary with string keys and positive integer values. The PositiveInt type is shorthand for Annotated[int, annotated_types.Gt(0)] . The input here is an ISO 8601 formatted datetime, but Pydantic will convert it to a datetime object. The key here is bytes , but Pydantic will take care of coercing it to a string. Similarly, Pydantic will coerce the string '1' to the integer 1 . We create instance of User by passing our external data to User as keyword arguments. We can access fields as attributes of the model. We can convert the model to a dictionary with model_dump() . If validation fails, Pydantic will raise an error with a breakdown of what was wrong: Validation Error # continuing the above example... from datetime import datetime from pydantic import BaseModel , PositiveInt , ValidationError class User ( BaseModel ): id : int name : str = 'John Doe' signup_ts : datetime | None tastes : dict [ str , PositiveInt ] external_data = { 'id' : 'not an int' , 'tastes' : {}} # (1)! try : User ( ** external_data ) # (2)! except ValidationError as e : print ( e . errors ()) """ [ { 'type': 'int_parsing', 'loc': ('id',), 'msg': 'Input should be a valid integer, unable to parse string as an integer', 'input': 'not an int', 'url': 'https://errors.pydantic.dev/2/v/int_parsing', }, { 'type': 'missing', 'loc': ('signup_ts',), 'msg': 'Field required', 'input': {'id': 'not an int', 'tastes': {}}, 'url': 'https://errors.pydantic.dev/2/v/missing', }, ] """ The input data is wrong here — id is not a valid integer, and signup_ts is missing. Trying to instantiate User will raise a ValidationError with a list of errors. Who is using Pydantic? ¶ Hundreds of organisations and packages are using Pydantic. Some of the prominent companies and organizations around the world who are using Pydantic include: For a more comprehensive list of open-source projects using Pydantic see the list of dependents on github , or you can find some awesome projects using Pydantic in awesome-pydantic .
Markdown
[Skip to content](https://docs.pydantic.dev/latest/#pydantic-validation) What's new — we've launched [Pydantic Logfire](https://pydantic.dev/articles/logfire-announcement) ![🔥](https://cdn.jsdelivr.net/gh/jdecked/twemoji@15.0.3/assets/svg/1f525.svg) to help you monitor and understand your [Pydantic validations.](https://logfire.pydantic.dev/docs/integrations/pydantic/) [![logo](https://docs.pydantic.dev/latest/logo-white.svg)](https://docs.pydantic.dev/latest/ "Pydantic Validation") Pydantic Validation Welcome to Pydantic Type to start searching [pydantic/pydantic](https://github.com/pydantic/pydantic "Go to repository") - [Get Started](https://docs.pydantic.dev/latest/) - [Concepts](https://docs.pydantic.dev/latest/concepts/models/) - [API Documentation](https://docs.pydantic.dev/latest/api/base_model/) - [Internals](https://docs.pydantic.dev/latest/internals/architecture/) - [Examples](https://docs.pydantic.dev/latest/examples/files/) - [Error Messages](https://docs.pydantic.dev/latest/errors/errors/) - [Integrations](https://docs.pydantic.dev/latest/integrations/logfire/) - [Blog](https://blog.pydantic.dev/) - [Pydantic People](https://docs.pydantic.dev/latest/pydantic_people/) [![logo](https://docs.pydantic.dev/latest/logo-white.svg)](https://docs.pydantic.dev/latest/ "Pydantic Validation") Pydantic Validation [pydantic/pydantic](https://github.com/pydantic/pydantic "Go to repository") - Get Started Get Started - Welcome to Pydantic [Welcome to Pydantic](https://docs.pydantic.dev/latest/) Page contents - [Why use Pydantic?](https://docs.pydantic.dev/latest/#why-use-pydantic) - [Pydantic examples](https://docs.pydantic.dev/latest/#pydantic-examples) - [Who is using Pydantic?](https://docs.pydantic.dev/latest/#who-is-using-pydantic) - [Why use Pydantic](https://docs.pydantic.dev/latest/why/) - [Help with Pydantic](https://docs.pydantic.dev/latest/help_with_pydantic/) - [Installation](https://docs.pydantic.dev/latest/install/) - [Migration Guide](https://docs.pydantic.dev/latest/migration/) - [Version Policy](https://docs.pydantic.dev/latest/version-policy/) - [Contributing](https://docs.pydantic.dev/latest/contributing/) - [Changelog](https://docs.pydantic.dev/latest/changelog/) - Concepts Concepts - [Models](https://docs.pydantic.dev/latest/concepts/models/) - [Fields](https://docs.pydantic.dev/latest/concepts/fields/) - [JSON Schema](https://docs.pydantic.dev/latest/concepts/json_schema/) - [JSON](https://docs.pydantic.dev/latest/concepts/json/) - [Types](https://docs.pydantic.dev/latest/concepts/types/) - [Unions](https://docs.pydantic.dev/latest/concepts/unions/) - [Alias](https://docs.pydantic.dev/latest/concepts/alias/) - [Configuration](https://docs.pydantic.dev/latest/concepts/config/) - [Serialization](https://docs.pydantic.dev/latest/concepts/serialization/) - [Validators](https://docs.pydantic.dev/latest/concepts/validators/) - [Dataclasses](https://docs.pydantic.dev/latest/concepts/dataclasses/) - [Forward Annotations](https://docs.pydantic.dev/latest/concepts/forward_annotations/) - [Strict Mode](https://docs.pydantic.dev/latest/concepts/strict_mode/) - [Type Adapter](https://docs.pydantic.dev/latest/concepts/type_adapter/) - [Validation Decorator](https://docs.pydantic.dev/latest/concepts/validation_decorator/) - [Conversion Table](https://docs.pydantic.dev/latest/concepts/conversion_table/) - [Settings Management](https://docs.pydantic.dev/latest/concepts/pydantic_settings/) - [Performance](https://docs.pydantic.dev/latest/concepts/performance/) - [Experimental](https://docs.pydantic.dev/latest/concepts/experimental/) - API Documentation API Documentation - Pydantic Pydantic - [BaseModel](https://docs.pydantic.dev/latest/api/base_model/) - [RootModel](https://docs.pydantic.dev/latest/api/root_model/) - [Pydantic Dataclasses](https://docs.pydantic.dev/latest/api/dataclasses/) - [TypeAdapter](https://docs.pydantic.dev/latest/api/type_adapter/) - [Validate Call](https://docs.pydantic.dev/latest/api/validate_call/) - [Fields](https://docs.pydantic.dev/latest/api/fields/) - [Aliases](https://docs.pydantic.dev/latest/api/aliases/) - [Configuration](https://docs.pydantic.dev/latest/api/config/) - [JSON Schema](https://docs.pydantic.dev/latest/api/json_schema/) - [Errors](https://docs.pydantic.dev/latest/api/errors/) - [Functional Validators](https://docs.pydantic.dev/latest/api/functional_validators/) - [Functional Serializers](https://docs.pydantic.dev/latest/api/functional_serializers/) - [Standard Library Types](https://docs.pydantic.dev/latest/api/standard_library_types/) - [Pydantic Types](https://docs.pydantic.dev/latest/api/types/) - [Network Types](https://docs.pydantic.dev/latest/api/networks/) - [Version Information](https://docs.pydantic.dev/latest/api/version/) - [Annotated Handlers](https://docs.pydantic.dev/latest/api/annotated_handlers/) - [Experimental](https://docs.pydantic.dev/latest/api/experimental/) - Pydantic Core Pydantic Core - [pydantic\_core](https://docs.pydantic.dev/latest/api/pydantic_core/) - [pydantic\_core.core\_schema](https://docs.pydantic.dev/latest/api/pydantic_core_schema/) - [Pydantic Settings](https://docs.pydantic.dev/latest/api/pydantic_settings/) - Pydantic Extra Types Pydantic Extra Types - [Color](https://docs.pydantic.dev/latest/api/pydantic_extra_types_color/) - [Country](https://docs.pydantic.dev/latest/api/pydantic_extra_types_country/) - [Payment](https://docs.pydantic.dev/latest/api/pydantic_extra_types_payment/) - [Phone Numbers](https://docs.pydantic.dev/latest/api/pydantic_extra_types_phone_numbers/) - [Routing Numbers](https://docs.pydantic.dev/latest/api/pydantic_extra_types_routing_numbers/) - [Coordinate](https://docs.pydantic.dev/latest/api/pydantic_extra_types_coordinate/) - [Mac Address](https://docs.pydantic.dev/latest/api/pydantic_extra_types_mac_address/) - [ISBN](https://docs.pydantic.dev/latest/api/pydantic_extra_types_isbn/) - [Pendulum](https://docs.pydantic.dev/latest/api/pydantic_extra_types_pendulum_dt/) - [Currency](https://docs.pydantic.dev/latest/api/pydantic_extra_types_currency_code/) - [Language](https://docs.pydantic.dev/latest/api/pydantic_extra_types_language_code/) - [Script Code](https://docs.pydantic.dev/latest/api/pydantic_extra_types_script_code/) - [Semantic Version](https://docs.pydantic.dev/latest/api/pydantic_extra_types_semantic_version/) - [Timezone Name](https://docs.pydantic.dev/latest/api/pydantic_extra_types_timezone_name/) - [ULID](https://docs.pydantic.dev/latest/api/pydantic_extra_types_ulid/) - Internals Internals - [Architecture](https://docs.pydantic.dev/latest/internals/architecture/) - [Resolving Annotations](https://docs.pydantic.dev/latest/internals/resolving_annotations/) - Examples Examples - [Validating File Data](https://docs.pydantic.dev/latest/examples/files/) - [Web and API Requests](https://docs.pydantic.dev/latest/examples/requests/) - [Queues](https://docs.pydantic.dev/latest/examples/queues/) - [Databases](https://docs.pydantic.dev/latest/examples/orms/) - [Custom Validators](https://docs.pydantic.dev/latest/examples/custom_validators/) - [Dynamic models](https://docs.pydantic.dev/latest/examples/dynamic_models/) - Error Messages Error Messages - [Error Handling](https://docs.pydantic.dev/latest/errors/errors/) - [Validation Errors](https://docs.pydantic.dev/latest/errors/validation_errors/) - [Usage Errors](https://docs.pydantic.dev/latest/errors/usage_errors/) - Integrations Integrations - [Pydantic Logfire](https://docs.pydantic.dev/latest/integrations/logfire/) - [LLMs](https://docs.pydantic.dev/latest/integrations/llms/) - Dev Tools Dev Tools - [Mypy](https://docs.pydantic.dev/latest/integrations/mypy/) - [Pyrefly](https://docs.pydantic.dev/latest/integrations/pyrefly/) - [PyCharm](https://docs.pydantic.dev/latest/integrations/pycharm/) - [Hypothesis](https://docs.pydantic.dev/latest/integrations/hypothesis/) - [Visual Studio Code](https://docs.pydantic.dev/latest/integrations/visual_studio_code/) - [datamodel-code-generator](https://docs.pydantic.dev/latest/integrations/datamodel_code_generator/) - [devtools](https://docs.pydantic.dev/latest/integrations/devtools/) - [Rich](https://docs.pydantic.dev/latest/integrations/rich/) - [Linting](https://docs.pydantic.dev/latest/integrations/linting/) - [Documentation](https://docs.pydantic.dev/latest/integrations/documentation/) - Production Tools Production Tools - [AWS Lambda](https://docs.pydantic.dev/latest/integrations/aws_lambda/) - [Blog](https://blog.pydantic.dev/) - [Pydantic People](https://docs.pydantic.dev/latest/pydantic_people/) Page contents - [Why use Pydantic?](https://docs.pydantic.dev/latest/#why-use-pydantic) - [Pydantic examples](https://docs.pydantic.dev/latest/#pydantic-examples) - [Who is using Pydantic?](https://docs.pydantic.dev/latest/#who-is-using-pydantic) # Pydantic Validation[¶](https://docs.pydantic.dev/latest/#pydantic-validation "Permanent link") [![CI](https://img.shields.io/github/actions/workflow/status/pydantic/pydantic/ci.yml?branch=main&logo=github&label=CI)](https://github.com/pydantic/pydantic/actions?query=event%3Apush+branch%3Amain+workflow%3ACI) [![Coverage](https://coverage-badge.samuelcolvin.workers.dev/pydantic/pydantic.svg)](https://github.com/pydantic/pydantic/actions?query=event%3Apush+branch%3Amain+workflow%3ACI) [![pypi](https://img.shields.io/pypi/v/pydantic.svg)](https://pypi.python.org/pypi/pydantic) [![CondaForge](https://img.shields.io/conda/v/conda-forge/pydantic.svg)](https://anaconda.org/conda-forge/pydantic) [![downloads](https://static.pepy.tech/badge/pydantic/month)](https://pepy.tech/project/pydantic) [![license](https://img.shields.io/github/license/pydantic/pydantic.svg)](https://github.com/pydantic/pydantic/blob/main/LICENSE) [![llms.txt](https://img.shields.io/badge/llms.txt-green)](https://docs.pydantic.dev/latest/llms.txt) Documentation for version: [v2.12.5](https://github.com/pydantic/pydantic/releases/tag/v2.12.5). Pydantic is the most widely used data validation library for Python. Fast and extensible, Pydantic plays nicely with your linters/IDE/brain. Define how data should be in pure, canonical Python 3.9+; validate it with Pydantic. Monitor Pydantic with Pydantic Logfire ![🔥](https://cdn.jsdelivr.net/gh/jdecked/twemoji@15.1.0/assets/svg/1f525.svg) **[Pydantic Logfire](https://pydantic.dev/logfire)** is an application monitoring tool that is as simple to use and powerful as Pydantic itself. Logfire integrates with many popular Python libraries including FastAPI, OpenAI and Pydantic itself, so you can use Logfire to monitor Pydantic validations and understand why some inputs fail validation: Monitoring Pydantic with Logfire ``` ``` 1. Set logfire record all both successful and failed validations, use `record='failure'` to only record failed validations, [learn more](https://logfire.pydantic.dev/docs/integrations/pydantic/). 2. This will raise a `ValidationError` since there are too few `dimensions`, details of the input data and validation errors will be recorded in Logfire. Would give you a view like this in the Logfire platform: [![Logfire Pydantic Integration](https://docs.pydantic.dev/latest/img/logfire-pydantic-integration.png)](https://logfire.pydantic.dev/docs/guides/web-ui/live/) This is just a toy example, but hopefully makes clear the potential value of instrumenting a more complex application. **[Learn more about Pydantic Logfire](https://logfire.pydantic.dev/docs/)** **Sign up for our newsletter, *The Pydantic Stack*, with updates & tutorials on Pydantic, Logfire, and Pydantic AI:** ## Why use Pydantic?[¶](https://docs.pydantic.dev/latest/#why-use-pydantic "Permanent link") - **Powered by type hints** — with Pydantic, schema validation and serialization are controlled by type annotations; less to learn, less code to write, and integration with your IDE and static analysis tools. [Learn more…](https://docs.pydantic.dev/latest/why/#type-hints) - **Speed** — Pydantic's core validation logic is written in Rust. As a result, Pydantic is among the fastest data validation libraries for Python. [Learn more…](https://docs.pydantic.dev/latest/why/#performance) - **JSON Schema** — Pydantic models can emit JSON Schema, allowing for easy integration with other tools. [Learn more…](https://docs.pydantic.dev/latest/why/#json-schema) - **Strict** and **Lax** mode — Pydantic can run in either strict mode (where data is not converted) or lax mode where Pydantic tries to coerce data to the correct type where appropriate. [Learn more…](https://docs.pydantic.dev/latest/why/#strict-lax) - **Dataclasses**, **TypedDicts** and more — Pydantic supports validation of many standard library types including `dataclass` and `TypedDict`. [Learn more…](https://docs.pydantic.dev/latest/why/#dataclasses-typeddict-more) - **Customisation** — Pydantic allows custom validators and serializers to alter how data is processed in many powerful ways. [Learn more…](https://docs.pydantic.dev/latest/why/#customisation) - **Ecosystem** — around 8,000 packages on PyPI use Pydantic, including massively popular libraries like *FastAPI*, *huggingface*, *Django Ninja*, *SQLModel*, & *LangChain*. [Learn more…](https://docs.pydantic.dev/latest/why/#ecosystem) - **Battle tested** — Pydantic is downloaded over 360M times/month and is used by all FAANG companies and 20 of the 25 largest companies on NASDAQ. If you're trying to do something with Pydantic, someone else has probably already done it. [Learn more…](https://docs.pydantic.dev/latest/why/#using-pydantic) [Installing Pydantic](https://docs.pydantic.dev/latest/install/) is as simple as: `pip install pydantic` ## Pydantic examples[¶](https://docs.pydantic.dev/latest/#pydantic-examples "Permanent link") To see Pydantic at work, let's start with a simple example, creating a custom class that inherits from `BaseModel`: Validation Successful ``` ``` 1. `id` is of type `int`; the annotation-only declaration tells Pydantic that this field is required. Strings, bytes, or floats will be coerced to integers if possible; otherwise an exception will be raised. 2. `name` is a string; because it has a default, it is not required. 3. `signup_ts` is a [`datetime`](https://docs.python.org/3/library/datetime.html#datetime.datetime) field that is required, but the value `None` may be provided; Pydantic will process either a [Unix timestamp](https://en.wikipedia.org/wiki/Unix_time) integer (e.g. `1496498400`) or a string representing the date and time. 4. `tastes` is a dictionary with string keys and positive integer values. The `PositiveInt` type is shorthand for `Annotated[int, annotated_types.Gt(0)]`. 5. The input here is an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) formatted datetime, but Pydantic will convert it to a [`datetime`](https://docs.python.org/3/library/datetime.html#datetime.datetime) object. 6. The key here is `bytes`, but Pydantic will take care of coercing it to a string. 7. Similarly, Pydantic will coerce the string `'1'` to the integer `1`. 8. We create instance of `User` by passing our external data to `User` as keyword arguments. 9. We can access fields as attributes of the model. 10. We can convert the model to a dictionary with [`model_dump()`](https://docs.pydantic.dev/latest/api/base_model/#pydantic.BaseModel.model_dump). If validation fails, Pydantic will raise an error with a breakdown of what was wrong: Validation Error ``` ``` 1. The input data is wrong here — `id` is not a valid integer, and `signup_ts` is missing. 2. Trying to instantiate `User` will raise a [`ValidationError`](https://docs.pydantic.dev/latest/api/pydantic_core/#pydantic_core.ValidationError) with a list of errors. ## Who is using Pydantic?[¶](https://docs.pydantic.dev/latest/#who-is-using-pydantic "Permanent link") Hundreds of organisations and packages are using Pydantic. Some of the prominent companies and organizations around the world who are using Pydantic include: [![Adobe](https://docs.pydantic.dev/latest/logos/adobe_logo.png)](https://docs.pydantic.dev/latest/why/#org-adobe "Adobe") [![Amazon and AWS](https://docs.pydantic.dev/latest/logos/amazon_logo.png)](https://docs.pydantic.dev/latest/why/#org-amazon "Amazon and AWS") [![Anthropic](https://docs.pydantic.dev/latest/logos/anthropic_logo.png)](https://docs.pydantic.dev/latest/why/#org-anthropic "Anthropic") [![Apple](https://docs.pydantic.dev/latest/logos/apple_logo.png)](https://docs.pydantic.dev/latest/why/#org-apple "Apple") [![ASML](https://docs.pydantic.dev/latest/logos/asml_logo.png)](https://docs.pydantic.dev/latest/why/#org-asml "ASML") [![AstraZeneca](https://docs.pydantic.dev/latest/logos/astrazeneca_logo.png)](https://docs.pydantic.dev/latest/why/#org-astrazeneca "AstraZeneca") [![Cisco Systems](https://docs.pydantic.dev/latest/logos/cisco_logo.png)](https://docs.pydantic.dev/latest/why/#org-cisco "Cisco Systems") [![Comcast](https://docs.pydantic.dev/latest/logos/comcast_logo.png)](https://docs.pydantic.dev/latest/why/#org-comcast "Comcast") [![Datadog](https://docs.pydantic.dev/latest/logos/datadog_logo.png)](https://docs.pydantic.dev/latest/why/#org-datadog "Datadog") [![Facebook](https://docs.pydantic.dev/latest/logos/facebook_logo.png)](https://docs.pydantic.dev/latest/why/#org-facebook "Facebook") [![GitHub](https://docs.pydantic.dev/latest/logos/github_logo.png)](https://docs.pydantic.dev/latest/why/#org-github "GitHub") [![Google](https://docs.pydantic.dev/latest/logos/google_logo.png)](https://docs.pydantic.dev/latest/why/#org-google "Google") [![HSBC](https://docs.pydantic.dev/latest/logos/hsbc_logo.png)](https://docs.pydantic.dev/latest/why/#org-hsbc "HSBC") [![IBM](https://docs.pydantic.dev/latest/logos/ibm_logo.png)](https://docs.pydantic.dev/latest/why/#org-ibm "IBM") [![Intel](https://docs.pydantic.dev/latest/logos/intel_logo.png)](https://docs.pydantic.dev/latest/why/#org-intel "Intel") [![Intuit](https://docs.pydantic.dev/latest/logos/intuit_logo.png)](https://docs.pydantic.dev/latest/why/#org-intuit "Intuit") [![Intergovernmental Panel on Climate Change](https://docs.pydantic.dev/latest/logos/ipcc_logo.png)](https://docs.pydantic.dev/latest/why/#org-ipcc "Intergovernmental Panel on Climate Change") [![JPMorgan](https://docs.pydantic.dev/latest/logos/jpmorgan_logo.png)](https://docs.pydantic.dev/latest/why/#org-jpmorgan "JPMorgan") [![Jupyter](https://docs.pydantic.dev/latest/logos/jupyter_logo.png)](https://docs.pydantic.dev/latest/why/#org-jupyter "Jupyter") [![Microsoft](https://docs.pydantic.dev/latest/logos/microsoft_logo.png)](https://docs.pydantic.dev/latest/why/#org-microsoft "Microsoft") [![Molecular Science Software Institute](https://docs.pydantic.dev/latest/logos/molssi_logo.png)](https://docs.pydantic.dev/latest/why/#org-molssi "Molecular Science Software Institute") [![NASA](https://docs.pydantic.dev/latest/logos/nasa_logo.png)](https://docs.pydantic.dev/latest/why/#org-nasa "NASA") [![Netflix](https://docs.pydantic.dev/latest/logos/netflix_logo.png)](https://docs.pydantic.dev/latest/why/#org-netflix "Netflix") [![NSA](https://docs.pydantic.dev/latest/logos/nsa_logo.png)](https://docs.pydantic.dev/latest/why/#org-nsa "NSA") [![NVIDIA](https://docs.pydantic.dev/latest/logos/nvidia_logo.png)](https://docs.pydantic.dev/latest/why/#org-nvidia "NVIDIA") [![OpenAI](https://docs.pydantic.dev/latest/logos/openai_logo.png)](https://docs.pydantic.dev/latest/why/#org-openai "OpenAI") [![Oracle](https://docs.pydantic.dev/latest/logos/oracle_logo.png)](https://docs.pydantic.dev/latest/why/#org-oracle "Oracle") [![Palantir](https://docs.pydantic.dev/latest/logos/palantir_logo.png)](https://docs.pydantic.dev/latest/why/#org-palantir "Palantir") [![Qualcomm](https://docs.pydantic.dev/latest/logos/qualcomm_logo.png)](https://docs.pydantic.dev/latest/why/#org-qualcomm "Qualcomm") [![Red Hat](https://docs.pydantic.dev/latest/logos/redhat_logo.png)](https://docs.pydantic.dev/latest/why/#org-redhat "Red Hat") [![Revolut](https://docs.pydantic.dev/latest/logos/revolut_logo.png)](https://docs.pydantic.dev/latest/why/#org-revolut "Revolut") [![Robusta](https://docs.pydantic.dev/latest/logos/robusta_logo.png)](https://docs.pydantic.dev/latest/why/#org-robusta "Robusta") [![Salesforce](https://docs.pydantic.dev/latest/logos/salesforce_logo.png)](https://docs.pydantic.dev/latest/why/#org-salesforce "Salesforce") [![Starbucks](https://docs.pydantic.dev/latest/logos/starbucks_logo.png)](https://docs.pydantic.dev/latest/why/#org-starbucks "Starbucks") [![Texas Instruments](https://docs.pydantic.dev/latest/logos/ti_logo.png)](https://docs.pydantic.dev/latest/why/#org-ti "Texas Instruments") [![Twilio](https://docs.pydantic.dev/latest/logos/twilio_logo.png)](https://docs.pydantic.dev/latest/why/#org-twilio "Twilio") [![Twitter](https://docs.pydantic.dev/latest/logos/twitter_logo.png)](https://docs.pydantic.dev/latest/why/#org-twitter "Twitter") [![UK Home Office](https://docs.pydantic.dev/latest/logos/ukhomeoffice_logo.png)](https://docs.pydantic.dev/latest/why/#org-ukhomeoffice "UK Home Office") For a more comprehensive list of open-source projects using Pydantic see the [list of dependents on github](https://github.com/pydantic/pydantic/network/dependents), or you can find some awesome projects using Pydantic in [awesome-pydantic](https://github.com/Kludex/awesome-pydantic). Back to top Made with [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/)
Readable Markdown
[![CI](https://img.shields.io/github/actions/workflow/status/pydantic/pydantic/ci.yml?branch=main&logo=github&label=CI)](https://github.com/pydantic/pydantic/actions?query=event%3Apush+branch%3Amain+workflow%3ACI) [![Coverage](https://coverage-badge.samuelcolvin.workers.dev/pydantic/pydantic.svg)](https://github.com/pydantic/pydantic/actions?query=event%3Apush+branch%3Amain+workflow%3ACI) [![pypi](https://img.shields.io/pypi/v/pydantic.svg)](https://pypi.python.org/pypi/pydantic) [![CondaForge](https://img.shields.io/conda/v/conda-forge/pydantic.svg)](https://anaconda.org/conda-forge/pydantic) [![downloads](https://static.pepy.tech/badge/pydantic/month)](https://pepy.tech/project/pydantic) [![license](https://img.shields.io/github/license/pydantic/pydantic.svg)](https://github.com/pydantic/pydantic/blob/main/LICENSE) [![llms.txt](https://img.shields.io/badge/llms.txt-green)](https://docs.pydantic.dev/latest/llms.txt) Documentation for version: [v2.12.5](https://github.com/pydantic/pydantic/releases/tag/v2.12.5). Pydantic is the most widely used data validation library for Python. Fast and extensible, Pydantic plays nicely with your linters/IDE/brain. Define how data should be in pure, canonical Python 3.9+; validate it with Pydantic. Monitor Pydantic with Pydantic Logfire ![🔥](https://cdn.jsdelivr.net/gh/jdecked/twemoji@15.1.0/assets/svg/1f525.svg) **[Pydantic Logfire](https://pydantic.dev/logfire)** is an application monitoring tool that is as simple to use and powerful as Pydantic itself. Logfire integrates with many popular Python libraries including FastAPI, OpenAI and Pydantic itself, so you can use Logfire to monitor Pydantic validations and understand why some inputs fail validation: Monitoring Pydantic with Logfire ``` ``` 1. Set logfire record all both successful and failed validations, use `record='failure'` to only record failed validations, [learn more](https://logfire.pydantic.dev/docs/integrations/pydantic/). 2. This will raise a `ValidationError` since there are too few `dimensions`, details of the input data and validation errors will be recorded in Logfire. Would give you a view like this in the Logfire platform: [![Logfire Pydantic Integration](https://docs.pydantic.dev/latest/img/logfire-pydantic-integration.png)](https://logfire.pydantic.dev/docs/guides/web-ui/live/) This is just a toy example, but hopefully makes clear the potential value of instrumenting a more complex application. **[Learn more about Pydantic Logfire](https://logfire.pydantic.dev/docs/)** **Sign up for our newsletter, *The Pydantic Stack*, with updates & tutorials on Pydantic, Logfire, and Pydantic AI:** ## Why use Pydantic?[¶](https://docs.pydantic.dev/latest/#why-use-pydantic "Permanent link") - **Powered by type hints** — with Pydantic, schema validation and serialization are controlled by type annotations; less to learn, less code to write, and integration with your IDE and static analysis tools. [Learn more…](https://docs.pydantic.dev/latest/why/#type-hints) - **Speed** — Pydantic's core validation logic is written in Rust. As a result, Pydantic is among the fastest data validation libraries for Python. [Learn more…](https://docs.pydantic.dev/latest/why/#performance) - **JSON Schema** — Pydantic models can emit JSON Schema, allowing for easy integration with other tools. [Learn more…](https://docs.pydantic.dev/latest/why/#json-schema) - **Strict** and **Lax** mode — Pydantic can run in either strict mode (where data is not converted) or lax mode where Pydantic tries to coerce data to the correct type where appropriate. [Learn more…](https://docs.pydantic.dev/latest/why/#strict-lax) - **Dataclasses**, **TypedDicts** and more — Pydantic supports validation of many standard library types including `dataclass` and `TypedDict`. [Learn more…](https://docs.pydantic.dev/latest/why/#dataclasses-typeddict-more) - **Customisation** — Pydantic allows custom validators and serializers to alter how data is processed in many powerful ways. [Learn more…](https://docs.pydantic.dev/latest/why/#customisation) - **Ecosystem** — around 8,000 packages on PyPI use Pydantic, including massively popular libraries like *FastAPI*, *huggingface*, *Django Ninja*, *SQLModel*, & *LangChain*. [Learn more…](https://docs.pydantic.dev/latest/why/#ecosystem) - **Battle tested** — Pydantic is downloaded over 360M times/month and is used by all FAANG companies and 20 of the 25 largest companies on NASDAQ. If you're trying to do something with Pydantic, someone else has probably already done it. [Learn more…](https://docs.pydantic.dev/latest/why/#using-pydantic) [Installing Pydantic](https://docs.pydantic.dev/latest/install/) is as simple as: `pip install pydantic` ## Pydantic examples[¶](https://docs.pydantic.dev/latest/#pydantic-examples "Permanent link") To see Pydantic at work, let's start with a simple example, creating a custom class that inherits from `BaseModel`: Validation Successful ``` ``` 1. `id` is of type `int`; the annotation-only declaration tells Pydantic that this field is required. Strings, bytes, or floats will be coerced to integers if possible; otherwise an exception will be raised. 2. `name` is a string; because it has a default, it is not required. 3. `signup_ts` is a [`datetime`](https://docs.python.org/3/library/datetime.html#datetime.datetime) field that is required, but the value `None` may be provided; Pydantic will process either a [Unix timestamp](https://en.wikipedia.org/wiki/Unix_time) integer (e.g. `1496498400`) or a string representing the date and time. 4. `tastes` is a dictionary with string keys and positive integer values. The `PositiveInt` type is shorthand for `Annotated[int, annotated_types.Gt(0)]`. 5. The input here is an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) formatted datetime, but Pydantic will convert it to a [`datetime`](https://docs.python.org/3/library/datetime.html#datetime.datetime) object. 6. The key here is `bytes`, but Pydantic will take care of coercing it to a string. 7. Similarly, Pydantic will coerce the string `'1'` to the integer `1`. 8. We create instance of `User` by passing our external data to `User` as keyword arguments. 9. We can access fields as attributes of the model. 10. We can convert the model to a dictionary with [`model_dump()`](https://docs.pydantic.dev/latest/api/base_model/#pydantic.BaseModel.model_dump). If validation fails, Pydantic will raise an error with a breakdown of what was wrong: Validation Error ``` ``` 1. The input data is wrong here — `id` is not a valid integer, and `signup_ts` is missing. 2. Trying to instantiate `User` will raise a [`ValidationError`](https://docs.pydantic.dev/latest/api/pydantic_core/#pydantic_core.ValidationError) with a list of errors. ## Who is using Pydantic?[¶](https://docs.pydantic.dev/latest/#who-is-using-pydantic "Permanent link") Hundreds of organisations and packages are using Pydantic. Some of the prominent companies and organizations around the world who are using Pydantic include: [![Adobe](https://docs.pydantic.dev/latest/logos/adobe_logo.png)](https://docs.pydantic.dev/latest/why/#org-adobe "Adobe") [![Amazon and AWS](https://docs.pydantic.dev/latest/logos/amazon_logo.png)](https://docs.pydantic.dev/latest/why/#org-amazon "Amazon and AWS") [![Anthropic](https://docs.pydantic.dev/latest/logos/anthropic_logo.png)](https://docs.pydantic.dev/latest/why/#org-anthropic "Anthropic") [![Apple](https://docs.pydantic.dev/latest/logos/apple_logo.png)](https://docs.pydantic.dev/latest/why/#org-apple "Apple") [![ASML](https://docs.pydantic.dev/latest/logos/asml_logo.png)](https://docs.pydantic.dev/latest/why/#org-asml "ASML") [![AstraZeneca](https://docs.pydantic.dev/latest/logos/astrazeneca_logo.png)](https://docs.pydantic.dev/latest/why/#org-astrazeneca "AstraZeneca") [![Cisco Systems](https://docs.pydantic.dev/latest/logos/cisco_logo.png)](https://docs.pydantic.dev/latest/why/#org-cisco "Cisco Systems") [![Comcast](https://docs.pydantic.dev/latest/logos/comcast_logo.png)](https://docs.pydantic.dev/latest/why/#org-comcast "Comcast") [![Datadog](https://docs.pydantic.dev/latest/logos/datadog_logo.png)](https://docs.pydantic.dev/latest/why/#org-datadog "Datadog") [![Facebook](https://docs.pydantic.dev/latest/logos/facebook_logo.png)](https://docs.pydantic.dev/latest/why/#org-facebook "Facebook") [![GitHub](https://docs.pydantic.dev/latest/logos/github_logo.png)](https://docs.pydantic.dev/latest/why/#org-github "GitHub") [![Google](https://docs.pydantic.dev/latest/logos/google_logo.png)](https://docs.pydantic.dev/latest/why/#org-google "Google") [![HSBC](https://docs.pydantic.dev/latest/logos/hsbc_logo.png)](https://docs.pydantic.dev/latest/why/#org-hsbc "HSBC") [![IBM](https://docs.pydantic.dev/latest/logos/ibm_logo.png)](https://docs.pydantic.dev/latest/why/#org-ibm "IBM") [![Intel](https://docs.pydantic.dev/latest/logos/intel_logo.png)](https://docs.pydantic.dev/latest/why/#org-intel "Intel") [![Intuit](https://docs.pydantic.dev/latest/logos/intuit_logo.png)](https://docs.pydantic.dev/latest/why/#org-intuit "Intuit") [![Intergovernmental Panel on Climate Change](https://docs.pydantic.dev/latest/logos/ipcc_logo.png)](https://docs.pydantic.dev/latest/why/#org-ipcc "Intergovernmental Panel on Climate Change") [![JPMorgan](https://docs.pydantic.dev/latest/logos/jpmorgan_logo.png)](https://docs.pydantic.dev/latest/why/#org-jpmorgan "JPMorgan") [![Jupyter](https://docs.pydantic.dev/latest/logos/jupyter_logo.png)](https://docs.pydantic.dev/latest/why/#org-jupyter "Jupyter") [![Microsoft](https://docs.pydantic.dev/latest/logos/microsoft_logo.png)](https://docs.pydantic.dev/latest/why/#org-microsoft "Microsoft") [![Molecular Science Software Institute](https://docs.pydantic.dev/latest/logos/molssi_logo.png)](https://docs.pydantic.dev/latest/why/#org-molssi "Molecular Science Software Institute") [![NASA](https://docs.pydantic.dev/latest/logos/nasa_logo.png)](https://docs.pydantic.dev/latest/why/#org-nasa "NASA") [![Netflix](https://docs.pydantic.dev/latest/logos/netflix_logo.png)](https://docs.pydantic.dev/latest/why/#org-netflix "Netflix") [![NSA](https://docs.pydantic.dev/latest/logos/nsa_logo.png)](https://docs.pydantic.dev/latest/why/#org-nsa "NSA") [![NVIDIA](https://docs.pydantic.dev/latest/logos/nvidia_logo.png)](https://docs.pydantic.dev/latest/why/#org-nvidia "NVIDIA") [![OpenAI](https://docs.pydantic.dev/latest/logos/openai_logo.png)](https://docs.pydantic.dev/latest/why/#org-openai "OpenAI") [![Oracle](https://docs.pydantic.dev/latest/logos/oracle_logo.png)](https://docs.pydantic.dev/latest/why/#org-oracle "Oracle") [![Palantir](https://docs.pydantic.dev/latest/logos/palantir_logo.png)](https://docs.pydantic.dev/latest/why/#org-palantir "Palantir") [![Qualcomm](https://docs.pydantic.dev/latest/logos/qualcomm_logo.png)](https://docs.pydantic.dev/latest/why/#org-qualcomm "Qualcomm") [![Red Hat](https://docs.pydantic.dev/latest/logos/redhat_logo.png)](https://docs.pydantic.dev/latest/why/#org-redhat "Red Hat") [![Revolut](https://docs.pydantic.dev/latest/logos/revolut_logo.png)](https://docs.pydantic.dev/latest/why/#org-revolut "Revolut") [![Robusta](https://docs.pydantic.dev/latest/logos/robusta_logo.png)](https://docs.pydantic.dev/latest/why/#org-robusta "Robusta") [![Salesforce](https://docs.pydantic.dev/latest/logos/salesforce_logo.png)](https://docs.pydantic.dev/latest/why/#org-salesforce "Salesforce") [![Starbucks](https://docs.pydantic.dev/latest/logos/starbucks_logo.png)](https://docs.pydantic.dev/latest/why/#org-starbucks "Starbucks") [![Texas Instruments](https://docs.pydantic.dev/latest/logos/ti_logo.png)](https://docs.pydantic.dev/latest/why/#org-ti "Texas Instruments") [![Twilio](https://docs.pydantic.dev/latest/logos/twilio_logo.png)](https://docs.pydantic.dev/latest/why/#org-twilio "Twilio") [![Twitter](https://docs.pydantic.dev/latest/logos/twitter_logo.png)](https://docs.pydantic.dev/latest/why/#org-twitter "Twitter") [![UK Home Office](https://docs.pydantic.dev/latest/logos/ukhomeoffice_logo.png)](https://docs.pydantic.dev/latest/why/#org-ukhomeoffice "UK Home Office") For a more comprehensive list of open-source projects using Pydantic see the [list of dependents on github](https://github.com/pydantic/pydantic/network/dependents), or you can find some awesome projects using Pydantic in [awesome-pydantic](https://github.com/Kludex/awesome-pydantic).
Shard140 (laksa)
Root Hash6903177193130590940
Unparsed URLdev,pydantic!docs,/latest/ s443