Impunity: A Python library to check physical units

>>> Get Started <<<

Easy to use

Based on a decorator, to add on any annotated function or class

Support for various annotation styles

Usable with Annotated object or string annotations

Integration with popular Python type checkers.

Can be used along mypy for powerful typing systems

No additional runtime overhead

Impunity works directly on the AST for a static analysis of your code

@impunity
def speed(d: "m", t: "s") -> "m / s":
   return d / t

speed(10, 10) # returns 1
@impunity
def speed(d: "m", t: "s") -> "km / h":
   return d / t

speed(10, 10) # returns 3.6
@impunity
def speed(d: "m", t: "s") -> "feet":
   return d / t

# Warning: "Incompatible unit returned"
@impunity
def speed(d: "m", t: "s") -> "m / s":
   return d + t

# Warning: "Types are not compatible"