Category "pydantic"

How to specify a BaseSettings Config's env_file based on a field from the same class?

I want to implement this logic from pydantic import BaseSettings class Settings(BaseSettings): ENVIRONMENT: str = 'local' SECRET_KEY: str = 'someke

How to generate Pydantic model for multiple different objects

I need to have a variable covars that contains an unknown number of entries, where each entry is one of three different custom Pydantic models. In this case, ea

`pyyaml` can't parse `pydantic` object if `typing` module is used

Let me start off by saying I wanted to open an issue in pydantic repo. Once I started rubber duck debugging I came up to the conclusion it's actually pyyaml tha

Problems with ABC/Interfaces using pydantic + Mixins pattern

Im trying to implement Mixin patter while Im using Pydantics BaseClass to facilitate the instantiation and validation of data from my class. The problem is that

How to JSONIFY a dict having a pydantic model

I am new to pydantic and am stuck. Below code is throwing error TypeError: Type is not JSON serializable: Person from pydantic import BaseModel,Extra from typin

How to create mutually exclusive fields in Pydantic

I am using Pydantic to model an object. How can I make two fields mutually exclusive? For instance, if I have the following model: class MyModel(pydantic.BaseMo

The alias field of the Pydantic Model schema is by default in swagger instead of the original field

I need to receive data from an external platform (cognito) that uses PascalCase, and the Pydantic model supports this through field aliases, adding an alias_gen

using nested classes for organize Model, how to "crossreference"

I'm want to use nested classes to organize my pydantic models. So something like this: class AttributeValue(BaseModel): id: int typeid: int value: str cl

How to initialize a Pydantic object from field values given by position instead of name?

I am not able to find a simple way how to initialize a Pydantic object from field values given by position (for example in a list instead of a dictionary) so I

Can I get incoming extra fields from Pydantic?

I have defined a pydantic Schema with extra = Extra.allow in Pydantic Config. Is it possible to get a list or set of extra fields passed to the Schema separatel

Python Enum and Pydantic : accept enum member's composition

I have an enum : from enum import Enum class MyEnum(Enum): val1 = "val1" val2 = "val2" val3 = "val3" I would like to validate a pydantic field bas

Pydantic - Dynamically create a model with multiple base classes?

From the pydantic docs I understand this: import pydantic class User(pydantic.BaseModel): id: int name: str class Student(pydantic.BaseModel): sem

How to add both file and JSON body in a FastAPI POST request?

Specifically, I want the below example to work: from typing import List from pydantic import BaseModel from fastapi import FastAPI, UploadFile, File app = Fas

Pydantic enum field does not get converted to string

I am trying to restrict one field in a class to an enum. However, when I try to get a dictionary out of class, it doesn't get converted to string. Instead it re

FastAPI - GET Request with Pydantic List field

I'm new to FastAPI (migrating from Flask) and I'm trying to create a Pydantic model for my GET route: from fastapi import APIRouter,Depends from pydantic import

Make Pydantic chuck error for wrong argument names

Suppose I have the following class: class ModelConfig(pydantic.BaseModel): name: str = "bert" If I were to instantiate it with model_config = ModelConfig(n

Is it possible to have a union of url and FilePath in Pydantic?

I wonder if this would somehow be possible: class Picture(BaseModel): src: Union[FilePath, stricturl(allowed_schemes=["https"])] I have this test, which is

Is there a way to exclude Pydantic models from FastAPI's auto-generated documentation?

Is there a way for a FastAPI application to not display a model in its schema documentation? I have some models which are slight variations of others, and with

Python [Pydantic] - default values based other object in the class

I would like to set default email in case email not provided, i.e: name = a last_name = b email = None email will become "[email protected]" I tried something li

How do I pass kwargs to pydantic validator

I'm trying to write pydantic validators, but I can't seem to understand how to make use of the kwargs argument that is mentioned in the docs. I would like to p