quantiphy


Namequantiphy JSON
Version 2.20 PyPI version JSON
download
home_pageNone
Summaryphysical quantities (numbers with units)
upload_time2024-04-27 23:21:07
maintainerNone
docs_urlNone
authorKen Kundert
requires_python>=3.6
licenseNone
keywords quantities physical quantity units si scale factors engineering notation mks cgs
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage
            QuantiPhy — Physical Quantities
===============================

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

| Author: Ken Kundert
| Version: 2.20
| Released: 2024-04-27
|


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 <https://kdavies4.github.io/natu/seealso.html>`_).  
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 <https://en.wikipedia.org/wiki/SI_base_unit>`_, 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
<https://quantiphy.readthedocs.io>`_.  Install with::

   pip3 install --user 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 <https://quantiphy.readthedocs.io>`_.

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

.. code-block:: python

   >>> 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:

.. code-block:: python

   >>> 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:

.. code-block:: python

   >>> 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:

.. code-block:: python

   >>> 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:

.. code-block:: python

   >>> 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 <https://quantiphy.readthedocs.io>`_.


.. |downloads| image:: https://pepy.tech/badge/quantiphy/month
    :target: https://pepy.tech/project/quantiphy

.. |rtd status| image:: https://img.shields.io/readthedocs/quantiphy.svg
   :target: https://quantiphy.readthedocs.io/en/latest/?badge=latest

.. |build status| image:: https://github.com/KenKundert/quantiphy/actions/workflows/build.yaml/badge.svg
    :target: https://github.com/KenKundert/quantiphy/actions/workflows/build.yaml

.. |coverage| image:: https://coveralls.io/repos/github/KenKundert/quantiphy/badge.svg?branch=master
    :target: https://coveralls.io/github/KenKundert/quantiphy?branch=master

.. |pypi version| image:: https://img.shields.io/pypi/v/quantiphy.svg
    :target: https://pypi.python.org/pypi/quantiphy

.. |anaconda version| image:: https://anaconda.org/conda-forge/quantiphy/badges/version.svg
    :target: https://anaconda.org/conda-forge/quantiphy

.. |python version| image:: https://img.shields.io/pypi/pyversions/quantiphy.svg
    :target: https://pypi.python.org/pypi/quantiphy/



            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "quantiphy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "quantities, physical quantity, units, SI scale factors, engineering notation, mks, cgs",
    "author": "Ken Kundert",
    "author_email": "quantiphy@nurdletech.com",
    "download_url": "https://files.pythonhosted.org/packages/92/dc/dec6a98d5ef472812848c1141630f819bfaf2e469f3733083ded2f3b08aa/quantiphy-2.20.tar.gz",
    "platform": null,
    "description": "QuantiPhy \u2014 Physical Quantities\n===============================\n\n|downloads| |build status| |coverage| |rtd status| |pypi version| |anaconda version| |python version|\n\n| Author: Ken Kundert\n| Version: 2.20\n| Released: 2024-04-27\n|\n\n\nWhat?\n-----\n\n*QuantiPhy* is a Python library that offers support for physical quantities.  \nA quantity is the pairing of a number and a unit of measure that indicates the \namount of some measurable thing.  *QuantiPhy* provides quantity objects that \nkeep the units with the number, making it easy to share them as single object.  \nThey subclass float and so can be used anywhere a real number is appropriate.\n\n\nWhy?\n----\n\n*QuantiPhy* naturally supports SI scale factors, which are widely used in \nscience and engineering. SI scale factors make it possible to cleanly represent \nboth very large and very small quantities in a form that is both easy to read \nand write.  While generally better for humans, no general programming language \nprovides direct support for reading or writing quantities with SI scale factors, \nmaking it difficult to write numerical software that communicates effectively \nwith people.  *QuantiPhy* addresses this deficiency, making it natural and \nsimple to both input and output physical quantities.\n\n\nFeatures\n--------\n\n- Flexibly reads amounts with units and SI scale factors.\n- Quantities subclass the *float* class and so can be used as conventional \n  numbers.\n- Generally includes the units when printing or converting to strings and by \n  default employs SI scale factors.\n- Flexible unit conversion and scaling is supported to make it easy to convert \n  to or from any required form.\n- Supports the binary scale factors (*Ki*, *Mi*, etc.) along with the normal SI \n  scale factors (*k*, *M*, etc.).\n- When a quantity is created from a string, the actual digits specified can be \n  used in any output, eliminating any loss of precision.\n\n\nAlternatives\n------------\n\nThere are a considerable number of Python packages dedicated to units and \nquantities (`alternatives <https://kdavies4.github.io/natu/seealso.html>`_).  \nHowever, as a rule, they focus on the units rather than the scale factors. In \nparticular, they build a system of units that you are expected to use throughout \nyour calculations.  These packages demand a high level of commitment from their \nusers and in turn provide unit consistency and built-in unit conversions.\n\nIn contrast, *QuantiPhy* treats units basically as documentation.  They are \nsimply strings that are attached to quantities largely so they can be presented \nto the user when the values are printed. As such, *QuantiPhy* is a light-weight \npackage that demands little from the user.  It is used when inputting and \noutputting values, and then only when it provides value.  As a result, it \nprovides a simplicity in use that cannot be matched by the other packages.\n\nIn addition, these alternative packages generally build their unit systems upon \nthe `SI base units <https://en.wikipedia.org/wiki/SI_base_unit>`_, which tends \nto restrict usage to physical quantities with static conversion factors.  They \nare less suited to non-physical quantities or conversion factors that change \ndynamically, such as with currencies.  *QuantiPhy* gracefully handles all of \nthese cases.\n\n\nQuick Start\n-----------\n\nYou can find the documentation on `ReadTheDocs\n<https://quantiphy.readthedocs.io>`_.  Install with::\n\n   pip3 install --user quantiphy\n\nRequires Python 3.6 or newer.  If you using an earlier version of Python,\ninstall version 2.10 of *QuantiPhy*.\n\nYou can find the full documentation `here <https://quantiphy.readthedocs.io>`_.\n\nYou use *Quantity* to convert numbers and units in various forms to quantities:\n\n.. code-block:: python\n\n   >>> from quantiphy import Quantity\n\n   >>> Tclk = Quantity(10e-9, 's')\n   >>> print(Tclk)\n   10 ns\n\n   >>> Fhy = Quantity('1420.405751786 MHz')\n   >>> print(Fhy)\n   1.4204 GHz\n\n   >>> Rsense = Quantity('1e-4\u03a9')\n   >>> print(Rsense)\n   100 u\u03a9\n\n   >>> cost = Quantity('$11_200_000')\n   >>> print(cost)\n   $11.2M\n\n   >>> Tboil = Quantity('212 \u00b0F', scale='\u00b0C')\n   >>> print(Tboil)\n   100 \u00b0C\n\nOnce you have a quantity, there are a variety of ways of accessing aspects of \nthe quantity:\n\n.. code-block:: python\n\n   >>> Tclk.real\n   1e-08\n\n   >>> float(Fhy)\n   1420405751.786\n\n   >>> 2*cost\n   22400000.0\n\n   >>> Rsense.units\n   '\u03a9'\n\n   >>> str(Tboil)\n   '100 \u00b0C'\n\nYou can use the *render* method to flexibly convert the quantity to a string:\n\n.. code-block:: python\n\n   >>> Tclk.render()\n   '10 ns'\n\n   >>> Tclk.render(show_units=False)\n   '10n'\n\n   >>> Tclk.render(form='eng', show_units=False)\n   '10e-9'\n\n   >>> Fhy.render(prec=8)\n   '1.42040575 GHz'\n\n   >>> Tboil.render(scale='\u00b0F')\n   '212 \u00b0F'\n\nThe *fixed* method is a variant that specializes in rendering numbers without \nscale factors or exponents:\n\n.. code-block:: python\n\n   >>> cost.fixed(prec=2, show_commas=True, strip_zeros=False)\n   '$11,200,000.00'\n\nYou can use the string format method or the new format strings to flexibly \nincorporate quantity values into strings:\n\n.. code-block:: python\n\n   >>> f'{Fhy}'\n   '1.4204 GHz'\n\n   >>> f'{Fhy:.6}'\n   '1.420406 GHz'\n\n   >>> f'\u276c{Fhy:<15.6}\u276d'\n   '\u276c1.420406 GHz   \u276d'\n\n   >>> f'\u276c{Fhy:>15.6}\u276d'\n   '\u276c   1.420406 GHz\u276d'\n\n   >>> f'{cost:#,.2P}'\n   '$11,200,000.00'\n\n   >>> f'Boiling point of water: {Tboil:s}'\n   'Boiling point of water: 100 \u00b0C'\n\n   >>> f'Boiling point of water: {Tboil:s\u00b0F}'\n   'Boiling point of water: 212 \u00b0F'\n\n*QuantiPhy* has many more features and capabilities. For more information, view \nthe `documentation <https://quantiphy.readthedocs.io>`_.\n\n\n.. |downloads| image:: https://pepy.tech/badge/quantiphy/month\n    :target: https://pepy.tech/project/quantiphy\n\n.. |rtd status| image:: https://img.shields.io/readthedocs/quantiphy.svg\n   :target: https://quantiphy.readthedocs.io/en/latest/?badge=latest\n\n.. |build status| image:: https://github.com/KenKundert/quantiphy/actions/workflows/build.yaml/badge.svg\n    :target: https://github.com/KenKundert/quantiphy/actions/workflows/build.yaml\n\n.. |coverage| image:: https://coveralls.io/repos/github/KenKundert/quantiphy/badge.svg?branch=master\n    :target: https://coveralls.io/github/KenKundert/quantiphy?branch=master\n\n.. |pypi version| image:: https://img.shields.io/pypi/v/quantiphy.svg\n    :target: https://pypi.python.org/pypi/quantiphy\n\n.. |anaconda version| image:: https://anaconda.org/conda-forge/quantiphy/badges/version.svg\n    :target: https://anaconda.org/conda-forge/quantiphy\n\n.. |python version| image:: https://img.shields.io/pypi/pyversions/quantiphy.svg\n    :target: https://pypi.python.org/pypi/quantiphy/\n\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "physical quantities (numbers with units)",
    "version": "2.20",
    "project_urls": {
        "changelog": "https://github.com/KenKundert/quantiphy/blob/master/doc/releases.rst",
        "documentation": "https://quantiphy.readthedocs.io",
        "homepage": "https://quantiphy.readthedocs.io",
        "repository": "https://github.com/kenkundert/quantiphy"
    },
    "split_keywords": [
        "quantities",
        " physical quantity",
        " units",
        " si scale factors",
        " engineering notation",
        " mks",
        " cgs"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "379142c59c137bf3d82a6525f3200f23ea6cad81f53828f96e187a519cdf34c3",
                "md5": "c664caeccf9a537ad1652c9b217f91b3",
                "sha256": "afdf5f9d1cc87359bd7daf19dc1cb23808eb2e264d9395b36ca6527fb4d71b3a"
            },
            "downloads": -1,
            "filename": "quantiphy-2.20-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c664caeccf9a537ad1652c9b217f91b3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 41254,
            "upload_time": "2024-04-27T23:21:05",
            "upload_time_iso_8601": "2024-04-27T23:21:05.194539Z",
            "url": "https://files.pythonhosted.org/packages/37/91/42c59c137bf3d82a6525f3200f23ea6cad81f53828f96e187a519cdf34c3/quantiphy-2.20-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "92dcdec6a98d5ef472812848c1141630f819bfaf2e469f3733083ded2f3b08aa",
                "md5": "66ca1565ea7a5422b34240c2a646174c",
                "sha256": "ba5375ac55c3b90077a793588dd5a88aaf81b2c3b0fc9c9359513ac39f6ed84d"
            },
            "downloads": -1,
            "filename": "quantiphy-2.20.tar.gz",
            "has_sig": false,
            "md5_digest": "66ca1565ea7a5422b34240c2a646174c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 42073,
            "upload_time": "2024-04-27T23:21:07",
            "upload_time_iso_8601": "2024-04-27T23:21:07.223462Z",
            "url": "https://files.pythonhosted.org/packages/92/dc/dec6a98d5ef472812848c1141630f819bfaf2e469f3733083ded2f3b08aa/quantiphy-2.20.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-27 23:21:07",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "KenKundert",
    "github_project": "quantiphy",
    "travis_ci": true,
    "coveralls": true,
    "github_actions": true,
    "tox": true,
    "lcname": "quantiphy"
}
        
Elapsed time: 1.61794s