{"id":2190,"library":"pint","title":"Pint: Physical Quantities","description":"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.","status":"active","version":"0.25.3","language":"en","source_language":"en","source_url":"https://github.com/hgrecco/pint","tags":["units","quantities","physics","measurement","science","dimensional-analysis"],"install":[{"cmd":"pip install pint","lang":"bash","label":"PyPI"},{"cmd":"conda install -c conda-forge pint","lang":"bash","label":"Conda"}],"dependencies":[{"reason":"Optional: enhanced support for array operations and ufuncs with quantities.","package":"numpy","optional":true},{"reason":"Optional: integration for unit-aware DataFrames via the `pint-pandas` package.","package":"pandas","optional":true},{"reason":"Optional: transparently handles calculations with quantities that have uncertainties.","package":"uncertainties","optional":true},{"reason":"Optional: enables unit name translation.","package":"babel","optional":true}],"imports":[{"symbol":"UnitRegistry","correct":"from pint import UnitRegistry"}],"quickstart":{"code":"from pint import UnitRegistry\n\n# Initialize the UnitRegistry, which stores unit definitions and handles conversions\nureg = UnitRegistry()\n\n# Define quantities using numerical values and units from the registry\ndistance = 24.0 * ureg.meter\ntime = 8.0 * ureg.second\n\n# Perform calculations; Pint automatically handles unit propagation\nspeed = distance / time\nprint(f\"Calculated Speed: {speed}\")\n\n# Convert quantities to different compatible units\nspeed_kmh = speed.to(ureg.kilometer / ureg.hour)\nprint(f\"Speed in kilometers per hour: {speed_kmh}\")\n\n# Quantities can also be created by parsing strings\nforce = ureg.Quantity(\"100 N\")\nprint(f\"Force from string: {force}\")","lang":"python","description":"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."},"warnings":[{"fix":"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.","message":"Minimum Python version support has increased over time. For Pint v0.25.3, Python 3.11+ is required. Older versions like 0.18 required Python 3.8+ and Numpy 1.19+; version 0.10 required Python 3.6+. Check the changelog for specific version compatibility.","severity":"breaking","affected_versions":">=0.10"},{"fix":"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.","message":"Creating multiple instances of `UnitRegistry` across different modules in your project can lead to `ValueError: Cannot operate with Quantity and Quantity of different registries.` when performing operations between them.","severity":"gotcha","affected_versions":"All"},{"fix":"Explicitly compare the quantity's magnitude to a reference value (e.g., `if temp.magnitude > 0:`) rather than relying on implicit boolean conversion.","message":"Attempting to cast a `Quantity` with offset units (e.g., temperature in Celsius) to a boolean value will raise a `ValueError` since version 0.10. This prevents ambiguous boolean evaluations.","severity":"breaking","affected_versions":">=0.10"},{"fix":"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.","message":"The `auto_reduce_dimensions` and `autoconvert_to_preferred` parameters of `UnitRegistry` are `False` by default for performance reasons. This means units might not automatically simplify or convert to preferred forms unless explicitly enabled.","severity":"gotcha","affected_versions":"All"},{"fix":"Ensure you are installing `pint` (lowercase) for physical quantities and refer to its specific documentation and examples to avoid conflicts or incorrect usage.","message":"There is a separate Python library for pulsar timing called `PINT` (all uppercase). Be careful not to confuse `pint` (lowercase, for physical quantities) with `PINT` when installing or searching, as they are distinct projects.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}