Skip to main content

A package for units.

Project description

AllYourUnitAreBelongToUs

version version version version

Installation

pip install ayuabtu

Usage

Creating quantities

Create quantities with a given unit:

>>> from ayuabtu.quantities import Length
>>> from ayuabtu.units import LengthUnit
>>> Length(2, LengthUnit.METER)
2 m

Or you can use the unit specific factory methods:

>>> from ayuabtu.quantities import Length
>>> Length.from_meters(2)
2 m

You can also access only the value with

>>> from ayuabtu.quantities import Length
>>> Length.from_meters(2).value
2

Converting units

You can convert a quantity to a quantity with another unit

>>> from ayuabtu.quantities import Length
>>> from ayuabtu.units import LengthUnit
>>> distance_metric = Length.from_meters(2)
>>> distance_metric.to_unit(LengthUnit.FOOT)
6.561679790026246 ft

If you just need the numeric value of the quantity, but expressed in another unit, use

>>> from ayuabtu.quantities import Length
>>> from ayuabtu.units import LengthUnit
>>> distance_metric = Length.from_meters(2)
>>> distance_metric.as_unit(LengthUnit.FOOT)
6.561679790026246

For this common usecase, there are also shorthand methods:

>>> from ayuabtu.quantities import Length
>>> distance_metric = Length.from_meters(2)
>>> distance_metric.feet()
6.561679790026246

Quantity arithmetics

Coming soon ...

Custom units

Coming soon ...

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

ayuabtu-0.0.3.tar.gz (7.4 kB view hashes)

Uploaded Source

Built Distribution

ayuabtu-0.0.3-py3-none-any.whl (23.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