Utils API
The utils module provides utility functions for unit conversion and measurement handling.
Unit Conversion
- usda_fdc.utils.parse_unit_and_value(measurement_str)[source]
Parse a measurement string into a value and unit.
- usda_fdc.utils.convert_to_grams(amount, unit)[source]
Convert a measurement to grams.
- Parameters:
- Returns:
The equivalent amount in grams.
- Raises:
ValueError – If the unit cannot be converted to grams.
- Return type:
- usda_fdc.utils.convert_to_milliliters(amount, unit)[source]
Convert a measurement to milliliters.
- Parameters:
- Returns:
The equivalent amount in milliliters.
- Raises:
ValueError – If the unit cannot be converted to milliliters.
- Return type:
- usda_fdc.utils.convert_measurement(amount, from_unit, to_unit)[source]
Convert a measurement from one unit to another.
- Parameters:
- Returns:
The converted amount.
- Raises:
ValueError – If the conversion is not possible.
- Return type: