Package: qntpy
TL;DRquantipy gives your calculations:intuitive dimensional analysiseffortless unit conversionautomatic commensurability enforcementseeherefor a list of units and constants the package addswhat is quantipy?quantipy is a dimensional analysis module for engineering and physics calculations that allows you to manipulate physical quantities in an intutive way. it also enforces proper unit usage and prevents many unit errors.why quantipy?there are several other python packages that provide support for quantities with units. here is a (non-exhaustive) list:astropy.unitsDimPyDUQMagnitudenumericalunitsPintQuantitiesScalarthese packages serve a variety of purposes, and all have their strengths and weaknesses. depending on your application, one of these might be better for you--but quantipy has certain features that sets it apart from each of these. In short,quantipy is ideal as a calculator for quick napkin calculations involving physical quantities.how does it work?here's a simple example-- let's say i want to find the the velocity of an object involved in an inelastic collision:fromqntpyimport*m1=10*kgm2=5*kgv1=5.4*m/sv2=3.2*m/spCombined=m1*v1+m2*v2m3=m1+m2v3=pCombined/m3print(v3)# 4.666666666666667 ms⁻¹ok, but how is that useful?sure, that example didn't really need quantipy. but that's not all it can do: for example, take this calculation for the force of an electromagnet using the equation $F = (NI)^2\mu_0 \frac{A}{2l^2}$:fromqntpyimport*fromqntpy.constantsimportmu_0,g_earthm_1=0.9*lbm# quantipy will automatically convert every unit you enter into standard unitscurrent=3*Alength=2*cmturns=5000area=100*mm**2force=(turns*current)**2*mu_0*area/(2*(length**2))print(force.round(4))# 35.3429 Nprint((m_1*g_earth).round(4))# 4.0007 Nif(force>m_1*g_earth):print("magnet can lift load!")else:print("magnet is underpowered :(")# magnet can lift load!a little more useful, huh?but wait, there's more!quantipy includes other features too, such as commonly-used physics constants, the ability to represent a value in whatever base or derived units you want, and even currency conversion support, updated daily (with an API key):fromqntpyimport*fromqntpy.currencyimport*price=399*USDdata=23*GiBweight=430*lbfdataPerWeightCurrency=data/price/weightprint(dataPerWeightCurrency.termsOf(MB/(EUR*kN),4))# 34.3292 MB/EUR•kNfromqntpyimport*importqntpy.constantsasqcmass=3.043*MeVc2num_electrons=mass/qc.m_e# call qc.constants() to see all available constantsprint(round(num_electrons,0))# 6.0currency unitsin addition to normal physics and engineering units, several currencies are defined by quantipy via theAPILayer Exchange Rates Data API. you can access them by importingqntpy.currencyand adding your APILayer API key to theapi_key.txtfile that is generated by the module--this file lives undersite-packages/qntpy/in your python environment folder. you can reference currencies in code with theirISO 4217currency codes and use them as you would other units.importqntpy.currencyascncyprint(cncy.BTC.termsOf(cncy.EUR))# '26369.10595485628 EUR'unit enforcementquantipy automatically enforces proper usage of units in your calculations. trying to add incompatible units will throw an error:fromqntpyimport*m1=10*kgm2=12*m/sprint(m1+m2)ArithmeticError:Incompatibleunits:kgandm/sthis feature will solve a surprising amount of calculation errors.defining custom unitsyou can even define your own custom constants with your own symbols and conversion factors and use them in your code!fromqntpyimport*# the first argument is the commensurability of the new unit, the second is its unit symbol, the third is its value# define a new unit "Fizz" equal to 12 m/kg, with the symbol "Fz"Fizz=Unit.derived(m/kg,"Fz",12)value=12000*m/kgprint(value.termsOf(Fizz))# 1000.0 FznewValue=1000*Fizzprint(newValue==value)# Truebuilt-in functions are also provided to automatically create prefixed units:kFizz=kilo(Fizz)print(value.termsOf(kFizz))# 1.0 kFzthese functions define a new derived unit whose symbol is the same as the original unit with the SI prefix added.the included prefix functions are as follows:functionvalueprefixpico$10^{-12}{}$pnano$10^{-9}{}$nmicro$10^{-6}{}$μmilli$10^{-3}{}$mkilo$10^{3}{}$kmega$10^{6}{}$Mgiga$10^{9}{}$Gtera$10^{12}{}$Tpeta$10^{15}{}$Pnon-absolute units# define a new unit "Buzz" equal to 2 J, but "0 Buzzes" is equal to 11 J.Buzz=Unit.derived(J,"Bz",2,11)this may seem like a weird and arbitrary feature, but it's how quantipy is able to work with units like degrees Celsius, which aren't based on absolute scales.print(0*Buzz)# 11 Jbe careful how you use non-absolute units; for example, the expression "12*degC / kg" is actually equal to "285.15 K / kg". it's preferred to use absolute units (kelvins and rankines) for conversion factors. non-absolute units are mostly added for completeness, and so you can convert between them:print((43*degF).termsOf(K),(16*degF).termsOf(degC))# 279.2611111111111 K -8.888888888888857 ⁰Cmore informationfor a full list of units and constants added by quantipy, seehere.