This repo contains the example code that goes with the Pint + SQLAlchemy = Unit consistency and enforcement in your database poster at PyData Global 2020.
To use:
-
Install the dependencies with
pip install -r requirements.txt
. -
Look at model_basic.py and demo_basic.py which show standard SQLAlchemy code to define a simple model and use it to insert a couple of rows into a database table. Nothing in these files is novel - this is standard SQLAlchemy usage. Running
demo_basic.py
will print out a bit of information about the rows inserted. -
Look at model_units.py to see how the model has been changed to check and enforce units, and then demo_units.py to see how to use the new model. Running
demo_units.py
will show the values at various stages, showing that unit conversion and enforcement has happened. Uncomment some of the commented lines indemo_units.py
to see what happens when you try and give a value with incorrect units.
Please feel free to contact me on [email protected] with any questions - I will endeavour to get back to you as soon as I can.