Welcome to si-units
This package provides representations of quantities with SI units. It is written with flexibility in mind and is able to represent arbitrarily complex units. In addition to simple scalar quantities, it can be used to decorate any complex data type (numpy arrays, PyTorch tensors) to provide unit checks.
Installation
You can install si-units
from pypi using pip
:
pip install si-units
Build from source
To build the code from source, you need the rust compiler.
maturin
With maturin installed:
git clone https://github.com/itt-ustutt/quantity
cd quantity/si-units
maturin build --release
You can then install the generated wheel (placed in quantity/target/wheels
) into your Python environment.
uv
You can use uv to build the wheel:
git clone https://github.com/itt-ustutt/quantity
cd quantity/si-units
uv build
You can then install the generated wheel (placed in dist/
) into your Python environment.
Usage
Ideal gas pressure | |
---|---|
1 2 3 4 5 6 |
|
123.94785148011941 kPa
This also works with numpy.ndarray
:
Using numpy | |
---|---|
1 2 3 4 5 |
|
[4, 9, 16] m²
When you divide a quantity by its unit, the value
(i.e. float
for scalars or numpy.ndarray[float]
for arrays) is returned.
You can use this to convert units:
Unit conversion | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 |
|
V = 8.9e+06 A^3
See Examples section for more use cases.