Skip to main content

Python library for easy unit handling and conversion for scientific & engineering applications.

Project description

PyPI GitHub last commit GitHub Release Date

misura

Python library for easy unit handling and conversion[^1] for scientific & engineering applications.

misura is a Python library designed to simplify the handling of units of measure for scientific and engineering applications. It provides a unified interface for dealing with different units and their conversions, allowing for quick and accurate calculations without the need for complex manual conversions.

Make sure to take a look at the documentation, at the contributing guidelines and at the examples.

[^1]: To be implemented.

Installation

Installing misura

misura can be installed from PyPI by:

python3 -m pip install --upgrade misura

Importing misura

misura can be imported by:

import misura

Examples

These are some examples of operations between units of measure.
Note that, by enabling misura.style.unitHighlighting, misura uses colorama to highlight units of measure. by disabling it, the output is in the form of num [unit]

Creating a number with unit of measure:

from misura import unit

num = unit(2, "m s-1")

print(num)

The output is:

2 m / s

Mathematical operations

from misura import unit

num1 = unit(2, "m s-1")
num2 = unit(4, "m s-1")
num3 = unit(2, "s")

print(num1 + num2)
print(num1 * num2)
print(num1 / num3)
print(num3 ** 2)

The output is:

6 m / s
8 m(2.0) / s(2.0)
1.0 m / s(2.0)
4 s(2.0)

Comparisons

from misura import unit

num1 = unit(2, "m s-1")
num2 = unit(4, "m s-1")
num3 = unit(2, "s")

print(num1 > num2)
print(num2 < 6)
print(num1 > num3)

The output is:

False
True
"misura.units.SymbolError: unsupported operand symbol(s) for >: 'm s-1.0' and 's'"

Unary operators and functions

from misura import unit
from misura import style
from math import trunc

style.unitHighlighting = False

num1 = unit(2, "m s-1")
num2 = unit(4.5, "m s-1")
num3 = unit(-2, "s")

print(-num1)
print(trunc(num2))
print(abs(num3))

The output is:

-2 [m / s]
4 [m / s]
2 [s]

Formatting

from misura import unit

num1 = unit(2000, "m s-1")

print("Exponential notation: {:.2e}".format(num1))

The output is:

Exponential notation: 2.00e+00 m / s

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

misura-1.0.0.tar.gz (8.9 kB view hashes)

Uploaded Source

Built Distribution

misura-1.0.0-py3-none-any.whl (5.2 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