semvec/pypi-packages huggingface dataset:
pynits 0.1.1
The Python library to work with all sorts of units.
License: MIT
Requires Python: >=3.9,<4.0
Keywords: pyunits,pynits,units

# Pynits

Pynits is a Python library that allows you to easily work with pre-defined units *(like imperial and metric units)* and creating your own units aswell.

Installing
----------
You can install and update pynits using pip:
```
$ pip install pynits
```

Usage
-----

You can use pyunits to convert to different units.
```py
import pynits

km = pynits.Kilometer(int(input("Enter an amount of kilometers: ")))
cm = km.convert(pynits.Centimeter)
print(f"{km.amount} kilometers are equivalent to {cm}")
```
```
Enter an amount of kilometers: 12
12 kilometers are equivalent to 1200000
```

Or even better, you can create your custom units.
```py
import pynits

# Create the converters for the custom units
class ACNHBellConverter(pynits.base.Converter):
    def __init__(self):
        conversions = [
            # For my dear TLOZ fans, this is not the actual conversion, it's just an example.
            (TLOZRupee, 0.0745)
        ]
        super().__init__(parent_unit=ACNHBell, conversions=conversions)


class TLOZRupeeConverter(pynits.base.Converter):
    def __init__(self):
        conversions = [(ACNHBell, 13.42)]
        super().__init__(parent_unit=TLOZRupee, conversions=conversions)


class ACNHBell(pynits.base.UnitMixin):
    def __init__(self, amount: float):
        super().__init__(amount=amount, converter=ACNHBellConverter())


class TLOZRupee(pynits.base.UnitMixin):
    def __init__(self, amount: float):
        super().__init__(amount=amount, converter=TLOZRupeeConverter())


bells = ACNHBell(int(input("Enter an amount of Animal Crossing: New Horizons Bell: ")))
rupee = bells.convert(TLOZRupee)

print(f'{bells.amount} Bells are equivalent to {rupee} rupees from The Legend of Zelda.')
```
```
Enter an amount of Animal Crossing: New Horizons Bell: 15000
15000 Bells are equivalent to 1117.5 rupees from The Legend of Zelda.
```

Contributing
------------
Work in progress