Skip to content

Latest commit

 

History

History

si-units

si-units

documentation PyPI version

Representation of quantities with SI units.

The package 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 and Usage

You can install the package from PyPI

pip install si-units

For the documentation, see here.

To build the wheel or documentation locally, see below.

Examples

Calculate the pressure of an ideal gas.

from si_units import *
temperature = 25.0 * CELSIUS
volume = 1.5 * METER**3
moles = 75.0 * MOL
pressure = moles * RGAS * temperature / volume
print(pressure) # 123.94785148011941 kPa

numpy functions can be used with SI units:

from si_units import *
import numpy as np
ms = np.linspace(2.0, 4.0, 3) * METER
sqms = ms**2
print(sqms) # [4, 9, 16] m²

Building from Source

You need a rust compiler to build the wheel locally. To build the bindings to python, we use maturin.

Use

# in si-units
maturin develop --release

to build the package locally.

To build the python wheels, use

maturin build --release

Building the Documentation

To build the documentation you need mkdocs-material and mkdocstrings-python. Installing these packages (e.g. using uv or pip) will also install the needed dependencies. During development, use

# in si-units
mkdocs serve

to run a local development server.

To build the documentation for deployment, use

# in si-units
mkdocs build