si library for python

python class for si quantities

the library includes a module with all si units with common prefixes (e.g. m, mmol), common (prefixed) derived units (kN, l), other units (c, eV).

an example:

>>> from si.common import *
>>> mass=5*kg
>>> height=10*cm
>>> gravity=9.81*m/s/s
>>> energy=mass*gravity*height
>>> print energy
4.905 J

the module can also be used together wity SymPy:

>>> import si.mathmodules
>>> si.mathmodules.choose('sympy')
>>> from si.common import *
>>> print Oe # Oersted: old CGS unit of magnetic field
250/pi A/m

download

you can fetch the module from the python package index in the most recent version. (using setuptools, installation is as easy as sudo easy_install si.)

meta

the si library was written by chrysn in 2007 and is published under the terms of the GNU GPL.