Skip to content

ManiMozaffar/PydKit

Repository files navigation

PydKit

Release Build status codecov Commit activity License

Extended kit and tools for pydantic, to enjoy pydantic even more!

Contribution

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!

Features

Use case of CSV read/write would be:

  1. 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)
  1. 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
  1. 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