File: pydantic_support.md

package info (click to toggle)
python-apischema 0.18.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,608 kB
  • sloc: python: 15,266; sh: 7; makefile: 7
file content (11 lines) | stat: -rw-r--r-- 737 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
# Pydantic support

It takes only 30 lines of code to support `pydantic.BaseModel` and all of its subclasses. You could add these lines to your project using *pydantic* and start to benefit from *apischema* features.

This example deliberately doesn't use `set_object_fields` but instead the [conversions feature](../conversions.md) in order to roughly include *pydantic* "as is": it will reuse *pydantic* coercion, error messages, JSON schema, etc. This makes a full retro-compatible support.

As a result, lot of *apischema* features like GraphQL schema generation or `NewType` validation cannot be supported using this method — but they could be by using `set_object_fields` instead. 

```python
{!examples/pydantic_support.py!}
```