Skip to main content

unithandler

This is a package for managing and interacting with units. The focus of the package is to provide numeric type objects (e.g. float and int) which also have a unit attribute. The three core classes of this package are Unit, UnitFloat, and UnitInt.

While there are a variety of packages which support units, this package focused on enabling straightforward implementation of units without affecting Pythonic functionality of the numbers.

Additionally, the UnitFloat class was designed to represent the magnitude of the stored value as best as possible with an appropriate SI prefix. The value stored is scaled in its representation, but remains locked to a specified prefix when operated upon. For example, 0.005 with the unit 'L' would be represented as 5 mL if printed, but will behave as 0.005 for any numeric operations. This was implemented to automatically keep track of the scale of a unit while allowing the user to easily visualize the magnitude of the stored value.

Installation

unithandler is registered on PyPI.

pip install unithandler

Source files may be found in the GitLab repository.

The Unit class

This class handles all unit-associated attributes and methods. The unit attribute returns an appropriately formatted unit (complete with superscripts) as a string. Units are managed in dictionary format, associating a power to each unit denoted. The class (and its subclasses) are structured) so that the units may be easily modified using python built-in multiplication and division operators (exactly as one would track units with pen and paper).

The UnitFloat class

The UnitFloat class is a float-like numeric class that has an associated unit. The class has all defined Python magic methods, which enable all appropriate modifications and operations on or by UnitFloat objects. Typically, the return of each magic method is another UnitFloat instance, but see the UnitFloat documentation for further details.

Known limitations

Since this package is written entirely in Python, it does not provide direct access to values as the true float and int would. As such, some errors or unintended functionality may be encountered.

Currently numpy support is limited to basic ufunc implementation. Unexpected behaviour may be encountered when performing numpy operations on UnitFloat or UnitInt. We are working to implement full support for vectorized operations on the numeric classes in this package. To the best of our knowledge, the math package is fully supported, so any numeric operations should be performed with that package while we work to enable numpy support.

Metadata

Release files for unithandler 1.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for unithandler 1.6.0
File Size Uploaded Provenance Actions
unithandler-1.6.0.tar.gz 20.5 kB Without provenance Details for unithandler-1.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for unithandler 1.6.0
File Interpreter ABI Platform Actions
unithandler-1.6.0-py3-none-any.whl Python 3 none any Details for unithandler-1.6.0-py3-none-any.whl

Total release size: 40.5 kB

Release files / unithandler-1.6.0.tar.gz

Download URL unithandler-1.6.0.tar.gz
Size 20.5 kB
Tags Source
SHA-256 checksum
How to use checksums
41a9c6545316a2c2606a7b309b86877c3a5018c97ae61585d00a207ba57ba3db
BLAKE2b-256 checksum
How to use checksums
4c3e8bc9961dfec436dc4be4475871b544f0d6068a875304be28b4b73735df90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.7.1 requests/2.26.0 setuptools/58.1.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.7

Release files / unithandler-1.6.0-py3-none-any.whl

Download URL unithandler-1.6.0-py3-none-any.whl
Size 20.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
47e5b0629635e6f249ca292e765aa4e73ec1207724203fb1a0b436626704215a
BLAKE2b-256 checksum
How to use checksums
81138f183eff34f7c8bb14edcdc34069e2acbcd5c915ac105fc75dfe186ed533
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.7.1 requests/2.26.0 setuptools/58.1.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.7

Security for unithandler 1.6.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page