A simple utility to convert values between different units
Project description
punits
A simple utility to convert values between different units.
Installation
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]
or
>>> punits.punits('length', 'px', 'mm', [235, 123.2], {'dpi': 200})
[29.844999999999995, 15.646400000000002]
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file punits-0.2.tar.gz
.
File metadata
- Download URL: punits-0.2.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7483ef7a900b003e16c1f06e84f3150f97c97cdfef8de4aee83b7723457c66e |
|
MD5 | 05aa72ca1f09fa730519289efcd546a1 |
|
BLAKE2b-256 | b32696c1242659b9338af7e13cba47b7418b8237d7f46b49e489d581f0a80dbc |
File details
Details for the file punits-0.2-py3-none-any.whl
.
File metadata
- Download URL: punits-0.2-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9d348b2201e40837d7b885a129e2899b1b43afba4cf64355229a4889094a575 |
|
MD5 | 5b30488d52e8706718bc0d8cc05aebb8 |
|
BLAKE2b-256 | 17f6ab99c7fcb0180f017f36642a6b900a2958d03faec375334607e9e7f77afb |