Skip to main content

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

Project description

% Percentify %

PyPI Downloads PyPI version Python Versions License Build Status

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.


✨ What It Does

A tiny, zero-dependency Python toolkit for all things percentages:

  • percent — what percentage is part of whole?
  • 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.

📦 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

percentify-0.2.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.2.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: percentify-0.2.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.2.0.tar.gz
Algorithm Hash digest
SHA256 26f6627514ad69e0ccb0a8e5e4910c20307791a9b01bf57aa91ad580d642e9c2
MD5 44d779b578d6bbde8762940c793f5a22
BLAKE2b-256 b1f6f1bbca9ac15b1419e5d3d1689b60426a33416c47ea7f191648daa1e16255

See more details on using hashes here.

File details

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

File metadata

  • Download URL: percentify-0.2.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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dfb28bcd1399f8c91764fcf38516b285f69f1f4c81e2e800af2c9e655a4beeb7
MD5 0a0c0abd53a599617dcfe2d0d4243e2a
BLAKE2b-256 984816387ff18d0fe34e902816277d532137340074240e915a9d9a1a9c7630f6

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