Skip to main content

A zero-dependency Python toolkit for percentages — calculate, compare, format, and distribute.

Project description

% Percentify %

PyPI version Python Versions License Build Status GitHub Stars

Percentify is a Python package 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 is part of whole?
  • change — how much did a value increase or decrease?
  • difference — how far apart are two values?
  • split — split a total into weighted shares.
  • display — 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.

📦 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)

change — Increase or Decrease

from percentify import change

change(100, 150)  # → 50.0   (50% increase)
change(200, 150)  # → -25.0  (25% decrease)
change(0, 100)    # → 0.0    (safe when old is zero)

difference — Difference Between Two Values

from percentify import difference

difference(10, 20)      # → 66.67
difference(50, 50)      # → 0.0

split — Split a Total by Weights

from percentify import split

split(200, [1, 3])       # → [50.0, 150.0]
split(100, [1, 1, 1])    # → [33.33, 33.33, 33.33]

display — Format as a String

from percentify import display

display(25.0)                  # → "25.0%"
display(33.3333, 1)            # → "33.3%"
display(50, suffix=" percent") # → "50.0 percent"

Composing Functions

from percentify import change, display

display(change(100, 20))  # → "-80.0%"

🤝 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 within scope, 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

percentify-0.3.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

percentify-0.3.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file percentify-0.3.0.tar.gz.

File metadata

  • Download URL: percentify-0.3.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.8

File hashes

Hashes for percentify-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b527d9879f9f15879497abd1b4979b7b21fd1983901bd58a8f34f39926889504
MD5 170783eb0dbb54a84038f7b3765c2cc9
BLAKE2b-256 edae8b0ba3ac2a15f058879a2d05331099c1eddfa253ce2ae0b17e17262a1576

See more details on using hashes here.

File details

Details for the file percentify-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: percentify-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.8

File hashes

Hashes for percentify-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 62a15ed58691e663d88979f50a744852c7f39b83fc361e7d4deb1c2763b014ba
MD5 9c06dcd11221ce180b464f55e620ee62
BLAKE2b-256 5d32ba617bef008312a20e69c5f6b78f838de5982d9491ca6fd3e0a1b59d5ddf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page