Python module that provides utilities related to the Body Mass Index (BMI). Also provides a Command Line Interface (CLI).
This library can be used from Python code, imported as a Python module.
- Install it with pip:
pip install body-mass-index
- Although you might consider using
pipenv
, which creates a Pipfile to keep track of your dependencies. In that case, the install command would be:pipenv install body-mass-index
- Then, import this module in your code:
from bmi import Bmi
- Note that the
Bmi
class contains all the utilities of this module
- Now, use it.
- E.g.
Bmi.calculate_bmi(80, 1.80)
- E.g.
- Two static methods:
calculate_bmi
: Calculates BMI, provided weight (kg) and height (m)calculate_weight
: Calculates weight (kg), provided height (m) and BMI
- Several class methods:
calculate_bmi_with_info
: Calculate BMI with range info, provided weight (kg), height (m) and languageget_bmi_range_info
: Return range info, provided BMI and languageget_bmi_ranges_info
: Return info of all rangescalculate_weight_boundaries
: Calculate weight boundaries (kg), based on BMI; provided height (m)calculate_weight_ranges_with_info
: Calculate weight ranges (kg), based on BMI ranges; provided height (m) and languagecalculate_healthy_weight
: Calculate healthy weight range (kg), provided height (m)
- Module provides class attributes:
boundaries
: List with the boundaries for BMI ranges, as defined by the WHOranges_i18n
: Text defining each BMI range, as per the WHO, in English and Spanish
This library can also be used as a CLI utility. And it can be run both with Python or with Docker.
Install it with pip.
Then, you can run the CLI utility in two different ways.
python3 -m bmi [command] [params]
docker run -it romenrg/bmi:0.0.1 [command] [params]
Notes:
- If no command is provided, help will be displayed
- Example providing command with parameters
docker run -it romenrg/bmi:0.0.1 calculate 80 1.80
calculate_bmi
: Calculate BMI, provided weight (kg) and height (m) [info]get_bmi_range_info
: Return range info, provided BMI and languageget_bmi_ranges_info
: Return info of all BMI rangescalculate_weight
: Calculate weight (kg), provided height (m) and BMIcalculate_weight_ranges_info
: Calculate weight ranges (kg), based on BMI ranges; provided height (m)calculate_healthy_weight
: Calculate healthy weight range (kg), provided height (m)
You can also clone the repository in order to build a Docker image, run tests, execute the module locally and/or contribute to keep improving this module.
Python, as an interpreted language, doesn't have to be built, but the Docker image does.
docker build --tag=romenrg/bmi:0.0.1 .
Existing unit tests can be run in two different ways.
python3 -m unittest
docker run -it --entrypoint python3 romenrg/bmi:0.0.1 -m unittest
You can run the CLI from the source code in the same way you can when you installed it. See the Run the CLI section.
Any contributions (i.e. PRs or issues) are welcome. Please feel free to propose changes following the contributing guideline.