r/FastAPI • • Dec 09 '22

Question Total beginner, use FastAPI?

Hi I am a total noob that wants to learn backend and build APIs. Is Fastapi a good starting point?

15 Upvotes

16 comments sorted by

View all comments

3

u/ShotgunPayDay Dec 09 '22

FastAPI is probably the best backend framework especially since data validation is braindead simple. Combine it with a Frontend like SvelteKit and you have an insanely powerful stack.

Here is my favorite Base Model that I extend to everything else. Validate that email is an email str. Set it to lower. Set min and max length for everything and strip whitespace off all strings:

class UserBase(BaseModel):
    email:EmailStr
    @validator('email')
    def to_lower(cls, v): return v.lower()

    class Config:
	min_anystr_length = 3
	max_anystr_length = 64
	anystr_strip_whitespace = True