Category : pydantic

I have the following Pydantic model: from pydantic import BaseModel import key class Wallet(BaseModel): private_key: str = Field(default_factory=key.generate_private_key) address: str I want address to have a default_factory as a function that takes a private_key as input and returns an address. My intentions would be something along the lines of the following: address: str = Field(default_factory=key.generate_address(self.private_key) ..

Read more

I would like to pass an instance of PipelineTask to PipelineTask.add however when I try I get a NameError which mentions PipelineTask is not defined. I believe this is because PipelineTask is only bound after PipelineTask.__init__() is called. class Task(BaseModel, abc.ABC): id: str @abc.abstractmethod async def run(self): pass class PipelineTask(Task): @abc.abstractmethod async def run(self): pass ..

Read more

I have function which returns another function. Example: def create_object() -> Callable[[str, Optional[int], str]: def create(name: str, length: int = 10) -> str: return # do something return create How I need to define Callable for length parameter with default value? If I will try to call this function only with name ( create_object()(‘Name’) ) ..

Read more

I have these two Python classes(Pydantic schemas which represent SQLAlchemy models): class Role(RoleBase): id: int users: list[User] = [] class Config: orm_mode = True class User(UserBase): id: int date_created: datetime.datetime profile_image: Optional[str] = None class Config: orm_mode = True I’ve tried to do it with ForwardRef: User = ForwardRef(‘User’) … users: list[User] = [] or ..

Read more

I want to use FastAPI without an ORM (using asyncpg) and map the returned values from a select query to a pydantic model. This way the returned values are validated with pydantic and the response that is returned is structured like the pydantic model/schema. I’ve tried looking for documentation on this but it’s pretty hard ..

Read more