> Every page of the ganymede website is listed in https://eugo.io/docs/ganymede/llms.txt.

# PyDantic

> PyDantic: Data validation using Python type hints. A Python demo notebook from ganymede.

Web page: https://eugo.io/docs/ganymede/demo_notebooks/data_processing/pydantic/
Notebook: https://eugo.io/docs/ganymede/demo_notebooks/data_processing/pydantic/pydantic.ipynb (source: https://github.com/eugo-inc/ganymede/blob/main/demo_notebooks/data_processing/pydantic.ipynb)

Description:
- Data validation using Python type hints.

Resources:
- [GitHub] https://github.com/pydantic/pydantic
- [Docs] https://docs.pydantic.dev/latest/

Source and license:
- Some of these examples are adapted from the pydantic README (https://github.com/pydantic/pydantic), Copyright (c) 2017 to present Pydantic Services Inc. and individual contributors, licensed under MIT. That code stays under its own license; see [THIRD_PARTY_NOTICES.md](https://github.com/eugo-inc/ganymede/blob/main/THIRD_PARTY_NOTICES.md).

## Example 1

Validate a custom model

```python
from datetime import datetime
from pydantic import ValidationError
from pydantic import BaseModel, PositiveInt
from typing import Optional

class User(BaseModel):
    id: int
    name: str = 'John Doe'
    signup_ts: Optional[datetime]
    tastes: dict[str, PositiveInt]

external_data = {'id': 'not an int', 'tastes': {}}

try:
    User(**external_data)
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',
        },
    ]
    """
```
