{"repo":"georgebv/drf-pydantic","free":true,"listed":false,"github":"https://github.com/georgebv/drf-pydantic","clone":"git clone https://github.com/georgebv/drf-pydantic.git","description":"Use pydantic with the Django REST framework","language":"Python","stars":147,"topics":["django","django-framework","django-rest-framework","djangorestframework","drf","drf-spectacular","pydantic","pydantic-django"],"license":"MIT","category":"api-integrations-sdks","readme_excerpt":"Use pydantic with Django REST framework - Introduction - Performance - Installation - Usage - General - Pydantic Validation - Updating Field Values - Validation Errors - Accessing the Validated Pydantic Instance - Existing Models - Nested Models - Manual Serializer Configuration - Per-Field Configuration - Custom Serializer - Additional Properties Introduction Pydantic is a Python library used to perform data serialization and validation. Django REST framework is a framework built on top of Django used to write REST APIs. If you develop DRF APIs and rely on pydantic for data validation/(de)serialization, then drf-pydantic is for you :heart eyes:. [!NOTE] The latest version of drf pydantic only supports pydantic v2. Support for pydantic v1 is available in the 1. version. Performance Translation between pydantic models and DRF serializers is done during class creation (e.g., when you first import the model). This means there will be zero runtime impact when using drf pydantic in your application. [!NOTE] There will be a minor penalty if validate pydantic is set to True due to pydantic model validation. This is minimal compared to an already-present overhead of DRF itself because pydantic runs its validation in rust while DRF is pure python. Installation Usage General Use drf pydantic.BaseModel instead of pydantic.BaseModel when creating your models: MyModel.drf serializer is equivalent to the following DRF Serializer class: Whenever you need a DRF serializer, you can get it fro","default_branch":null,"files":null,"tree":[],"storefront":"/r/georgebv","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/georgebv/drf-pydantic/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}