Using Pint in your projects#
Preprocessing input strings#
When an application accepts unit spellings that Pint does not define, pass
callables to the UnitRegistry preprocessors argument. The callables are
applied in order to each input string before parsing. For example, a registry can
support a known sq_cm spelling without changing its unit definitions:
>>> ureg = UnitRegistry(
... preprocessors=[lambda value: value.replace("sq_cm", "cm ** 2")]
... )
>>> ureg("3 sq_cm")
Quantity(3, "centimeter ** 2")
Keeping up to date with Pint development#
While we work hard to avoid breaking code using Pint, sometimes it happens. To help you track how Pint is evolving it is recommended that you run a daily or weekly job against pint master branch.
For example, this is how xarray is doing it:
If a new version of Pint breaks your code, please open an issue to let us know.