Contents

pydantic 2.6.4

0

Data validation using Python type hints

Data validation using Python type hints

Stars: 18411, Watchers: 18411, Forks: 1614, Open Issues: 352

The pydantic/pydantic repo was created 6 years ago and the last code push was 4 hours ago.
The project is extremely popular with a mindblowing 18411 github stars!

How to Install pydantic

You can install pydantic using pip

pip install pydantic

or add it to a project with poetry

poetry add pydantic

Package Details

Author
License
Homepage
PyPi:
https://pypi.org/project/pydantic/
Documentation:
https://docs.pydantic.dev
GitHub Repo:
https://github.com/samuelcolvin/pydantic

Classifiers

  • Internet
  • Software Development/Libraries/Python Modules
No  pydantic  pypi packages just yet.

Errors

A list of common pydantic errors.

  • [pydantic] NameError: Field name "schema" shadows a BaseModel attribute; use a different field name with "alias='schema'".

    This error is encountered when you define a pydantic class that has a attributed named schema. class EmbedDoc(BaseModel): schema: int = 1 name: str = Field(str) tags: List[str] archived: bool The schema attribute is special field for pydantic……. Workaround You can specify a field alias and when the document is serialized it will use the field name schama instead of schema_. class EmbedDoc(BaseModel): schema_: int = Field(1, alias="schema") name: str = Field(str) tags: List[str] archived: bool

Code Examples

Here are some pydantic code examples and snippets.

  • beanie code example from docs

    The following beanie code example shows how the library works by first defining two pydantic classes and then save a record to the database and retreiving a record. beanie utilizes pydantic and `motor`` to provide an asyncronys ODM for mongodb.

GitHub Issues

The pydantic package has 352 open issues on GitHub

  • build(deps): bump pre-commit from 2.16.0 to 2.17.0
  • build(deps): bump mkdocs-material from 8.1.3 to 8.1.8
  • avoid deepcopying object default
  • Fix pytest crashes with hypothesis and pydantic
  • New type StrLimited
  • Fixed docs about custom encoders
  • Added abstract SecretField class for secret fields
  • Pylance reports problem in match-case statement (PEP 634) with dataclasses
  • Add Robusta.dev to list of Pydantic users
  • ValueError raised when Nested Discriminated Unions are used twice
  • Fix issue with self-referencing dataclass
  • Linting error when using nested models with optional arguments
  • Equatable base dataclasses become inequatable when used as BaseModel fields
  • build(deps): bump hypothesis from 6.31.6 to 6.36.0
  • Prevent subclasses of bytes being converted to bytes

See more issues on GitHub

Related Packages & Articles

fastapi 0.110.1

FastAPI framework, high performance, easy to learn, fast to code, ready for production

apispec 6.6.0

A pluggable API specification generator. Currently supports the OpenAPI Specification (f.k.a. the Swagger specification).