Tools to generate Pydantic models from Pony ORM models.
Quick example:
# ... other imports
from pydantic_pony import pony_to_pydantic
class Person(db.Entity):
name = Required(str)
age = Required(int)
cars = Set('Car')
passport = Optional("Passport")
created = Required(datetime, default=datetime.now)
updated = Required(datetime, default=datetime.now)
class Car(db.Entity):
make = Required(str)
model = Required(str)
owner = Required(Person)
# Transform Pony Model to Pydantic
PydanticPerson = pony_to_pydantic(Person)
PydanticCar = pony_to_pydantic(Car)
person = select(p for p in Person).first()
pydantic_person = PydanticPerson.from_orm(person)
# Inherit
class PydanticPersonWithCars(PydanticPerson):
cars: List[PydanticCar] = []
pydantic_person_with_cars = PydanticPersonWithCars.from_orm(person)
- Added main function
pony_to_pydantic
.
This project is licensed under the terms of the MIT license.