Skip to main content

downloads build status coverage rtd status pypi version anaconda version python version

Author: Ken Kundert
Version: 2.23
Released: 2026-09-07

What?

QuantiPhy is a Python library that offers support for physical quantities. A quantity is the pairing of a number and a unit of measure that indicates the amount of some measurable thing. QuantiPhy provides quantity objects that keep the units with the number, making it easy to share them as single object. They subclass float and so can be used anywhere a real number is appropriate.

Why?

QuantiPhy naturally supports SI scale factors, which are widely used in science and engineering. SI scale factors make it possible to cleanly represent both very large and very small quantities in a form that is both easy to read and write. While generally better for humans, no general programming language provides direct support for reading or writing quantities with SI scale factors, making it difficult to write numerical software that communicates effectively with people. QuantiPhy addresses this deficiency, making it natural and simple to both input and output physical quantities.

Features

  • Flexibly reads amounts with units and SI scale factors.

  • Quantities subclass the float class and so can be used as conventional numbers.

  • Generally includes the units when printing or converting to strings and by default employs SI scale factors.

  • Flexible unit conversion and scaling is supported to make it easy to convert to or from any required form.

  • Supports the binary scale factors (Ki, Mi, etc.) along with the normal SI scale factors (k, M, etc.).

  • When a quantity is created from a string, the actual digits specified can be used in any output, eliminating any loss of precision.

Alternatives

There are a considerable number of Python packages dedicated to units and quantities (alternatives). However, as a rule, they focus on the units rather than the scale factors. In particular, they build a system of units that you are expected to use throughout your calculations. These packages demand a high level of commitment from their users and in turn provide unit consistency and built-in unit conversions.

In contrast, QuantiPhy treats units basically as documentation. They are simply strings that are attached to quantities largely so they can be presented to the user when the values are printed. As such, QuantiPhy is a light-weight package that demands little from the user. It is used when inputting and outputting values, and then only when it provides value. As a result, it provides a simplicity in use that cannot be matched by the other packages.

In addition, these alternative packages generally build their unit systems upon the SI base units, which tends to restrict usage to physical quantities with static conversion factors. They are less suited to non-physical quantities or conversion factors that change dynamically, such as with currencies. QuantiPhy gracefully handles all of these cases.

Quick Start

You can find the documentation on ReadTheDocs. Install with:

pip3 install quantiphy

Requires Python 3.6 or newer. If you using an earlier version of Python, install version 2.10 of QuantiPhy.

You can find the full documentation here.

You use Quantity to convert numbers and units in various forms to quantities:

>>> from quantiphy import Quantity

>>> Tclk = Quantity(10e-9, 's')
>>> print(Tclk)
10 ns

>>> Fhy = Quantity('1420.405751786 MHz')
>>> print(Fhy)
1.4204 GHz

>>> Rsense = Quantity('1e-4Ω')
>>> print(Rsense)
100 uΩ

>>> cost = Quantity('$11_200_000')
>>> print(cost)
$11.2M

>>> Tboil = Quantity('212 °F', scale='°C')
>>> print(Tboil)
100 °C

Once you have a quantity, there are a variety of ways of accessing aspects of the quantity:

>>> Tclk.real
1e-08

>>> float(Fhy)
1420405751.786

>>> 2*cost
22400000.0

>>> Rsense.units
'Ω'

>>> str(Tboil)
'100 °C'

You can use the render method to flexibly convert the quantity to a string:

>>> Tclk.render()
'10 ns'

>>> Tclk.render(show_units=False)
'10n'

>>> Tclk.render(form='eng', show_units=False)
'10e-9'

>>> Fhy.render(prec=8)
'1.42040575 GHz'

>>> Tboil.render(scale='°F')
'212 °F'

The fixed method is a variant that specializes in rendering numbers without scale factors or exponents:

>>> cost.fixed(prec=2, show_commas=True, strip_zeros=False)
'$11,200,000.00'

You can use the string format method or the new format strings to flexibly incorporate quantity values into strings:

>>> f'{Fhy}'
'1.4204 GHz'

>>> f'{Fhy:.6}'
'1.420406 GHz'

>>> f'❬{Fhy:<15.6}❭'
'❬1.420406 GHz   ❭'

>>> f'❬{Fhy:>15.6}❭'
'❬   1.420406 GHz❭'

>>> f'{cost:#,.2P}'
'$11,200,000.00'

>>> f'Boiling point of water: {Tboil:s}'
'Boiling point of water: 100 °C'

>>> f'Boiling point of water: {Tboil:s°F}'
'Boiling point of water: 212 °F'

QuantiPhy has many more features and capabilities. For more information, view the documentation.

Metadata

Release files for quantiphy 2.23

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for quantiphy 2.23
File Size Uploaded
quantiphy-2.23.tar.gz 43.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for quantiphy 2.23
File Interpreter ABI Platform
quantiphy-2.23-py3-none-any.whl Python 3 none any Details

Total release size: 87.4 kB

Release files / quantiphy-2.23.tar.gz

Download URL quantiphy-2.23.tar.gz
Size 43.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c883246c28a70a132f85b112e00170b89cbaed9bcd2e01cb52638f6b6b290bad
BLAKE2b-256 checksum
How to use checksums
803f4460c2ffa8a836e7dccba61d8011178b10054d670909e22977303c3d3541
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / quantiphy-2.23-py3-none-any.whl

Download URL quantiphy-2.23-py3-none-any.whl
Size 43.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e6924e1ae0942b96bbb5f41fb73578247fdcb1a22792e1505764b88e39864156
BLAKE2b-256 checksum
How to use checksums
2c7c87ef9a2a7f0b8498cb72ba2a74612ce44996b647b218516c520c23acd66f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release history Release notifications | RSS feed

This release

2.23 This release

2 release files

2.22.1

2 release files

2.22

2 release files

2.21

2 release files

2.20

2 release files

2.19

2 release files

2.16.0

2 release files

2.14.0

2 release files

2.13.0

2 release files

2.12.0

2 release files

2.11.0

1 release file

2.10.0

1 release file

2.9.0

1 release file

2.8.0

1 release file

2.7.0

1 release file

2.6.0

1 release file

2.5.0

1 release file

2.4.0

1 release file

2.3.0

1 release file

2.2.0

1 release file

2.1.0

1 release file

2.0.0

1 release file

1.4.0

1 release file

1.3.0

1 release file

1.2.0

1 release file

1.1.0

1 release file

1.0.0

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.2.0

1 release file

0.0.1

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page