Skip to main content

A simple utility to convert values between different units

Project description


PyPI Build Status License: MIT

A simple utility to convert values between different units.


You need Python>=3.6 to use punits.

It can be installed from PyPI with pip using

pip install punits

Command line usage

python3 -m punits <choice> <source-unit> <target-unit> <value-list>

where choice is the kind of units. Allowed values for are:

  • mass
  • length
  • volume
  • data
  • temperature.

For example, you can use

python3 -m punits mass lb kg 23 46.2 12.46

to get

10.43 20.96 5.65

Use python3 -m punits --help for more information.

Usage as module

The punits() function can be used.

Its signature is:

def punits(measure: str,
           src_unit: str,
           target_unit: str,
           values: List[float],
           params: Optional[dict] = None) -> List[float]

where the params argument can be used to pass additional parameters that may be needed (like dpi value when conversion is from or to pixesl).

For example,

>>> punits.punits('temperature', 'K', 'C', [235, 123.2])
[-38.14999999999998, -149.95]


>>> punits.punits('length', 'px', 'mm', [235, 123.2], {'dpi': 200})
[29.844999999999995, 15.646400000000002]

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

punits-0.2.tar.gz (8.9 kB view hashes)

Uploaded Source

Built Distribution

punits-0.2-py3-none-any.whl (11.4 kB view hashes)

Uploaded Python 3

Supported by

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