Pint is a Python package designed for defining, operating, and manipulating physical quantities. It allows for arithmetic operations between numerical values and units of measurement, as well as conversions between different units. The library includes a comprehensive list of physical units, prefixes, and constants, and its modular design enables users to extend or rewrite unit definitions. It integrates well with numerical libraries like NumPy and Pandas (via `pint-pandas`) and is actively maintained, with the latest stable version 0.25.3 released on March 19, 2026.
pip install pintVerified import paths — ran on the pinned version, not inferred.
Initialize a `UnitRegistry` to define and manage units. Use the registry to create `Quantity` objects, perform arithmetic operations, and convert units. Pint automatically handles dimensional analysis during calculations.
Ensure your Python environment meets the minimum version requirement for your chosen Pint release (e.g., Python >=3.11 for 0.25.3) and update NumPy if necessary.
Instantiate the `UnitRegistry` in a single, central location (e.g., your package's `__init__.py` file) and import that shared instance across your project. Optionally, use `set_application_registry(ureg)` for advanced scenarios.
Explicitly compare the quantity's magnitude to a reference value (e.g., `if temp.magnitude > 0:`) rather than relying on implicit boolean conversion.
If automatic simplification or conversion is desired, initialize your `UnitRegistry` with `ureg = UnitRegistry(auto_reduce_dimensions=True, autoconvert_to_preferred=True)` or call `.to_reduced_units()` / `.to_preferred()` explicitly.
Ensure you are installing `pint` (lowercase) for physical quantities and refer to its specific documentation and examples to avoid conflicts or incorrect usage.
Install the pint library using pip: `pip install pint` or `pip3 install pint`.
Ensure the unit name is spelled correctly, exists in Pint's default definitions, or define a custom unit if it's not standard. Example: `ureg.define('foobar = 10 meter')` or check for typos like `ureg.metre` instead of `ureg.meter`.Review the units of the quantities involved in the operation. Ensure that units being converted or operated upon belong to the same base dimension, or that the operation itself results in a dimensionally consistent quantity. For example, to convert from meters to feet: `(10 * ureg.meter).to(ureg.foot)`.
Convert quantities to a common absolute temperature unit (like Kelvin) before performing the ambiguous operation, or explicitly convert one of the offset units to a delta unit if the intent is to represent a temperature difference. Alternatively, set `ureg.autoconvert_offset_to_baseunit = True` for relaxed behavior, but be aware of potential ambiguities.
Ensure all Quantity objects in your application are created from a single, globally accessible UnitRegistry instance. A common pattern is to initialize the registry once and import it where needed: `from pint import UnitRegistry; ureg = UnitRegistry()` in a central module, then `from . import ureg` elsewhere.