Open-source project
hgrecco/pint avatar
hgrecco/pint

Pint: physical quantities and unit conversion in Python

Operate and manipulate physical quantities in Python

2,830 stars577 forksPythonNOASSERTION

At a glance

What is it?
Pint attaches units to numbers in Python and keeps them through arithmetic. This review covers how the UnitRegistry works, how to install it, where it breaks, and who should pick it over plain floats.
Who is it for?
Adopt Pint when your code does arithmetic across units and you want the unit checked rather than the number silently wrong: scientific and engineering code, simulation inputs, data pipelines that mix SI and imperial. Skip it when your numbers are dimensionless, when the unit is fixed by convention, or when you cannot accept per-operation overhead on hot loops.
Can I use it commercially?
Check first. The repository uses a licence we do not classify automatically, so read its LICENSE file before any commercial use.
Is it still maintained?
Yes. The repository last received commits 9 days ago.
What is it written in?
Mainly Python, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 24, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • hgrecco/pint2,830 ★ · +22
Star history
Repository2026-10-042026-11-24
hgrecco/pint2.8k2.8k

22 Stars in the last 51 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

The bug Pint exists to prevent

Adding 3 meters to 4 centimeters with plain floats gives 7. That number is wrong in a way no type checker catches, and it is the failure Pint is built around. A Pint quantity is a numerical value paired with a unit, and arithmetic between quantities propagates the unit instead of discarding it. The README's first example shows the intended shape of the library: 3 * ureg.meter + 4 * ureg.cm returns Quantity(3.04, "meter").

The audience is anyone writing Python that crosses unit systems: instrument drivers, simulation setup, data reduction, anything that reads a CSV column labelled in millimeters and compares it to a constant in meters. Pint does not make those programs faster. It makes the unit part of the value, so a mismatch surfaces as an exception or a conversion rather than as a plausible-looking number.

The project describes itself as BSD licensed and running on Python 3.12 and above with minimal dependencies. The last push to the repository was on 2026-09-18, and the repository is not archived.

How the UnitRegistry parses and propagates units

The entry point is pint.UnitRegistry(). It reads a text file of unit definitions shipped with the package, pint/default_en.txt, and builds the registry from it. That file is the whole unit system: prefixes, units, constants. The README calls this out as a design principle, that definitions are standalone and loaded from a text file so adding or changing units does not involve changing code. In practice you can point a UnitRegistry at your own definition file and get a different, or extended, universe of units.

Parsing is generative rather than a lookup table. The README explains that because kilo and meter are both defined, Pint understands kilometers without kilometers being defined anywhere. Plural forms work the same way. This is why the definition file stays short compared with libraries that enumerate every prefixed spelling.

The numerical type is not fixed. Pint works with float, decimal, Fraction, or a NumPy ndarray, and NumPy is optional. When you do use an ndarray, the README states that ufuncs are supported with automatic unit conversion, and gives numpy.arccos as an example: it requires a dimensionless input and returns a quantity in radians. That behaviour comes from Pint's own array type rather than from patching NumPy, which is the claim the README makes explicitly ("without monkey patching or wrapping numpy").

Installing Pint and converting units on the command line

Installation is a single pip command. The README gives no version pin and no post-install step; the package pulls in platformdirs, typing_extensions, flexcache and flexparser, which the pyproject file lists as the only required dependencies.

bash
pip install pint

If you use conda, the README gives the conda-forge channel as the alternative:

bash
conda install -c conda-forge pint

The package also installs a command-line script, pint-convert, which the README describes as a quick way to convert between units or get conversion factors. That is the fastest way to check whether a unit you care about is in the default registry before writing any Python.

For use inside a program, the README's example is the natural first step: create a registry, build a quantity by multiplying a number by a unit attribute, and add quantities with different units to see the conversion happen.

python
import pint

ureg = pint.UnitRegistry()
print(3 * ureg.meter + 4 * ureg.cm)

The expected output is Quantity(3.04, "meter"), which is the README's own result. If you see that, the registry loaded and the conversion ran. NumPy support is opt-in through an extra rather than being a hard requirement, and the pyproject file pins that extra at numpy >= 2.0.0.

Where Pint gets in the way

A quantity is not a float. Any code that expects a bare number, a C extension, a JSON serializer, or a library that calls math functions directly will need the magnitude extracted first, and that extraction is a place where units can be dropped by accident. The convenience of unit-aware arithmetic is paid for at every boundary between Pint-aware and Pint-unaware code.

Performance is the second constraint. Every operation goes through unit logic, and the NumPy integration works through Pint's own array wrapper rather than a raw ndarray. The project's own test extras include pytest-benchmark and pytest-codspeed, which indicates benchmarking is part of the development process, but the README makes no performance claim and none should be assumed. If a loop is hot and the units never change, carrying quantities through it is overhead you are choosing.

The third limitation is scope. Pint handles units and conversions. It does not validate that a formula is physically correct, and it does not know that your meter reading is a length rather than a count. Temperature is the sharp edge: the README notes support for units with different reference points, like positions on a map or absolute temperature scales. That is exactly the case where naive multiplication of a quantity by a scalar stops matching intuition, and it is worth reading the documentation rather than guessing.

Finally, the project's own classifier in pyproject.toml is "Development Status :: 4 - Beta". That is the maintainers' label, and it sits oddly next to a package this widely used, but it is what the metadata says.

Pint against a unit library that wraps NumPy

The closest comparison in the Python ecosystem is astropy.units, which comes from astronomy and is built around NumPy arrays as the primary object. The difference in approach matters more than the feature list. Astropy's Quantity is an ndarray subclass, so array behaviour is inherited; Pint's choice is to keep NumPy optional and provide its own array type, which the README frames as avoiding monkey patching or wrapping. If your work is astronomy or you already depend on Astropy, its units are the path of least resistance. If you want units on scalars with no NumPy dependency at all, or you want to swap the numerical type per project, Pint's design is the one that fits.

There is also a data-frame layer rather than a competing library: the README points to pint-pandas, which uses Pandas extension types so that operations on DataFrames and between columns are units aware. That is integration with Pandas, not a replacement for it, and the pyproject extras list pint-pandas >= 0.3 under the pandas extra.

Licence, dependencies and the cost of upgrades

The LICENSE file is present at the repository root and pyproject.toml declares the licence as BSD-3-Clause, while the repository metadata reports NOASSERTION. Those two signals disagree, and the pyproject declaration is the more specific of the two. BSD-3-Clause is permissive, so redistribution and modification are allowed with the usual conditions; this is a description of the declared licence, not legal advice, and anyone embedding Pint in a distributed product should read LICENSE themselves.

The dependency surface is small and deliberate: platformdirs, typing_extensions, flexcache, flexparser. The README states that Pint only interacts with packages like numpy and uncertainties if they are installed, which means an upgrade of Pint does not drag a numerical stack with it. That is the good news for upgrade cost.

The less good news is the Python floor. requires-python is ">=3.12", and the classifiers list 3.12, 3.13 and 3.14 only. A codebase still on 3.11 cannot take the current release without first moving its interpreter. The optional extras carry their own pins, including numpy >= 2.0.0, uncertainties >= 3.1.6, babel <= 2.8, dask < 2025.3.0, and pint-pandas >= 0.3, so an upgrade of Pint can force movement in those packages too. The dask pin is documented in pyproject.toml with a comment about a RuntimeError when using an asynchronous Client in a synchronous context, which is a good example of an extra that is not free to combine.

Editorial conclusion

Adopt Pint when your code does arithmetic across units and you want the unit checked rather than the number silently wrong: scientific and engineering code, simulation inputs, data pipelines that mix SI and imperial. Skip it when your numbers are dimensionless, when the unit is fixed by convention, or when you cannot accept per-operation overhead on hot loops. Before committing, verify three things against your own environment: that pip install pint resolves on your Python version, that pint-convert answers for the units you actually use, and that the optional extras you need (numpy, uncertainties, pandas) are available for your interpreter.

Frequently asked questions

How do you use Pint in Python?

Create a registry with pint.UnitRegistry(), then multiply a number by a unit attribute such as ureg.meter to build a quantity. Arithmetic between quantities converts units automatically, so 3 * ureg.meter + 4 * ureg.cm gives Quantity(3.04, "meter").

How does the pint package in Python handle units?

It loads unit definitions from a text file into a UnitRegistry and represents values as a number paired with a unit. Prefixed and pluralized forms are recognised without being defined, and arithmetic between quantities propagates and converts the unit.

Which Python versions does Pint support?

The pyproject file sets requires-python to >=3.12 and lists classifiers for Python 3.12, 3.13 and 3.14. Older interpreters are not covered by the current release.

Does Pint require NumPy?

No. The README states that NumPy is not required but supported, and the required dependencies are platformdirs, typing_extensions, flexcache and flexparser. NumPy is available as an optional extra pinned at numpy >= 2.0.0.

What does the pint-convert command do?

The README describes it as a command-line script that provides a quick way to convert between units or get conversion factors, without writing Python.

What licence is Pint released under?

pyproject.toml declares the licence as BSD-3-Clause, and a LICENSE file is present at the repository root, while the repository metadata reports NOASSERTION. Check the LICENSE file itself before relying on either.

Official sources

  1. hgrecco/pint on GitHub
  2. Issues
  3. Project website
  4. README
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/hgrecco-pint.svg)](https://hysenlabs.com/projects/hgrecco-pint)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/hgrecco-pint.svg)](https://hysenlabs.com/projects/hgrecco-pint)

Was this useful?