Pint – A Python package to define, operate and manipulate physical quantities
I&#x27;d like to point to a separate library for dealing with units: Barril<p><a href="https:&#x2F;&#x2F;github.com&#x2F;ESSS&#x2F;barril" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ESSS&#x2F;barril</a><p>Docs at: <a href="https:&#x2F;&#x2F;barril.readthedocs.io&#x2F;en&#x2F;latest&#x2F;" rel="nofollow">https:&#x2F;&#x2F;barril.readthedocs.io&#x2F;en&#x2F;latest&#x2F;</a><p>While it does have support for creating &quot;random&quot; units from computation (such as Pint, unum, etc), it&#x27;s more tailored to having a database of units (which the library has by default -- see: <a href="https:&#x2F;&#x2F;barril.readthedocs.io&#x2F;en&#x2F;latest&#x2F;units.html" rel="nofollow">https:&#x2F;&#x2F;barril.readthedocs.io&#x2F;en&#x2F;latest&#x2F;units.html</a> and the implementation: <a href="https:&#x2F;&#x2F;github.com&#x2F;ESSS&#x2F;barril&#x2F;blob&#x2F;master&#x2F;src&#x2F;barril&#x2F;units&#x2F;posc.py" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ESSS&#x2F;barril&#x2F;blob&#x2F;master&#x2F;src&#x2F;barril&#x2F;units&#x2F;...</a>) and then you can query and transform based on the related units.<p>One thing it supports that does a lot of difference in that regard is dealing with unit conversions which would be &quot;dimentionless&quot; -- such as m3&#x2F;m3 (i.e.:`volume per volume`) and then converting to `cm3&#x2F;m3` and keeping the dimension.<p>i.e.: in pint:<p><pre><code>  &gt;&gt;&gt; import pint
  &gt;&gt;&gt; ureg = pint.UnitRegistry()
  &gt;&gt;&gt; m = ureg.meter
  &gt;&gt;&gt; v = 1 \* (m\*3)&#x2F;(m\*3)
  &gt;&gt;&gt; v
  &lt;Quantity(1.0, &#x27;dimensionless&#x27;)&gt;
</code></pre>
And then, after that (as far as I know), it&#x27;s not really possible to do additional unit conversions properly knowing that it was m3&#x2F;m3.<p>In barril:<p><pre><code>  &gt;&gt;&gt; from barril.units import Scalar
  &gt;&gt;&gt; a = Scalar(3, &#x27;m3&#x2F;m3&#x27;)
  &gt;&gt;&gt; a.GetValue(&#x27;cm3&#x2F;m3&#x27;)
  3000000.0
  &gt;&gt;&gt; a.category
  &#x27;volume per volume&#x27;
  &gt;&gt;&gt; a.unit
  &#x27;m3&#x2F;m3&#x27;
</code></pre>
and something as `a.GetValue(&#x27;m3&#x27;)` (with an invalid value) would give an error saying that the conversion is actually invalid.<p>The unit database (which was initially based on the POSC Units of Measure Dictionary) is a bit more tailored for the Oil &amp; Gas field, but should be usable outside of it too.