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"
display(0.45, multiply=True)          # → "45.0%"

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.1.tar.gz (8.4 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.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: percentify-0.3.1.tar.gz
  • Upload date:
  • Size: 8.4 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.1.tar.gz
Algorithm Hash digest
SHA256 8c1d6921bf80cba2c93f48a824f8317c14cdd282e45959d583ca83d20ec672c3
MD5 484c4d159f0641b66c3982dbe4e925b7
BLAKE2b-256 5ae4c09a012fc3894d8e71fdf957f053b276f726a110956da13b4a041ab81963

See more details on using hashes here.

File details

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

File metadata

  • Download URL: percentify-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 8.3 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1720dd63f00f7023f0c288316b89be2a25eadb04b14997e18b82eff51327ba0c
MD5 9eb3b131490e57430b55adc516ad4f7b
BLAKE2b-256 de2525e4e2fd6463bd50065298e70f11476053198f5c13e02934022b95fe5a04

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