Skip to main content
https://github.com/cjrh/misu/actions/workflows/ci.yml/badge.svg?branch=master https://coveralls.io/repos/github/cjrh/misu/badge.svg?branch=master https://img.shields.io/pypi/pyversions/misu.svg https://img.shields.io/github/tag/cjrh/misu.svg https://img.shields.io/pypi/v/misu.svg

misu

misu is short for “misura”, which means measurement (in Italian). misu is a package for doing calculations with in consistent units of measurement.

Install

Precompiled wheels are published to PyPI for Linux (x86_64, aarch64), macOS (x86_64, aarch64), and Windows (x64), covering Python 3.9 and later. There is nothing to compile.

uv add misu        # in a uv project
uv pip install misu
pip install misu

Demo

Most of the time you will probably work with misu interactively, and it will be most convenient to import the entire namespace:

from misu import *

mass = 100*kg
print(mass >> lb)

The symbol kg got imported from the misu package. We redefine the shift operator to perform inline conversions. The code above produces:

220.46226218487757

There are many units already defined, and it is easy to add more. Here we convert the same quantity into ounces:

print(mass >> oz)

output:

3571.4285714285716

What you see above would be useless on its own. What you really need is to be able to perform consistent calculations with quantities expressed in different, but compatible units:

mass = 10*kg + 20*lb
print(mass)

output:

19.07 kg

For addition and subtraction, misu will ensure that only consistent units can be used. Multiplication and division will produce new units:

distance = 100*metres
time = 9.2*seconds

speed = distance / time
print(speed)

output:

10.87 m/s

As before, it is trivially easy to express that quantity in different units of compatible dimensions:

print(speed >> km/hr)

output:

39.130434782608695

Introduction

misu is a package of handling physical quantities with dimensions. This means performing calculations with all the units being tracked correctly. It is possible to add kilograms per hour to ounces per minute, obtain the correct answer, and have that answer be reported in, say, pounds per week.

misu grew out of a personal need. I have used this code personally in a (chemical) engineering context for well over a year now (at time of writing, Feb 2015). Every feature has been added in response to a personal need.

Features

  • Speed optimized. misu is very fast! Heavy math code in Python is only around 5X slower when expressed with misu quantities instead of plain floats — see Performance below for measured numbers. This is much faster than other quantities packages for Python.

  • Implemented as a Rust extension module via PyO3, so the hot paths run as native code.

  • When an operation involving incompatible units is attempted, an EIncompatibleUnits exception is raised, with a clear explanation message about which units were inconsistent.

  • Decorators for functions to enforce dimensions

@dimensions(x='Length', y='Mass')
def f(x, y):
    return x/y

f(2*m, 3*kg)         # Works
f(200*feet, 3*tons)  # Works

f(2*joules, 3*kelvin)  # raises AssertionError
f(2*m, 3)              # raises AssertionError
  • An operator for easily stripping the units component to obtain a plain numerical value

mass = 100 * kg
mass_lb = mass >> lb

duty = 50 * MW
duty_BTU_hr = duty >> BTU / hr
  • An enormous amount of redundancy in the naming of various units. This means that m, metre, metres, METRE, METRES will all work. The reason for this is that from my own experience, when working interactively (e.g. in the IPython Notebook) it can be very distracting to incorrectly guess the name for a particular unit, and have to look it up. ft, foot and feet all work, m3 means m**3 and so on.

  • You can specify a reporting unit for a dimension, meaning that you could have all lengths be reported in “feet” by default for example.

  • You can specify a reporting format for a particular unit.

Performance

Two looping numerical workloads, each timed in plain Python floats and then with misu quantities (so every operation in the inner loop pays the unit-tracking cost). The benchmark lives at scripts/benchmark.py and can be re-run any time:

python scripts/benchmark.py

Representative numbers on Python 3.14, best of five runs:

Workload

float (ms)

misu (ms)

slowdown

fall_with_drag — 200k Euler steps, 1-D free-fall with quadratic drag

~19

~103

~5.2x

orbit_step — 100k 2-D Kepler steps, sqrt-heavy

~18

~91

~5.1x

Geometric mean

~5.1x

The original 5x heuristic was measured back when misu was a Cython extension; the rewrite to a Rust/PyO3 extension lands in the same ballpark, presumably because the dominant cost is the Python-call boundary around each __mul__ / __add__ rather than the unit-arithmetic itself.

There are other projects, why misu?

There are several units systems for Python, but the primary motivating use-case is that misu is written as a Rust extension module and is by far the fastest* for managing units available in Python.

*Except for ``NumericalUnits``, which is a special case

**I haven’t actually checked that this statement is true for all of them yet.

General usage

For speed-critical code, the application of unit operations can still be too slow. In these situations it is typical to first cast quantities into numerical values (doubles, say), perform the speed-critical calculations (perhaps call into a C-library), and then re-cast the result back into a quantity and return that from a function.

@dimensions(x='Length', y='Mass')
def f(x, y):
    x = x >> metre   # Converts to metres, leaving a primitive float
    y = y >> ounces  # Converts to metres, leaving a primitive float
    <code that assumes meters and ounces, returns value in BTU>
    # Convert the primitive float to BTU on the way out
    return answer * BTU

This way you can still easily wrap performance-critical calculations with robust unit-handling.

Inspiration

The inspiration for misu was Frink by Alan Eliasen. It is wonderful, but I need to work with units in the IPython Notebook, and with all my other Python code.

There are a bunch of other similar projects. I have not used any of them enough yet to provide a fair comparison:

Releasing

Publishing to PyPI is automated via GitHub Actions and PyPI trusted publishing (OIDC). No API tokens or passwords are stored anywhere — PyPI trusts the cjrh/misu repo’s release.yml workflow running in the pypi environment, and rejects everything else.

Cutting a release

The version lives in Cargo.toml. pyproject.toml declares dynamic = ["version"], so maturin reads it from the Rust crate at build time — there is only one place to edit.

Use cargo-release to bump, commit, tag, and push in one step. From a clean master:

cargo release patch --execute   # 2.0.0 → 2.0.1
cargo release minor --execute   # 2.0.0 → 2.1.0
cargo release major --execute   # 2.0.0 → 3.0.0
cargo release 2.0.5 --execute   # explicit version

Drop --execute for a dry run.

What happens automatically

cargo-release performs the following steps locally:

  1. Bumps version in Cargo.toml and updates Cargo.lock.

  2. Commits the change with the message Release <version>.

  3. Creates an annotated tag v<version>.

  4. Pushes the branch and the tag to origin.

The tag push triggers .github/workflows/release.yml, which:

  1. Builds wheels for Linux (x86_64, aarch64), macOS (x86_64, aarch64), and Windows (x64), plus an sdist. Because PyO3 is configured with abi3-py39, one wheel per (OS, arch) covers all supported Python versions.

  2. Downloads all artifacts into the release job, which runs in the pypi GitHub environment.

  3. Uploads to PyPI via pypa/gh-action-pypi-publish. Authentication happens via OIDC against the trusted-publisher configuration on PyPI; nothing else is needed.

If the build jobs succeed but the release job fails (for example, the PyPI environment was not configured), nothing is published, and the release can be retried by re-running just the failed job.

Troubleshooting

  • cargo-release refuses with “uncommitted changes” — commit or stash first; cargo-release insists on a clean tree.

  • cargo-release refuses with “not on allowed branch” — release only from master (the default allow-branch setting).

  • PyPI rejects the upload with “version already exists” — PyPI filenames are immutable; bump again.

  • Tag pushed but workflow did not run — check the tag matches the tags: '*' trigger in release.yml and that the pypi GitHub environment exists with no protection rules blocking the run.

Release files for misu 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for misu 2.1.0
File Size Uploaded
misu-2.1.0.tar.gz 54.0 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for misu 2.1.0
File
misu-2.1.0-cp314-cp314t-win_amd64.whl CPython 3.14 CPython 3.14 free-threading Windows x86-64 Details
misu-2.1.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64 Details
misu-2.1.0-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ ARM64 Details
misu-2.1.0-cp314-cp314t-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 Details
misu-2.1.0-cp314-cp314t-macosx_10_12_x86_64.whl CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64 Details
misu-2.1.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
misu-2.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details
misu-2.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details
misu-2.1.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details
misu-2.1.0-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details

Total release size:3.2 MB

Release files / misu-2.1.0.tar.gz

Download URL misu-2.1.0.tar.gz
Size 54.0 kB
Tags Source
SHA-256 checksum
How to use checksums
4e9d64d0d2d9804f1873f1c89397e01ecbc31029b41eb11c400a8e37c0d931af
BLAKE2b-256 checksum
How to use checksums
76d3e50b2565e5cebacb49a5d3c72ce3eb158f684758ef201c222bf6c4d77e1c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 18, 2026.

Transparency log

Release files / misu-2.1.0-cp314-cp314t-win_amd64.whl

Download URL misu-2.1.0-cp314-cp314t-win_amd64.whl
Size 240.0 kB
Tags CPython 3.14 CPython 3.14 free-threading Windows x86-64
SHA-256 checksum
How to use checksums
1300be7e501498282e1e60b8df17a4b08e774c085bfdc15d27cd4ebfa595e0ba
BLAKE2b-256 checksum
How to use checksums
8aa1b1ae057454d4547c94eaef0e7271227d6396ee565bb10fee0acb20646f22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 18, 2026.

Transparency log

Release files / misu-2.1.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL misu-2.1.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 339.8 kB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
fd684df194ab328297f81455e91ff783017c477e784e51f6a77f04fb838dfceb
BLAKE2b-256 checksum
How to use checksums
9c3c674163e1ce2299b8490eea78de450e957bfe9b7c707dc2c230061eb8d227
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 18, 2026.

Transparency log

Release files / misu-2.1.0-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL misu-2.1.0-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 324.5 kB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
d39aea20a433df56c67b88de0b22258a0086d867aa9e1c8893651b18dec71675
BLAKE2b-256 checksum
How to use checksums
9985331bd5dad1d2ced9420dd1a0cf43f2aff92fd1512ecd1f0622d0d43f7e30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 18, 2026.

Transparency log

Release files / misu-2.1.0-cp314-cp314t-macosx_11_0_arm64.whl

Download URL misu-2.1.0-cp314-cp314t-macosx_11_0_arm64.whl
Size 306.1 kB
Tags CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
643f532a0cd21269826c66755ca93402b86c7ad6f2d83390a864e51f759aca31
BLAKE2b-256 checksum
How to use checksums
105cbe205a8b9b32d4c2d9806ca106cdbdb3e86490b540595f425bebef2837e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 18, 2026.

Transparency log

Release files / misu-2.1.0-cp314-cp314t-macosx_10_12_x86_64.whl

Download URL misu-2.1.0-cp314-cp314t-macosx_10_12_x86_64.whl
Size 327.4 kB
Tags CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
6b6fabe566a1a41c2526be8bb3766cd0f770ef29444f8545c4db95808783bf71
BLAKE2b-256 checksum
How to use checksums
11b6d6462fda1a7170e575a2373797a0502291dea5211c70612a464b6b9830f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 18, 2026.

Transparency log

Release files / misu-2.1.0-cp39-abi3-win_amd64.whl

Download URL misu-2.1.0-cp39-abi3-win_amd64.whl
Size 247.9 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
0cda3ffeccf50c133acc72bd392dad4cc7ec2323ae3c42571b2ef889a7d65ab3
BLAKE2b-256 checksum
How to use checksums
7ef44779cadf360e53363cc2b672b006135f2516552a3e8ce24d0b1df092668d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 18, 2026.

Transparency log

Release files / misu-2.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL misu-2.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 347.2 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
ecacdb5015b1cd71cd497ce8d88a32918fe83891115a5d17bc272eccc433ef57
BLAKE2b-256 checksum
How to use checksums
4d985c1d6ea772188b5b9160c9a58264ad353abbb10b279fefa035a9d9718e70
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 18, 2026.

Transparency log

Release files / misu-2.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL misu-2.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 332.1 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
1870593ddb8d3923201b87a489a524e66ff2ebcfc5020493959701509b2fb3bb
BLAKE2b-256 checksum
How to use checksums
081261a26232378fc9fa1183d4be869947e867340d0c58c71ff2941c760ac5aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 18, 2026.

Transparency log

Release files / misu-2.1.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL misu-2.1.0-cp39-abi3-macosx_11_0_arm64.whl
Size 315.9 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
6237db4b353a1f6afff8491d670f176e8c2ca9d4f5260e7b3bb4e0da12b765cb
BLAKE2b-256 checksum
How to use checksums
f6e85889c88333af8947ff905ace5b4a6f52cf3dbee7c323ba50784b7edea30e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 18, 2026.

Transparency log

Release files / misu-2.1.0-cp39-abi3-macosx_10_12_x86_64.whl

Download URL misu-2.1.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 333.1 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
c39d2af8b6b6d43a9c46bc015c760ec4e7dbe86a8dafa39d198d010287e33ec4
BLAKE2b-256 checksum
How to use checksums
b3e6713c5064b6f6cc3c2352f7885ae38e14bbaf5c9ffce83b6e96aaa82e7fe3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 18, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

2.1.0 This release

11 release files

2.0.1

6 release files

1.0.6

3 release files

1.0.5

4 release files

1.0.4

4 release files

1.0.3

7 release files

1.0.2

5 release files

0.1.0

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page