fast api Flashcards

1
Q

conint

A

from pydantic import conint

class ExampleModel(BaseModel):
age: conint(gt=18, le=99) # age must be between 19 and 99 inclusive

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

constr

A

from pydantic import BaseModel, constr

class ExampleModel(BaseModel):
name: constr(min_length=3, max_length=50, regex=’^[a-zA-Z ]+$’) # name must be between 3 and 50 characters, and only contain letters and spaces

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

conlist

A

from pydantic import BaseModel, conlist

class ExampleModel(BaseModel):
tags: conlist(str, min_items=1, max_items=5) # tags must be a list of strings with 1 to 5 items

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

confloat

A

from pydantic import BaseModel, confloat

class ExampleModel(BaseModel):
price: confloat(ge=0.0) # price must be a non-negative float

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

condecimal

A

from pydantic import BaseModel, condecimal
from decimal import Decimal

class ExampleModel(BaseModel):
balance: condecimal(gt=Decimal(‘0.0’), max_digits=10, decimal_places=2) # balance must be a positive decimal with up to 10 digits and 2 decimal places

How well did you know this?
1
Not at all
2
3
4
5
Perfectly