Skip to main content

unitful

PyPI version Python CI License

Physical units as first-class Python values

Attach a unit to any number, arithmetic propagates units automatically Dimension mismatches raise DimensionError at runtime instead of producing silently wrong results

Getting Started

pip install unitful
from unitful import m, s, kg, km, h

distance = 100 * m
time     = 9.58 * s
speed    = distance / time        # Quantity(10.44, 'm/s')

speed.to(km / h)                  # Quantity(37.58, 'km/h')
speed.to(kg)                      # DimensionError: [Length/Time] != [Mass]

Features

  • Dimension checking: all arithmetic validates physical dimensions and raises DimensionError with a clear message on mismatch
  • Unit conversion: .to(unit) converts between compatible units, including offset temperature scales (degC, degF, K)
  • NumPy integration: np.array([...]) * m returns a QuantityArray; ufuncs and reduction functions (np.mean, np.sum, etc.) preserve units
  • Decorators: @requires and @returns enforce dimensions on function arguments and return values
  • Custom units and dimensions: define_unit and new_dimension extend the registry at runtime
  • Serialization: to_json / from_json for plain-dict round-trips; pickle and copy work without extra setup
  • Formatting: f"{q:.2f~P}" (Unicode), f"{q:.2f~L}" (LaTeX), f"{q:.2f~H}" (HTML)

Requirements

Python 3.10 or later. NumPy is optional; install it with:

pip install "unitful[numpy]"

License

MIT

Release files for unitful 1.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 unitful 1.1.0
File Size Uploaded
unitful-1.1.0.tar.gz 25.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for unitful 1.1.0
File Interpreter ABI Platform
unitful-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 48.6 kB

Release files / unitful-1.1.0.tar.gz

Download URL unitful-1.1.0.tar.gz
Size 25.5 kB
Tags Source
SHA-256 checksum
How to use checksums
6bad38e6e6dc00563332790dacfde731a94eb2de7e0d0636edd17357ea79d807
BLAKE2b-256 checksum
How to use checksums
f26ee8619a2131a8ca30f85771b516c56b391a7ee2ce4bdc736606693d26d242
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 21, 2026.

Transparency log

Release files / unitful-1.1.0-py3-none-any.whl

Download URL unitful-1.1.0-py3-none-any.whl
Size 23.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
13fa4933e34ecfbc11bd72db305cf964dec61d6fe374118bc451f09e49120fdd
BLAKE2b-256 checksum
How to use checksums
66b4080453c37db8723ea81f802496635f5d92621b39d15aac9b9605dfbb3949
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 21, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.0

2 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