qunits logo qunits logo

A performant, verbose and generic physical unit system.

Static Badge Static Badge

© 2026 Patrick Müller. All rights reserved.

qunits. Unit  (  scale ,  exp_map ,  dimension ,  context  )[source]

A physical unit. Units are usually taken from the registry u and combined with *, / and ** (integer powers). Multiplying a number or an array with a unit creates a Quantity.

There is exactly one unit per exponent map, so units can be compared with is.

Defines a new unit. If the unit is already defined with the same scale, dimension and context, the existing unit is returned.

Parameters:
scalescalar

The scale factor of the unit relative to the SI unit of its dimension, e.g. 1000.0 for km.

exp_mapExpMap

The exponent map of the unit, e.g. frozenset({("km", 1)}).

dimensiontype[Dimension]

The Dimension of the unit.

contextContext

The Context of the unit.

Attributes:
contextContext

The Context of the unit. Only quantities with the same dimension and context can be added, subtracted or converted into each other.

dtype[Dimension]

The Dimension of the unit, same as dimension.

dimtype[Dimension]

The Dimension of the unit, same as dimension.

dimensiontype[Dimension]

The Dimension of the unit.

exp_mapExpMap

The ExpMap of the unit, e.g. frozenset({("m", 1), ("s", -1)}) for m/s. It identifies the unit and is how the unit is printed.

scalefloat

The scale factor of the unit relative to the SI unit of its dimension, e.g. 1000.0 for km.

Raises:
ValueError

If a unit with the same exp_map but another scale, dimension or context is defined.