Percentify — a tiny Python helper that turns "part of a whole" into a clean percentage.
Stop typing (part / whole) * 100 and worrying about division by zero.
Percentify gives you a single function:
- Calculates what percentage one number is of another.
- Handles divide-by-zero safely (returns 0.0 instead of crashing).
- Lets you choose how many decimal places to round to.
- Has zero dependencies — just pure Python.
pip install percentify
from percentify import percent
# Basic usage
percent(50, 200) # → 25.0
# Handles fractions
percent(1, 3) # → 33.33
# Safe when dividing by zero
percent(5, 0) # → 0.0
# Custom decimals
percent(7, 9, 4) # → 77.7778
The library is intentionally simple;
def percent(part: float, whole: float, decimals: int = 2) -> float:
if whole == 0:
return 0.0
return round((part / whole) * 100, decimals)
That’s it. Clean, safe, and ready to use anywhere you need percentages in your code.
Contributions are welcome!
- If you have an idea (extra helpers, bug fixes or an idea):
- Fork this repo
- Create a branch
- Commit your changes
- Open a pull request
I try to keep it tiny on purpose, to discuss big new features first.