A tiny, zero-dependency Python toolkit for percentages — calculate, compare, format, and distribute.
Project description
% Percentify %
Percentify is a Python helper that turns "part of a whole" into a clean percentage.
Stop typing (part / whole) * 100 and worrying about division by zero.
✨ What It Does
A zero-dependency Python toolkit for all things percentages:
percent— what percentage ispartofwhole?percent_change— how much did a value increase or decrease?percent_diff— how far apart are two values?percent_distribute— split a total into weighted shares.percent_format— turn any number into a clean"25.0%"string.
All functions handle edge cases (division by zero, negative values) safely and let you control decimal precision.
- 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 you want to round your answer to.
- Has zero dependencies — just pure Python.
📦 Installation
pip install percentify
Usage
percent — Part of a Whole
from percentify import percent
percent(50, 200) # → 25.0
percent(1, 3) # → 33.33
percent(5, 0) # → 0.0 (safe division by zero)
percent(7, 9, 4) # → 77.7778 (custom decimals)
percent_change — Increase or Decrease
from percentify import percent_change
percent_change(100, 150) # → 50.0 (50% increase)
percent_change(200, 150) # → -25.0 (25% decrease)
percent_change(0, 100) # → 0.0 (safe when old is zero)
percent_diff — Difference Between Two Values
from percentify import percent_diff
percent_diff(10, 20) # → 66.67
percent_diff(50, 50) # → 0.0
percent_distribute — Split a Total by Weights
from percentify import percent_distribute
percent_distribute(200, [1, 3]) # → [50.0, 150.0]
percent_distribute(100, [1, 1, 1]) # → [33.33, 33.33, 33.33]
percent_format — Format as a String
from percentify import percent_format
percent_format(25.0) # → "25.0%"
percent_format(33.3333, 1) # → "33.3%"
percent_format(50, suffix=" percent") # → "50.0 percent"
🤝 Contributing
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.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file percentify-0.2.1.tar.gz.
File metadata
- Download URL: percentify-0.2.1.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b5119e906b429c3e35faefd00d3a61e479a805c131ac174cf483d8e8aa1b8df
|
|
| MD5 |
9b4ab491e2a3654d6390f711956c47e7
|
|
| BLAKE2b-256 |
999c5a28a02566a3bc6e873d10e8c355323da4596d4c8aff12a7d5b300492993
|
File details
Details for the file percentify-0.2.1-py3-none-any.whl.
File metadata
- Download URL: percentify-0.2.1-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f318eb019b3692b59978b1ba58db274502b4526df7e7bdf21c64c01739cddc9e
|
|
| MD5 |
71197fdeea786517cbe5bad59cc2d5da
|
|
| BLAKE2b-256 |
3495dea5aca3e3932c76fb4198af71b1f18dee48d25aa0943d4982b43881931d
|