unyts
I identified the opportunity to use a directed graph (digraph) network to build a unit converter capable of converting between any two units without the need to populate an endless table of predefined conversions. Powered by the Breadth-First Search (BFS) algorithm to traverse the network, the converter determines conversion paths from a given unit (or ratio of units) to any other compatible unit (or ratio), provided that a connecting path exists.
This package is currently under active development and is regularly updated. Backward compatibility will be maintained whenever 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 units k to m to make km, 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 class Unit powered 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 three ways:
- Calling the function
units()to define instances of the Units class, that holds values associated to units, or, quantities. - As unit converter with the function
convert()to explicitly make conversion of numeric variables and instances. - As unit converter for single numerical values, using the GUI.
A comprehensive user manual is also available here: UNYTS_User_Manual.
To launch the GUI
From an OS terminal or console, execute python -m unyts
In the interface, simply type in the units to convert and the value to be converted and click the convert button or hit Enter key.
To use the units converter function convert():
from unyts import convert
convert(value, from_units, to_units)
where:
- value is a number (int, float, numpy.array, etc)
- from_units is a string defining the units of value (i.e.: 'ft')
- to_units is a string representing the units to convert value (i.e.: 'km')
To create instances of the Unit class using the units() function:
from unyts import units
variable = units(value, units)
- value is a number (
int,float,numpy.array, etc) - units is a string defining the units of value (i.e.: 'ft')
Then simply operate with the Unit instances or the variables related to them:
In: units(6, 'in') + units(1, 'ft')
Out: 18_in
Referring to the Unit class:
from unyts import Unit
- The
Unitclass is not intended to be used to create Unit instances, but to allow checking if other objectisinstanceof Unit: i.e.:isinstance(variable, Unit) - In order to create instances of Unit it is convenient to use the
units()function as it will return the appropriate Unit subclass.
Uses examples:
For further examples of use, the following Jupyter notebook unyts_demo intends to be a guide on how to use this converter and units classes.
To install this package:
Install it from the pypi.org repository:
pip install unyts
or upgrade to the latest version:
pip install --upgrade unyts !
Optional 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 of unyts:
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
Metadata
Release files for unyts 1.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| unyts-1.0.5.tar.gz | 288.0 kB | Without provenance | Details for unyts-1.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| unyts-1.0.5-py3-none-any.whl | Python 3 | none | any | Details for unyts-1.0.5-py3-none-any.whl |
Total release size: 571.7 kB
Release files / unyts-1.0.5.tar.gz
| Download URL | unyts-1.0.5.tar.gz |
|---|---|
| Size | 288.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dfc66ad619882b4c6847cc021c7533ccf55b94b35ce1d7c820aaf133139b04c7
|
|
BLAKE2b-256 checksum How to use checksums |
9813156292989b01c101a6607ab8f10ff88e9371df2a61edd3707f1b7e4470ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.0
|
Release files / unyts-1.0.5-py3-none-any.whl
| Download URL | unyts-1.0.5-py3-none-any.whl |
|---|---|
| Size | 283.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8ec1a77f1a73c17d6ece038f8bc1655aad018e0e9c87eb42e1ab9164df18892e
|
|
BLAKE2b-256 checksum How to use checksums |
f69e6f15a1e013e67e4c2cecd714408c04ec2be21dc75295ed2f856cfd03756d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.0
|
Security for unyts 1.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.