Skip to main content

Magnitude Order

Project description

magorder

This library streamlines the conversion of different multipliers, like transforming nm (nanometers) to meters, or kilobytes to gigabytes.

It is meant to take the load off the developer of larger applications.

Installation

Install it as usual:

pip install magorder

Dependencies

This library has no runtime dependencies.

Usage

To use the library in some other code:

from magorder.stdsi import StdSIMagnitudeUnit

mag = StdSIMagnitudeUnit("m")
assert mag.transform(0.1, "km") == 100
assert mag.transform(100_000_000, "µm") == 100
assert mag.transform(100_000_000_000_000_000_000_000_000.0, "ym") == 100
assert mag.transform(0.0000000000000000000001, "Ym", 3) == 100

Or to transform data units:

from magorder.data import SIDataMagnitudeUnit, IECDataMagnitudeUnit

mags = SIDataMagnitudeUnit("b")
assert mags.transform(1, "kb") == 1000
assert mags.transform(1, "Gb:kb") == 1_000_000

mags = IECDataMagnitudeUnit("b")
assert mags.transform(1, "Kib") == 1024
assert mags.transform(4096, "Mib:Gib") == 4

See the module tests for more examples.

License

Check the file LICENSE.

Contributions

Feel free to contribute to this code at:

https://github.com/russoz/magorder

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

magorder-0.11.tar.gz (15.0 kB view hashes)

Uploaded Source

Built Distribution

magorder-0.11-py3-none-any.whl (15.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page