pydantic

How should we manage datetime fields in SQLModel in python?

How should we manage datetime fields in SQLModel in python? Question: Let’s say I want to create an API with a Hero SQLModel, below are minimum viable codes illustrating this: from typing import Optional from sqlmodel import Field, Relationship, SQLModel from datetime import datetime from sqlalchemy import Column, TIMESTAMP, text class HeroBase(SQLModel): # essential fields …

Total answers: 1

Flatten nested Pydantic model

Flatten nested Pydantic model Question: from typing import Union from pydantic import BaseModel, Field class Category(BaseModel): name: str = Field(alias="name") class OrderItems(BaseModel): name: str = Field(alias="name") category: Category = Field(alias="category") unit: Union[str, None] = Field(alias="unit") quantity: int = Field(alias="quantity") When instantiated like this: OrderItems(**{‘name’: ‘Test’,’category’:{‘name’: ‘Test Cat’}, ‘unit’: ‘kg’, ‘quantity’: 10}) It returns data like …

Total answers: 3

Inherit as required only some fields from parent pandera SchemaModel

Inherit as required only some fields from parent pandera SchemaModel Question: I have Input and Output pandera SchemaModels and the Output inherits the Input which accurately represents that all attributes of the Input schema are in the scope of the Output schema. What I want to avoid is inheriting all attributes as required (non-Optional) as …

Total answers: 2

How to call POST API using body prams in angular [ raise 422 error (Unprocessable Entity)]

How to call POST API using body prams in angular [ raise 422 error (Unprocessable Entity)] Question: I’m struggling to use Post API using FastAPI , Angular while using HttpClient.post Function the issue with receiving the prams in the backend FastAPI no seeing the prams and raise 422 (Unprocessable Entity) Mybackend API CODE (FastAPI-Python): from …

Total answers: 1

Get all required fields of a nested Python Pydantic model

Get all required fields of a nested Python Pydantic model Question: My pydantic nested model is defined as below: from pydantic import BaseModel from typing import Optional class Location(BaseModel): city: Optional[str] state: str country: str class User(BaseModel): id: int name: Optional[str] = "Gandalf" age: Optional[int] location: Location I would like to get all required fields …

Total answers: 1

How to validate based on specific Enum member in a Fastapi Pydantic model

How to validate based on specific Enum member in a Fastapi Pydantic model Question: Here is my Pydantic model: from enum import Enum from pydantic import BaseModel class ProfileField(str, Enum): mobile = "mobile" email = "email" address = "address" interests ="interests" # need list of strings class ProfileType(str, Enum): primary = "primary" secondary = "secondary" …

Total answers: 1

Is there an advantage to Lambda Powertools’s Parser over straight Pydantic?

Is there an advantage to Lambda Powertools’s Parser over straight Pydantic? Question: I’ve got models which inherit Pydantic’s BaseModel and I use this to define my model attributes and do some validation. But I see that Lambda Powertools comes with a Parser module which uses Pydantic. Now that I want to use these models within …

Total answers: 1

Is there a way to convert a file path field to a parsed model in-place?

Is there a way to convert a file path field to a parsed model in-place? Question: If I have two models, the second of which has a file path field referencing a file, whose contents are described by the first model. Is it possible to expand the file contents in place (replace the file path …

Total answers: 1