https://github.com/robintw/sqlalchemy-units-example
Example code from 'Pint + SQLAlchemy = Unit consistency and enforcement in your database' poster at PyData Global 2020
https://github.com/robintw/sqlalchemy-units-example
pint sqlalchemy units
Last synced: about 1 year ago
JSON representation
Example code from 'Pint + SQLAlchemy = Unit consistency and enforcement in your database' poster at PyData Global 2020
- Host: GitHub
- URL: https://github.com/robintw/sqlalchemy-units-example
- Owner: robintw
- Created: 2020-09-21T19:16:16.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-09-22T08:20:15.000Z (over 5 years ago)
- Last Synced: 2025-04-01T15:57:20.065Z (about 1 year ago)
- Topics: pint, sqlalchemy, units
- Language: Python
- Homepage:
- Size: 5.86 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Pint + SQLAlchemy example code
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:
1. Install the dependencies with `pip install -r requirements.txt`.
2. Look at [model_basic.py](model_basic.py) and [demo_basic.py](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.
3. Look at [model_units.py](model_units.py) to see how the model has been changed to check and enforce units, and then [demo_units.py](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 in `demo_units.py` to see what happens when you try and give a value with incorrect units.
Please feel free to contact me on robin@rtwilson.com with any questions - I will endeavour to get back to you as soon as I can.