Pint: Physical Quantities

0.25.3 · active · verified Thu Apr 09

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.

Warnings

Install

Imports

Quickstart

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.

from pint import UnitRegistry

# Initialize the UnitRegistry, which stores unit definitions and handles conversions
ureg = UnitRegistry()

# Define quantities using numerical values and units from the registry
distance = 24.0 * ureg.meter
time = 8.0 * ureg.second

# Perform calculations; Pint automatically handles unit propagation
speed = distance / time
print(f"Calculated Speed: {speed}")

# Convert quantities to different compatible units
speed_kmh = speed.to(ureg.kilometer / ureg.hour)
print(f"Speed in kilometers per hour: {speed_kmh}")

# Quantities can also be created by parsing strings
force = ureg.Quantity("100 N")
print(f"Force from string: {force}")

view raw JSON →