Skip to content

Latest commit

 

History

History
60 lines (37 loc) · 1.23 KB

README.md

File metadata and controls

60 lines (37 loc) · 1.23 KB

pydantic-pony

Package version

Tools to generate Pydantic models from Pony ORM models.

How to use

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)

Release Notes

Latest Changes

0.0.1

  • Added main function pony_to_pydantic.

License

This project is licensed under the terms of the MIT license.