unitful
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
DimensionErrorwith a clear message on mismatch - Unit conversion:
.to(unit)converts between compatible units, including offset temperature scales (degC,degF,K) - NumPy integration:
np.array([...]) * mreturns aQuantityArray; ufuncs and reduction functions (np.mean,np.sum, etc.) preserve units - Decorators:
@requiresand@returnsenforce dimensions on function arguments and return values - Custom units and dimensions:
define_unitandnew_dimensionextend the registry at runtime - Serialization:
to_json/from_jsonfor plain-dict round-trips; pickle andcopywork 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
Metadata
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| unitful-1.1.0.tar.gz | 25.5 kB | With provenance | Details for unitful-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| unitful-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for unitful-1.1.0-py3-none-any.whl |
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 logRelease 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 logSecurity for unitful 1.1.0
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for unitful-1.1.0.tar.gz
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 logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.