Firkin is a Python module designed for converting measurement units. With Firkin, users can effortlessly convert between diverse measurement units with great precision.
To start using Firkin, you'll first need to create an instance of UnitManager using the following command:
>>> um=UnitManager()
Next, you can create two families of units. The first is liter, which uses SIFamily to automatically create units with the SI prefixes. Here's a list of the prefixes and their meanings:
prefix meaning value
f femto 10-15
p pico 10-12
n nano 10-9
µ micro 10-6
m milli 10-3
k kilo 103
M mega 106
G giga 109
T tera 1012
To add the liter family to your UnitManager instance, use the following command:
>>> um.add(SIFamily(base='l', name='liter'))
Now you have a UnitManager instance that knows about fl, pl, nl, ..., Ml, Gl, and Tl. To convert 10000 ml to liters, simply use the convert_to_unit method:
>>> um.convert_to_unit(1e4, 'ml', 'l')
(Decimal("10.0000"), 'l')
Next, you can create a family by hand using the Family class. Here's an example:
>>> f=Family(name='f', base='gallon')
>>> f.add('barrel', 36, 'gallon')
>>> f.add('kilderkin', 0.5, 'barrel')
>>> f.add('firkin', 0.5, 'kilderkin')
Now you have a family called f that uses gallon as its base and knows about barrel, kilderkin, and firkin. To convert one firkin to gallons, use the following command:
>>> f.convert(1, 'firkin', 'gallon')
(Decimal("9.00"), 'gallon')
And to find the best way to express 3 kilderkin, use the autoconvert method:
>>> f.autoconvert(3, 'kilderkin')
(Decimal("1.50"), 'barrel')
To convert between family f and family liter, you'll need to add f to your UnitManager instance and tell Firkin how much liters (the base unit of family liter) a gallon (the base unit of family f) is. Here's an example:
>>> um.add(f, other='liter', factor=4.54609)
Now you can convert between firkin and gallon:
>>> um.convert_to_unit(1, 'firkin', 'gallon')
(Decimal("9.00"), 'gallon')
Or between firkin and liters:
>>> um.convert_to_unit(1, 'firkin', 'l')
(Decimal("40.9148100"), 'l')
You can even find the best way to express one liter in one of the units from family f:
>>> um.convert_to_family(1, 'l', 'f')
(Decimal("0.219969248299"), 'gallon')
This works with barrels
Version 0.02: N/A