Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

TUnits - Fast Python Units

Continuous Integration

Implements unit of measurement arithmetic, where a number is associated with a product of powers of base units and values with compatible units can be added.

The library is written in Cython for speed. The library provides the ability to statically check dimensionality type (see below) and a limited protobuffer serialization support for select units (see below). Contributions to extend support for more units are welcome.

A precompiled wheel can be installed using pip install typedunits [--pre].

Example

>> import tunits
>> from tunits.units import meter, km, N, MHz

>> print(3*MHz)
Frequency(3, 'MHz')

>> print(5*meter + km)
Length(1005.0, 'm')

>> print(N/meter)
N/m

>> print((N/meter).in_base_units())
kg/s^2

>> print(2*km / tunits.Value(3, 's'))
0.666666666667 km/s

Static Type Check

TypedUnits provides the ability to statically check the dimensionality of variables and parameters. For example mypy would complain about incompatible types for the following code.

from tunits import Frequency, LengthArray
from tunits.units import meter, km, MHz

def frequency_fn(f: Frequency) -> Frequency:
    return 3*f

x = 2 * meter
x_arr = LengthArray([1, 2], km)
y = 3 * km
f = 7 * MHz

# okay
print(frequency_fn(f))
print(x + y)
print(x_arr - y)

# not okay
print(frequency_fn(x))
print(f + x)
print(x - f)
frequency_fn(x_arr)
$ mypy my_code.py
my_code.py:18: error: Argument 1 to "frequency_fn" has incompatible type "Length"; expected "Frequency"  [arg-type]
my_code.py:19: error: No overload variant of "__add__" of "Value" matches argument type "Length"  [operator]
my_code.py:19: note: Possible overload variants:
my_code.py:19: note:     def __add__(self, int | float | complex | number[Any], /) -> Frequency
my_code.py:19: note:     def __add__(self, ValueArray | list[Any] | tuple[Any] | ndarray[Any, dtype[Any]], /) -> ValueArray
my_code.py:19: note:     def __add__(self, Frequency, /) -> Frequency
my_code.py:20: error: No overload variant of "__sub__" of "Value" matches argument type "Frequency"  [operator]
my_code.py:20: note: Possible overload variants:
my_code.py:20: note:     def __sub__(self, int | float | complex | number[Any], /) -> Length
my_code.py:20: note:     def __sub__(self, list[Any] | tuple[Any] | ndarray[Any, dtype[Any]], /) -> ValueArray
my_code.py:20: note:     def __sub__(self, Length, /) -> Length
my_code.py:21: error: Argument 1 to "frequency_fn" has incompatible type "LengthArray"; expected "Frequency"  [arg-type]
Found 4 errors in 1 file (checked 1 source file)

Serialization support

TypedUnits provides protobuffer serialization support for selected units. Contributions are welcome to increase serialization coverage.

>> from tunits import Frequency
>> from tunits.units import MHz
>>
>> v = 3*MHz
>> msg = v.to_proto()
>> print(msg)
units {
  unit: HERTZ
  scale: MEGA
}
real_value: 3

>> Frequency.from_proto(msg)
Frequency(3.0, 'MHz')

Installation

  1. To install a precompiled wheel (add --pre for prelease version)

    pip install typedunits # [--pre] 
    
  2. To locally build the latest version from the main branch

    pip install git+https://github.com/quantumlib/TypedUnits
    
  3. For a local editable copy

    git clone https://github.com/quantumlib/TypedUnits
    cd TypedUnits
    pip install -e .
    

Development and Testing

  1. Clone the repository.

    git clone https://github.com/quantumlib/TypedUnits
    
    cd TypedUnits
    

    All future steps assume you are in the repository's directory.

  2. Install dev environment dependencies.

    pip install -r dev_tools/dev.env.txt
    
  3. Install TUnits

    pip install -e .
    
  4. Test.

    pytest
    

Formatting

dev_tools/format.sh  # to format
dev_tools/format.sh --check  # to verify format

Note: This is not an officially supported Google product

Metadata

Release files for typedunits 0.0.1.dev20250728235222

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

Built distributions (wheels)

Table of built distributions (wheels) for typedunits 0.0.1.dev20250728235222
File
typedunits-0.0.1.dev20250728235222-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
typedunits-0.0.1.dev20250728235222-cp313-cp313-win32.whl CPython 3.13 CPython 3.13 Windows x86-32 Details
typedunits-0.0.1.dev20250728235222-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details
typedunits-0.0.1.dev20250728235222-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
typedunits-0.0.1.dev20250728235222-cp313-cp313-macosx_10_13_x86_64.whl CPython 3.13 CPython 3.13 macOS 10.13+ x86-64 Details
typedunits-0.0.1.dev20250728235222-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
typedunits-0.0.1.dev20250728235222-cp312-cp312-win32.whl CPython 3.12 CPython 3.12 Windows x86-32 Details
typedunits-0.0.1.dev20250728235222-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
typedunits-0.0.1.dev20250728235222-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
typedunits-0.0.1.dev20250728235222-cp312-cp312-macosx_10_13_x86_64.whl CPython 3.12 CPython 3.12 macOS 10.13+ x86-64 Details
typedunits-0.0.1.dev20250728235222-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
typedunits-0.0.1.dev20250728235222-cp311-cp311-win32.whl CPython 3.11 CPython 3.11 Windows x86-32 Details
typedunits-0.0.1.dev20250728235222-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
typedunits-0.0.1.dev20250728235222-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details
typedunits-0.0.1.dev20250728235222-cp311-cp311-macosx_10_9_x86_64.whl CPython 3.11 CPython 3.11 macOS 10.9+ x86-64 Details
typedunits-0.0.1.dev20250728235222-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
typedunits-0.0.1.dev20250728235222-cp310-cp310-win32.whl CPython 3.10 CPython 3.10 Windows x86-32 Details
typedunits-0.0.1.dev20250728235222-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
typedunits-0.0.1.dev20250728235222-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details
typedunits-0.0.1.dev20250728235222-cp310-cp310-macosx_10_9_x86_64.whl CPython 3.10 CPython 3.10 macOS 10.9+ x86-64 Details

Total release size: 22.7 MB

Release files / typedunits-0.0.1.dev20250728235222-cp313-cp313-win_amd64.whl

Download URL typedunits-0.0.1.dev20250728235222-cp313-cp313-win_amd64.whl
Size 738.2 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
7adeef03e9f7593fe5d7d6b4341a1e98c845c03e4b16e7fcbdae4ff0b9e7b328
BLAKE2b-256 checksum
How to use checksums
942d69dd4b2f9f86a61dd2e2602d4df39bf3e29887803675e0508763b7c289c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / typedunits-0.0.1.dev20250728235222-cp313-cp313-win32.whl

Download URL typedunits-0.0.1.dev20250728235222-cp313-cp313-win32.whl
Size 683.9 kB
Tags CPython 3.13 Windows x86-32
SHA-256 checksum
How to use checksums
1b0d0c6a31547971897a20865bc90ac0d89dd13cf784139d98664688b61ac7eb
BLAKE2b-256 checksum
How to use checksums
8cc2bd211e95a7aaa1daf5b6a53a47e3e494105b6bd0522da90e86a634d2bb18
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / typedunits-0.0.1.dev20250728235222-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL typedunits-0.0.1.dev20250728235222-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.6 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
11a8953582d278c734bc031e5b065a471930c8faec12b548fbd7046bd41f31ab
BLAKE2b-256 checksum
How to use checksums
eebb172fa76a5812093526410ebe6d0abb696a63255bd13934c4102b9f5f3262
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / typedunits-0.0.1.dev20250728235222-cp313-cp313-macosx_11_0_arm64.whl

Download URL typedunits-0.0.1.dev20250728235222-cp313-cp313-macosx_11_0_arm64.whl
Size 755.6 kB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
8595b6e69c3e7dd14eac91c9de015050ef78d2c1742cf316cac4c361c1d7dae6
BLAKE2b-256 checksum
How to use checksums
5328095e9ce87b6dcb3755bed1845bbeb8749ea5ad24ebd57a83bfa35a51c804
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / typedunits-0.0.1.dev20250728235222-cp313-cp313-macosx_10_13_x86_64.whl

Download URL typedunits-0.0.1.dev20250728235222-cp313-cp313-macosx_10_13_x86_64.whl
Size 798.4 kB
Tags CPython 3.13 macOS 10.13+ x86-64
SHA-256 checksum
How to use checksums
f85d3b0a84b61aa8b0cd3e58028186347388aaa4ab233a0c13c1faa994fa8286
BLAKE2b-256 checksum
How to use checksums
faf5b2aa28230aa942a111d48da3c7dbfba6fe65f99a2145da08351c78bcd7c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / typedunits-0.0.1.dev20250728235222-cp312-cp312-win_amd64.whl

Download URL typedunits-0.0.1.dev20250728235222-cp312-cp312-win_amd64.whl
Size 734.7 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
60c4775aa7aa9f3408f5e74b4b45ac10b4db21136002bf544b201b1bf62d8644
BLAKE2b-256 checksum
How to use checksums
c223d91e51e982239fc273932ba25c1f76444e03a7c4f2ba3fcc2d66e79a92cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / typedunits-0.0.1.dev20250728235222-cp312-cp312-win32.whl

Download URL typedunits-0.0.1.dev20250728235222-cp312-cp312-win32.whl
Size 684.8 kB
Tags CPython 3.12 Windows x86-32
SHA-256 checksum
How to use checksums
864b24ce2138b3eb6e416cc2ab7dc7652edfffcb9e03c6e4d63bed7cb122ad20
BLAKE2b-256 checksum
How to use checksums
d0986f8f915f21684a9e794df91f6d504d73b2f2d916a9497c9c8995d6e7422b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / typedunits-0.0.1.dev20250728235222-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL typedunits-0.0.1.dev20250728235222-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.6 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
731260b4583a1a5b42c54d759febc966b73f58d7763c35c8e3437de56b545549
BLAKE2b-256 checksum
How to use checksums
574781b9c6efec017efaea7384f1a361a00dcbaf1310c1d304ca413d0fd05071
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / typedunits-0.0.1.dev20250728235222-cp312-cp312-macosx_11_0_arm64.whl

Download URL typedunits-0.0.1.dev20250728235222-cp312-cp312-macosx_11_0_arm64.whl
Size 755.6 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
57dd53d0d5e06615e4bcd9514a6909f7773b7d6eeda2374542da47665323d014
BLAKE2b-256 checksum
How to use checksums
d2e9f3775cdc27512fe0203734c18a200d308c2ded3d900944430a868eeff410
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / typedunits-0.0.1.dev20250728235222-cp312-cp312-macosx_10_13_x86_64.whl

Download URL typedunits-0.0.1.dev20250728235222-cp312-cp312-macosx_10_13_x86_64.whl
Size 804.2 kB
Tags CPython 3.12 macOS 10.13+ x86-64
SHA-256 checksum
How to use checksums
784aad71e623fde0f2483a67c18b0b297db67a4f830c35874069faebdf138834
BLAKE2b-256 checksum
How to use checksums
d2f2dd569be48975341b1115b7bb35f4351ad330fb3bd4c3a99895fb2663816b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / typedunits-0.0.1.dev20250728235222-cp311-cp311-win_amd64.whl

Download URL typedunits-0.0.1.dev20250728235222-cp311-cp311-win_amd64.whl
Size 814.9 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
0fee1d6510358486faf464a06c50ed035347dd00c93fbf6e7ecf073d3363ae63
BLAKE2b-256 checksum
How to use checksums
84bb1f7b4413b5934a656b56273de3278d9d82f396ba314e4df3a536c3eb6491
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / typedunits-0.0.1.dev20250728235222-cp311-cp311-win32.whl

Download URL typedunits-0.0.1.dev20250728235222-cp311-cp311-win32.whl
Size 749.2 kB
Tags CPython 3.11 Windows x86-32
SHA-256 checksum
How to use checksums
068fdb1dae2ac9fbb3144a94901285cad66427b34d51e10836a12b406a321329
BLAKE2b-256 checksum
How to use checksums
23651ce137a766adf820449774bef815c750173e735939c0e4b4353f04400ded
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / typedunits-0.0.1.dev20250728235222-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL typedunits-0.0.1.dev20250728235222-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.7 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
34606e4e4e8c8a1c83f62a234caf5b11be014f2736406ae2423cf65000ec6d67
BLAKE2b-256 checksum
How to use checksums
9e147905742d12a64e0b5cee828ae16dcd21b8348d2daada773401a7b9e5e083
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / typedunits-0.0.1.dev20250728235222-cp311-cp311-macosx_11_0_arm64.whl

Download URL typedunits-0.0.1.dev20250728235222-cp311-cp311-macosx_11_0_arm64.whl
Size 783.0 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
c10f056d95c57c1925f095920fe5b302925c6f14da3e67df740a0e44d8635a8d
BLAKE2b-256 checksum
How to use checksums
bc6b80acce6da8bb98babc4e1c2331a36bc9b16cdc45991e0ad6751300e4e949
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / typedunits-0.0.1.dev20250728235222-cp311-cp311-macosx_10_9_x86_64.whl

Download URL typedunits-0.0.1.dev20250728235222-cp311-cp311-macosx_10_9_x86_64.whl
Size 849.7 kB
Tags CPython 3.11 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
5da69de5ccc6d292062f2cf2f82e2d71d86e34a34a2ea071598149a5e8a2f027
BLAKE2b-256 checksum
How to use checksums
058a49e42402ca9d63881a6ada163e7f0232d78c96812926e4e6e69ae821c85b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / typedunits-0.0.1.dev20250728235222-cp310-cp310-win_amd64.whl

Download URL typedunits-0.0.1.dev20250728235222-cp310-cp310-win_amd64.whl
Size 814.8 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
4387c41d181711e063cc9f1694c88955b36fab5da1a79cc6f4c37556a319134b
BLAKE2b-256 checksum
How to use checksums
dd15ded2bd1384cfdda5171a36b2ff6f0dd2f49ed34645f3d82269e7c13e1660
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / typedunits-0.0.1.dev20250728235222-cp310-cp310-win32.whl

Download URL typedunits-0.0.1.dev20250728235222-cp310-cp310-win32.whl
Size 719.8 kB
Tags CPython 3.10 Windows x86-32
SHA-256 checksum
How to use checksums
f5fe2b3ffa44c5e1652631e97c5dd5b3811e9b4fc0d6553a6617ae12e5a58612
BLAKE2b-256 checksum
How to use checksums
d029d310d2f7edbfab7e4ae5c286a6153ae64b57595e2d8bfa7acca0421a3af5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / typedunits-0.0.1.dev20250728235222-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL typedunits-0.0.1.dev20250728235222-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.5 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
1834f318fd51af6b381cdb7fbb865853045be1c4608aabc8758f004bec81e641
BLAKE2b-256 checksum
How to use checksums
5232fa6b86d10e847b437ac52622b42b4a9abe9805367c3ef53aae3a301b4bea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / typedunits-0.0.1.dev20250728235222-cp310-cp310-macosx_11_0_arm64.whl

Download URL typedunits-0.0.1.dev20250728235222-cp310-cp310-macosx_11_0_arm64.whl
Size 745.9 kB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
4abd53ed1231554d7638eb030878812c16bb9dc5bca27bf6284ea96308d5f78b
BLAKE2b-256 checksum
How to use checksums
6463dfcef120aba9f7f2ada857ec86e50107551482494b3748ebef10660e5325
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / typedunits-0.0.1.dev20250728235222-cp310-cp310-macosx_10_9_x86_64.whl

Download URL typedunits-0.0.1.dev20250728235222-cp310-cp310-macosx_10_9_x86_64.whl
Size 811.7 kB
Tags CPython 3.10 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
1c2ebe26a67500a4d6b35be01b70d6be9cbfccb65dad70a374eedc3e8ae55a41
BLAKE2b-256 checksum
How to use checksums
1690fbf7827ea249c6f21d9f36c6c725a29af437ca0cc683923febe84ab008d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release history Release notifications | RSS feed

0.0.2

30 release files

0.0.1

24 release files

This release
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