Extended kit and tools for pydantic, to enjoy pydantic even more!
- Github repository: https://github.com/manimozaffar/pydkit/
I'll work on this library in few months, i don't have free time right now, but feel free to contribute. I'll check and test the PRs myself!
Use case of CSV read/write would be:
- Saving to a CSV file
from pydkit import csv
from pydantic import BaseModel
class User(BaseModel):
id: int
name: str
users = [
User(id=1, name="Alice"),
User(id=2, name="Abbas"),
]
csv.save("file.csv", users)
- Reading from a CSV file
from pydkit.csv import read, StrNone
from pydantic import BaseModel
class User(BaseModel):
id: int
name: str
last_name: None | StrNone = None
# StrNone helps you with reading from csv files!
users = csv.read("file.csv", User) # now user is list of User
- Type extensions -> Auto converter types
from pydkit.timezones import UTCTime
class User(BaseModel):
created_at: UTCTime
now if you use this model, it'll convert timezones to UTC automatically in your FastAPI application or else, you can also write custom validation
from pydkit.timezones import UTCBiggerThanNow
class User(BaseModel):
future_ts: UTCBiggerThanNow