Package: unyts
unytsAfter culminating a project for a class from MITx courses, I saw the opportunity to use adigraph networkto build a units converter able to convert from any units to any units without the need to populate a huge but finite table of possible conversions. Powered by theBreadth First Search, orBFS, algorithm to search through the network, this converter can find conversions from a particular Unit (or ratio of units) to any other Unit (or ratio) as long as a path connecting them exists.This package is under development and is regularly updated. Back compatibility is intended to be maintained when possible.What do this package contains:It is loaded with a network of units preloaded for distances, area, volume, mass and time conversions defined for SI and Imperial systems according to the definition of each Unit, i.e.:1_foot = 12_inches.Prefixes applied to the basic units, like in SI unitsktomto makekm, are loaded as a network of conversion paths allowing the algorithm to apply the prefix to any other unit in the same system.It provides a classUnitpowered with arithmetic and logic operations to intrinsically consider unit conversions when making calculations.How to use this package:This package is intended to be used in two ways:Calling the functionunits()to define instances of theUnitsclass, that holdsvalues associated to units, or,quantities.As unit converter with the functionconvert()to explicitly make conversion of numeric variables and instances.To use theunits converterfunctionconvert():from unyts import convertconvert(value, from_units, to_units)where:valueis a number (int, float, numpy.array, etc)from_unitsis a string defining the units ofvalue(i.e.: 'ft')to_unitsis a string representing the units to convertvalue(i.e.: 'km')To create instances of theUnitclass using theunits()function:from unyts import unitsvariable = units(value, units)valueis a number (int,float,numpy.array, etc)unitsis a string defining the units ofvalue(i.e.: 'ft')Then simply operate with theUnitinstances or the variables related to them:In: units(6, 'in') + units(1, 'ft')Out: 18_inReferring to theUnitclass:from unyts import UnitTheUnitclass is not intended to be used to createUnitinstances, but to allow checking if other objectisinstanceofUnit: i.e.:isinstance(variable, Unit)In order to create instances ofUnitit is convenient to use theunits()function as it will return the appropriateUnitsubclass.Uses examples:For further examples of use, the following Jupyter notebookunyts_demointends to be a guide on how to use this converter and units classes.To install this package:Install it from thepypi.orgrepository:pip install unytsor upgrade to the latest version:pip install --upgrade unytsOptional requisites:The main functionalities are purely Python powered and does not require any other package to work but, if present, some commonly known packages are used to improve the operability ofunyts:NumPyto be able to deal with iterables not of nparray type, like (list of values)Pandasto be able to recognize Series and DataFramescloudpickleto be able to save internal dictionaries and network to cache file, for faster loadingopenpyxlif willing to export the units network to a pandas DataFrame