Registry / data / measurement

measurement

JSON →
library3.2.2pypypi✓ verified 22d ago

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.

pip install measurement
INSTALL
IMPORT
SIG · MEASUREMENT
M
measurement
datapythonv3.2.2
Install
6.3s avg
Import
1073ms
Disk
89MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.2.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 1.104s · 78.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 6.3s · import 1.042s · 79MB
89MB installed
● package 89MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Distance
from measurement.measures import Distance
Weight
from measurement.measures import Weight
Temperature
from measurement.measures import Temperature
MeasureBase
from measurement.base import MeasureBase
Used for creating custom measurement types.

Demonstrates creating measurement objects, performing basic arithmetic, and converting between different units.

from measurement.measures import Weight, Distance # Create a Weight object weight_1 = Weight(lb=125) weight_2 = Weight(kg=40) # Perform arithmetic operations added_together = weight_1 + weight_2 print(f"Weight 1: {weight_1}") print(f"Weight 2: {weight_2}") print(f"Sum in pounds: {added_together.lb:.2f} lb") print(f"Sum in kilograms: {added_together.kg:.2f} kg") # Create a Distance object and convert units distance_m = Distance(m=1000) distance_km = distance_m.km distance_miles = distance_m.miles print(f"1000 meters is {distance_km:.2f} km") print(f"1000 meters is {distance_miles:.2f} miles")
Debug
Known issues
gotchaMeasurements 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.
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.
affects: All versions
gotchaWhen 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.
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.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'measurement'
The 'measurement' library has not been installed in your Python environment.
fix
Install the library using pip: `pip install python-measurement`
AttributeError: 'Distance' object has no attribute 'lightyears'
You are attempting to access a unit for conversion (e.g., 'lightyears') that is either not supported by the 'Distance' measure or is misspelled.
fix
Consult the library's documentation to verify supported units for the specific measure (e.g., Distance, Weight, Temperature) or check for typos. If the unit exists, ensure it's accessible as an attribute.
TypeError: unsupported operand type(s) for +: 'Distance' and 'Weight'
You are trying to perform an arithmetic operation (like addition or subtraction) between two measurement objects that represent fundamentally incompatible physical quantities (e.g., adding a distance to a weight).
fix
Ensure that arithmetic operations are only performed between measurement objects of compatible dimensions. If you need to combine values of different types, consider their physical relevance and handle them separately or convert them to a common comparable base if meaningful (e.g., energy from mass-energy equivalence).
TypeError: __init__ missing 1 required keyword-only argument: 'value'
When creating a measurement object (e.g., `Distance`, `Weight`), the library expects the value and unit to be passed as a keyword argument (e.g., `Distance(km=10)`), not as positional arguments.
fix
Initialize measurement objects using a keyword argument where the keyword is the unit and its value is the quantity, for example: `from measurement.measures import Distance; d = Distance(km=10)`
ValueError: Invalid unit 'foo'
You have provided a unit string ('foo' in this example) that the library does not recognize when attempting to create a measurement or use a utility function like `guess()`.
fix
Use a valid unit string recognized by the 'measurement' library. Check the library's documentation for the list of supported units and their correct abbreviations or full names.
Upgrade
Version history
3.2.2latest on PyPI · released Jan 10, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
1 hits · last 30 days
Resources
measurement — pip install measurement · libregistry