GCB CI status: |
---|
Implements unit of measurement arithmetic, where a number is associated with a product of powers of base units and values with compatible units can be added.
Defines SI units, SI prefixes, and some derived units.
import tunits
from tunits.units import meter, km, N
print(5*meter + km)
# 1005.0 meter
print(N/meter)
# N/meter
print((N/meter).inBaseUnits())
# kg/s^2
print(2*km / tunits.Value(3, 's'))
# 0.666666666667 km/s
-
To install the latest version from the main branch
pip install git+https://github.com/quantumlib/TypedUnits
-
For a local editable copy
git clone https://github.com/quantumlib/TypedUnits cd TypedUnits pip install .
-
Clone the repository.
git clone https://github.com/quantumlib/TypedUnits cd TypedUnits
All future steps assume you are in the repository's directory.
-
Install dev environment dependencies.
pip install -r dev_tools/dev.env.txt
-
Install TUnits
pip install .
-
Test.
pytest
dev_tools/format.sh # to format
dev_tools/format.sh --check # to verify format
Note: This is not an officially supported Google product