Questions tagged [pydantic]

Pydantic is a library for data validation and settings management based on Python type hinting and variable annotations. You can use Pydantic for defining schemas of complex structures in Python.

Pydantic is a library for data validation and settings management based on Python type hinting (PEP484) and variable annotations (PEP526). It allows for defining schemas in Python for complex structures.

1612 questions
0
votes
1 answer

Return list representation in pydantic root validator

I am using pydantic to validate data from a REST API and really like the package so far: from datetime import datetime from typing import Optional, List, Union from pydantic import BaseModel, Field, root_validator from pprint import…
Cord Kaldemeyer
  • 6,405
  • 8
  • 51
  • 81
0
votes
2 answers

I want to change api response json in fastapi | pydantic

I am new in fastapi and please help me! I got an validation error when I change the default API response comes when I use response_model in fastAPI. The default API response is simple json like object from response_model. user.py from fastapi import…
Raj Shah
  • 48
  • 3
  • 10
0
votes
0 answers

How can I link MongoDB collections in FastAPI and implement the pydantic model using pymongo or motor?

Please, can some show me how to do this in fastapi? Sample collections User Collection: { "_id" : "object ID", "name": " str", "email": " str" } UserProfile Collection: { "_id" : "object ID", "first_name": "str", …
0
votes
1 answer

pydantic error during dockerfile execution

I have a fastapi project which is running correctly with docker-compose and the normal run. However, when I try to execute the project with only the dockerfile an error occurs. I HAVE TO read some config from .env and the variables are not updated…
0
votes
0 answers

Cannot return _id field

In the api I'm doing,when a user creates a post,it should return to him the id of it,and when I get all posts it should return the id also,but it's not working that way,sometimes if I use id it works in the schema,or if I use _id it doesn't give an…
user16792099
0
votes
0 answers

Extending base schemas with Pydantic

I'm building a FastAPI project, and in it, I'd like all my errors to be structured as such: errors: { #... whatever } I know I can create a pydantic schema as such: class Error(BaseModel): error: Dict However, for documentation sake, I'd…
Rohit
  • 3,018
  • 2
  • 29
  • 58
0
votes
1 answer

How to add count of items to a FastAPI API using SQLAlchemy and Pydantic?

I have three SQLAlchemy models, let's say a 'project' table, a 'worker' table and an 'equipment' table. I am using the Pydantic Schemas. workers and equipment can be assigned to a project through Foreignkeys (i.e. worker.project_id ==project.id). In…
Reza-sh
  • 1
  • 3
0
votes
1 answer

Pydantic validation issue when using pagination with FastApi

Here is my code snippet: from fastapi_pagination import Page, add_pagination from fastapi_pagination.ext.sqlalchemy import paginate @app.get("/clients", response_model=Page[PydanticModel]) def get_items( db: Session = Depends(get_db) ) -> Any: …
Smaillns
  • 2,540
  • 1
  • 28
  • 40
0
votes
1 answer

Why is sqlalchemy not setting default value correctly?

For some reason, in this example, the optional is_active attribute is not getting set to default value. from pydantic import BaseModel, EmailStr from datetime import datetime # Pydantic schemas # Shared properties class UserBase(BaseModel): …
muon
  • 12,821
  • 11
  • 69
  • 88
0
votes
1 answer

How to post a list of pydantic objects that contain datetime property by using aiohttp to fastapi endpoint?

I have a small web server: # app.py from typing import List from fastapi import FastAPI from pydantic import BaseModel app = FastAPI() class Item(BaseModel): id: int name: str @app.post("/items") async def items_list(items: List[Item]): …
user3225309
  • 1,183
  • 3
  • 15
  • 31
0
votes
0 answers

Issue with SQLAlchemy model on FastAPI

I'm having issues with my SQLAlchemy model schema.Particulary with this schema on my models.py: from sqlalchemy import Boolean, Column, ForeignKey, Integer, String from .database import Base class User(Base): __tablename__ = "users" id =…
0
votes
2 answers

Fastapi pydantic validation: return items grouped by day

I have a FastAPI application. I would like to provide an overview per day of the total steps someone is doing. The database table contains following information: id activity client_ip duration steps …
wiwa1978
  • 2,317
  • 3
  • 31
  • 67
0
votes
1 answer

Is it possible to use pydantic library to validate the input body of python http trigger Azure function

I am new to Azure functions and looking for a way to validate the request data received by my POST request. Is it possible to use pydantic library to perform these validations and if not what is the best way to input validations.
0
votes
1 answer

How can I unpack a pydantic BaseModel to make a 'from_config' class method?

I have a class where I want to add a from_config class method to use a Pydantic BaseModel an example would be class Config(BaseModel): name: str = "Tom" id: int = 1 class User: def __init__(self, name, id): self.name = name …
Tom McLean
  • 5,583
  • 1
  • 11
  • 36
0
votes
1 answer

Passing instance of type self to method as argument

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…
Babbleshack
  • 341
  • 1
  • 5
  • 16