Package: misura
misura>>>frommisura.quantitiesimportquantity>>>quantity(7,"m",1.5)/quantity(2,"s")3.5±0.75m/s>>>frommisura.currenciesimportcurrency>>>currency(2,"EUR")+currency(3,"USD")5.17USDPython library providing effortless unit handling and currency conversion for scientific and engineering purposes.misurais a powerful Python library designed to facilitate the efficient handling of units of measure for scientific and engineering applications, including currencies handling and conversion with constantly updated exchange rates. With its unified interface for dealing with different units and their conversions, you can quickly and accurately complete calculations without the need for complex manual conversions. Additionally,misurasupports uncertainty handling allowing you to work with physical quantities and their associated uncertainties in a user-friendly and intuitive fashion. What's more,misuragrants you the flexibility to create custom units of measure, so you can work in your preferred units.Make sure to take a look at thedocumentation, at thecontributing guidelinesand at theexamples.FeaturesMathematical and logical operations between quantities:Example,exampleCurrencies handling with daily updated exchange rates.Uncertainty handling:ExampleManual conversions:ExampleAutomatic conversions on operations:ExampleUnpack and pack derived units:Example,exampleUser defined base and derived units:ExampleLarge compatibility with other libraries:ExampleCustom exceptions:ExampleInstallationInstalling misuramisuracan be installed fromPyPIby:python3 -m pip install --upgrade misuraVerifying installation and base informationsBy:python -m misurayou'll be able to verify the installation ofmisuraalong getting some informations about the library:misura

Python library providing effortless unit handling and currency conversion for scientific and engineering purposes.

Developed by Andrea Di Antonio, more on https://github.com/diantonioandrea/misura
Documentation on https://misura.diantonioandrea.com
Bug tracker on https://github.com/diantonioandrea/misura/issuesImporting misuramisuracan be imported by:import misuraExamplesThese are some examples of operations between quantities.Note that, by enablingglobals.style.unitHighlighting,misurauses colorama to highlight units of measure. by disabling it, the output is in the form ofnum [unit]Mathematical operationsfrommisura.quantitiesimportquantitynum1=quantity(2,"m s-1")num2=quantity(4,"m s-1")num3=quantity(2,"s",.5)print(num1+num2)print((num1+num2).dimension())print(num1*num2)print(num1/num3)print(num3**2)The output is:6 m / s
[length / time]
8 m(2) / s(2)
1.0 ± 0.25 m / s(2)
4 ± 2.0 s(2)Currenciesfrommisura.currenciesimportcurrencycur1=currency(2,"EUR")cur2=currency(3,"USD")print(cur0*2)print(cur1+cur0)The output is:4 EUR
5.17 USDWorking with other librariesfrommisura.quantitiesimportquantity,convertfromdecimalimportDecimal,getcontextimportnumpygetcontext().prec=40arr1=numpy.array([quantity(2,"m"),quantity(50,"m s-1"),quantity(2,"kg")])arr2=quantity(numpy.array([1,2,3]),"J")num2=quantity(numpy.sqrt(Decimal(5)),"kg")print(arr1*3)print(arr2**2)print(num2)The output is:[6 m 150 m / s 6 kg]
[1 4 9] J(2)
2.236067977499789696409173668731276235441 kgUnit highlighting helps distinguish between different numbers.User defined units of measurefrommisura.quantitiesimportquantity,convertfrommisura.tablesimportaddUnitaddUnit("volume",{"L":1,"daL":10,"hL":100,"kL":1000,"dL":0.1,"cL":0.01,"mL":0.001},"dm3")num1=quantity(3,"L")print(convert(num1,"cm3"))The output is:3000.0 cm(3)Manual and automatic conversionfrommisura.quantitiesimportquantity,convertnum1=quantity(2,"m2")num2=quantity(4,"kg")num3=quantity(400,"m s-1")print(convert(num1,"cm2"))print(num2+quantity(5,"g"))print(convert(num3,"km",partial=True))The output is:20000.0 cm(2)
4.005 kg
0.4 km / sUnpack derived quantitiesfrommisura.quantitiesimportquantity,unpacknum1=quantity(2,"J2")num2=quantity(4,"C H")print(unpack(num1))print(unpack(num2,"H"))The output is:2.0 kg(2) m(4) / s(4)
4.0 C kg m(2) / A(2) s(2)Pack derived quantitiesfrommisura.quantitiesimportquantity,packnum1=quantity(3,"N m T")num2=quantity(45,"A2 s2")print(pack(num1,"J",ignore="T"))print(pack(num2,"C",full=True))The output is:3.0 J T
45.0 C(2)Comparisonsfrommisura.quantitiesimportquantitynum1=quantity(2,"m s-1")num2=quantity(4,"m s-1")num3=quantity(2,"s")print(num1>num2)print(num2<6)print(num1>num3)The output is:False
True

misura.conversion.ConversionError: cannot convert from 's' to 'm s-1'
raised by: '2 s' -> 'm s-1'Unary operators and functionsfrommisura.quantitiesimportquantityfrommisura.globalsimportstylefrommathimporttruncstyle.quantityHighlighting=Falsenum1=quantity(2,"m s-1")num2=quantity(4.5,"m s-1")num3=quantity(-2,"s")print(-num1)print(trunc(num2))print(abs(num3))The output is:-2 [m / s]
4 [m / s]
2 [s]Formattingfrommisura.quantitiesimportquantitynum1=quantity(2000,"m s-1")print("Exponential notation:{:.2e}".format(num1))The output is:Exponential notation: 2.00e+00 m / s