8.5 Extras
Here are some ideas for you to add to this project.
8.5.1 Revise all previous chapter models to use Pydantic
The previous chapters used dataclass
definitions from the dataclasses
module. These can be shifted to use the pydantic.dataclasses
module. This should have minimal impact on the previous projects.
We can also shift all of the previous acceptance test suites to use a formal schema definition for the source data.
8.5.2 Use the ORM layer
For SQL extracts, an ORM can be helpful. The pydantic
module lets an application create Python objects from intermediate ORM objects. This two-layer processing seems complex but permits detailed validation in the Pydantic objects that aren’t handled by the database.
For example, a database may have a numeric column without any range provided. A Pydantic class definition can provide a field definition with ge
and le
attributes to define a range. Further, Pydantic permits the definition of a unique data type with unique validation...