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.dev20250912005737

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.dev20250912005737
File
typedunits-0.0.1.dev20250912005737-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
typedunits-0.0.1.dev20250912005737-cp313-cp313-win32.whl CPython 3.13 CPython 3.13 Windows x86-32 Details
typedunits-0.0.1.dev20250912005737-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.dev20250912005737-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
typedunits-0.0.1.dev20250912005737-cp313-cp313-macosx_10_13_x86_64.whl CPython 3.13 CPython 3.13 macOS 10.13+ x86-64 Details
typedunits-0.0.1.dev20250912005737-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
typedunits-0.0.1.dev20250912005737-cp312-cp312-win32.whl CPython 3.12 CPython 3.12 Windows x86-32 Details
typedunits-0.0.1.dev20250912005737-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.dev20250912005737-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
typedunits-0.0.1.dev20250912005737-cp312-cp312-macosx_10_13_x86_64.whl CPython 3.12 CPython 3.12 macOS 10.13+ x86-64 Details
typedunits-0.0.1.dev20250912005737-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
typedunits-0.0.1.dev20250912005737-cp311-cp311-win32.whl CPython 3.11 CPython 3.11 Windows x86-32 Details
typedunits-0.0.1.dev20250912005737-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.dev20250912005737-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details
typedunits-0.0.1.dev20250912005737-cp311-cp311-macosx_10_9_x86_64.whl CPython 3.11 CPython 3.11 macOS 10.9+ x86-64 Details
typedunits-0.0.1.dev20250912005737-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
typedunits-0.0.1.dev20250912005737-cp310-cp310-win32.whl CPython 3.10 CPython 3.10 Windows x86-32 Details
typedunits-0.0.1.dev20250912005737-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.dev20250912005737-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details
typedunits-0.0.1.dev20250912005737-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.dev20250912005737-cp313-cp313-win_amd64.whl

Download URL typedunits-0.0.1.dev20250912005737-cp313-cp313-win_amd64.whl
Size 738.0 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
c8e547250a10350db668483d3ff8a537286cb771026d7152ce7ca367b0ae9aca
BLAKE2b-256 checksum
How to use checksums
f625264286078448b2a50ffc4cd375ac9009b540fccf0b3f4c0fca570e13dd66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

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

Download URL typedunits-0.0.1.dev20250912005737-cp313-cp313-win32.whl
Size 683.6 kB
Tags CPython 3.13 Windows x86-32
SHA-256 checksum
How to use checksums
b49de34c206ca174fc5e227e52e69ea14b88fad0709c6f9105a92a5df0bf744a
BLAKE2b-256 checksum
How to use checksums
ebdebbbee93c7e338892fa57ea6a2e732bf0b58d909f92914b8faaa4b47bb5f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

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

Download URL typedunits-0.0.1.dev20250912005737-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
95a074cffbb608c87dd1786ae1af4d7a8c88d1b93291f3a8a998389352f53a18
BLAKE2b-256 checksum
How to use checksums
c5472a0c046f19a351953a26350aa0402b304703d8dd7f8089ab51f51827a88d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

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

Download URL typedunits-0.0.1.dev20250912005737-cp313-cp313-macosx_11_0_arm64.whl
Size 755.5 kB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
cc69cc4a2d8171c7a715778b8b0b12016c8d66695a7ee4d0dd8eb03e6dc96587
BLAKE2b-256 checksum
How to use checksums
e9d080108f57395d8279a9f7489e11387b1d11ef16b2850eb81be724be1a9b00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

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

Download URL typedunits-0.0.1.dev20250912005737-cp313-cp313-macosx_10_13_x86_64.whl
Size 798.2 kB
Tags CPython 3.13 macOS 10.13+ x86-64
SHA-256 checksum
How to use checksums
15a095782947e6eece5e2b6cbf562aceb8ca29fa3cb55224b48c8fb8890329d0
BLAKE2b-256 checksum
How to use checksums
de01d52b3d524968aca45dbe957bb28858a0ddf86b29f42b64019b8fd0759c73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

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

Download URL typedunits-0.0.1.dev20250912005737-cp312-cp312-win_amd64.whl
Size 734.4 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
7854d1efe2fe053e0af399ed7395f1acdf27d8d189aadb7bbcafe887faef2264
BLAKE2b-256 checksum
How to use checksums
221b4f7043730aa889e0b3c256b50a7c6480c9c68777f5e0d5eb04f841eeb975
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

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

Download URL typedunits-0.0.1.dev20250912005737-cp312-cp312-win32.whl
Size 684.6 kB
Tags CPython 3.12 Windows x86-32
SHA-256 checksum
How to use checksums
6388d6140ffd254fff1a9c5a52ccc2f9bba2e88e8367fe8f5aed414fdfa935d1
BLAKE2b-256 checksum
How to use checksums
128cb32dc650865733a818e66df4efcc5a8f460a4aece51a7d4579a3873d51ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

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

Download URL typedunits-0.0.1.dev20250912005737-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
a827701d23b0c65f9a473f30203abca2a35a115b72f6afee71208d8c4e016c3c
BLAKE2b-256 checksum
How to use checksums
e8fea6fd2abce56440b1aa4715c888cc74ef1f12e092cd419fd76f2109b09974
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

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

Download URL typedunits-0.0.1.dev20250912005737-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
d49c82651b02f9e2dafe2f060f8bbbef289f68e5d731bbad1b52980226cfac0e
BLAKE2b-256 checksum
How to use checksums
31b72c1c1b50631a9984b2f3f1abf52f675cea5f07ff30471eb5589db9047288
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

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

Download URL typedunits-0.0.1.dev20250912005737-cp312-cp312-macosx_10_13_x86_64.whl
Size 804.0 kB
Tags CPython 3.12 macOS 10.13+ x86-64
SHA-256 checksum
How to use checksums
f33930ebaf7a0c792bc3113b12f36faab9eb00f6115ae2c32db02494038cfb1a
BLAKE2b-256 checksum
How to use checksums
981038b4d440b088d7f54d1399aefbd7f77cecd2559ee2502f0c1a08d0badc48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

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

Download URL typedunits-0.0.1.dev20250912005737-cp311-cp311-win_amd64.whl
Size 814.7 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
e34ef38f22671061184f792036993f44f485f1e4b9ee873ad4c303ade9b63a83
BLAKE2b-256 checksum
How to use checksums
64226ee43e5dbc45dc8997d17121e86f541bf59216cbf5b37d682479b10fcdf9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

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

Download URL typedunits-0.0.1.dev20250912005737-cp311-cp311-win32.whl
Size 749.0 kB
Tags CPython 3.11 Windows x86-32
SHA-256 checksum
How to use checksums
155bdb1b049735a88f640e765ad54ee1389a51274f748c14e1224f5a9e61483f
BLAKE2b-256 checksum
How to use checksums
8f9c125c486982cfe8e2cfd81bce88bcc1a75307780798a695329a376a9b9c12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

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

Download URL typedunits-0.0.1.dev20250912005737-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
15f556552e6dd00697d2e78e76de98977172ce3844b524d3df53ccfd6c20c210
BLAKE2b-256 checksum
How to use checksums
0e05eb0f69ed6ca34ff412b0a0999101e29628472ce8fdca3a86ce9b7ef104a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

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

Download URL typedunits-0.0.1.dev20250912005737-cp311-cp311-macosx_11_0_arm64.whl
Size 782.8 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b7158460f8b6279850d809ea68e73c4672d809230abc6ce9ae6f977144b4111c
BLAKE2b-256 checksum
How to use checksums
9e0c22dbcaa429120b28aae1b95d6fb2fdd1ef7215c6fe4deafcb56b923d0590
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

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

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

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

Download URL typedunits-0.0.1.dev20250912005737-cp310-cp310-win_amd64.whl
Size 814.7 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
a640a54dc6184fcced8a12cb65b0dc7c5bf123665e733130afa5cebe401abd26
BLAKE2b-256 checksum
How to use checksums
a505d62193538464862c6953a120d927f198a0e90e0d5c3221114ffc85b7e866
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

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

Download URL typedunits-0.0.1.dev20250912005737-cp310-cp310-win32.whl
Size 719.6 kB
Tags CPython 3.10 Windows x86-32
SHA-256 checksum
How to use checksums
1fc8509b4ee38fc0f50c3bdc6198ea643eb146caaae68b15ee9b290ca670a766
BLAKE2b-256 checksum
How to use checksums
4d4a9cb9d35803e78063bac0fcfa96d4d7f2d071e26ab5f9b91657d058b2ca85
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

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

Download URL typedunits-0.0.1.dev20250912005737-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
899c38a1fe345ecbf42cd211e652eb47042f0f6a4fd30eee62e3a543b251377c
BLAKE2b-256 checksum
How to use checksums
072bb18bd1339f14a4209225940ef31a36f065952d5fa24752dd8099011cf144
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

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

Download URL typedunits-0.0.1.dev20250912005737-cp310-cp310-macosx_11_0_arm64.whl
Size 745.6 kB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
d12e4a528308e75ebcc072066a492e69891933b953718b730542ca9c0594b5d8
BLAKE2b-256 checksum
How to use checksums
8a5d7fe4ccdd48be82d3a68eede111d2756931c870d996c507ffd241981a821d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

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

Download URL typedunits-0.0.1.dev20250912005737-cp310-cp310-macosx_10_9_x86_64.whl
Size 811.3 kB
Tags CPython 3.10 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
90815f5d91301d2edab53d82d23c2f9c3e8f96e6a7081241f490da30be6b414c
BLAKE2b-256 checksum
How to use checksums
d604b6aff9c0cf90664327dac75730d366b2688230214512bd27a59ee2e1bd4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.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