{"id":4627,"library":"measurement","title":"Unit-Aware Measurements","description":"The `measurement` library (also known as `python-measurement`) provides easy-to-use unit-aware measurement objects in Python. It allows for manipulation and conversion between various SI, US, and Imperial units for quantities like Distance, Weight, Volume, Temperature, Energy, Speed, and Time. The library is currently active, with its latest release (3.2.2) on January 10, 2023, and maintains a stable API.","status":"active","version":"3.2.2","language":"en","source_language":"en","source_url":"https://github.com/coddingtonbear/python-measurement","tags":["units","measurement","quantities","conversion","science","engineering"],"install":[{"cmd":"pip install measurement","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"Distance","correct":"from measurement.measures import Distance"},{"symbol":"Weight","correct":"from measurement.measures import Weight"},{"symbol":"Temperature","correct":"from measurement.measures import Temperature"},{"note":"Used for creating custom measurement types.","symbol":"MeasureBase","correct":"from measurement.base import MeasureBase"}],"quickstart":{"code":"from measurement.measures import Weight, Distance\n\n# Create a Weight object\nweight_1 = Weight(lb=125)\nweight_2 = Weight(kg=40)\n\n# Perform arithmetic operations\nadded_together = weight_1 + weight_2\nprint(f\"Weight 1: {weight_1}\")\nprint(f\"Weight 2: {weight_2}\")\nprint(f\"Sum in pounds: {added_together.lb:.2f} lb\")\nprint(f\"Sum in kilograms: {added_together.kg:.2f} kg\")\n\n# Create a Distance object and convert units\ndistance_m = Distance(m=1000)\ndistance_km = distance_m.km\ndistance_miles = distance_m.miles\n\nprint(f\"1000 meters is {distance_km:.2f} km\")\nprint(f\"1000 meters is {distance_miles:.2f} miles\")\n","lang":"python","description":"Demonstrates creating measurement objects, performing basic arithmetic, and converting between different units."},"warnings":[{"fix":"Be aware of the inherent limitations of floating-point arithmetic. For high-precision scientific or engineering applications, consider libraries designed for arbitrary-precision arithmetic or interval arithmetic if uncertainty propagation is critical.","message":"Measurements are stored internally as floating-point numbers of a (generally) reasonable SI unit. This can lead to slight inaccuracies due to the nature of floating-point representation. Do not use this library for applications requiring extreme precision, such as navigation algorithms for critical systems.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Thoroughly test custom `MeasureBase` implementations, especially their interaction with `STANDARD_UNIT` and the `UNITS` dictionary. If preserving the original input unit is crucial, store it alongside the measurement object or use `measurement.utils.guess` to infer the unit upon retrieval where possible.","message":"When defining custom `MeasureBase` subclasses, ensure `STANDARD_UNIT` and `UNITS` are correctly configured. Incorrect definitions can lead to unexpected unit conversions or a loss of the original unit information if the measurement is stored and retrieved without explicit handling for the custom units.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}