This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Pint: makes units easy

Pint is a Python package to define, operate and manipulate physical quantities: the product of a numerical value and a unit of measurement. It allows arithmetic operations between them and conversions from and to different units.

It is distributed with a comprehensive list of physical units, prefixes and constants. Due to its modular design, you can extend (or even rewrite!) the complete list without changing the source code. It supports a lot of numpy mathematical operations without monkey patching or wrapping numpy.

It has a complete test coverage. It runs in Python 2.6 and 3.X with no other dependency. It is licensed under BSD.

It is extremely easy and natural to use:

>>> import pint
>>> ureg = pint.UnitRegistry()
>>> 3 * ureg.meter + 4 * ureg.cm
<Quantity(3.04, 'meter')>

and you can make good use of numpy if you want:

>>> import numpy as np
>>> [3, 4] * ureg.meter + [4, 3] * ureg.cm
<Quantity([ 3.04  4.03], 'meter')>
>>> np.sum(_)
<Quantity(7.07, 'meter')>

Quick Installation

To install Pint, simply:

$ pip install pint

and then simply enjoy it!

Documentation

Full documentation is available at http://pint.readthedocs.org/

Design principles

Although there are already a few very good Python packages to handle physical quantities, no one was really fitting my needs. Like most developers, I programed Pint to scratch my own itches.

  • Unit parsing: prefixed and pluralized forms of units are recognized without explicitly defining them. In other words: as the prefix kilo and the unit meter are defined, Pint understands kilometers. This results in a much shorter and maintainable unit definition list as compared to other packages.
  • Standalone unit definitions: units definitions are loaded from simple and easy to edit text file. Adding and changing units and their definitions does not involve changing the code.
  • Advanced string formatting: a quantity can be formatted into string using PEP 3101 syntax. Extended conversion flags are given to provide latex and pretty formatting.
  • Small codebase: small and easy to maintain with a flat hierarchy.
  • Dependency free: it depends only on Python and its standard library.
  • Python 2 and 3: A single codebase that runs unchanged in Python 2.6+ and Python 3.0+.
  • Advanced NumPy support: While NumPy is not a requirement for Pint, when available ndarray methods and ufuncs can be used in Quantity objects.

Pint is written and maintained by Hernan E. Grecco <hernan.grecco@gmail.com>.

Other contributors, listed alphabetically, are:

(If you think that your name belongs here, please let the maintainer know)

Pint Changelog

0.7.2 (2016-03-02)

  • Fixed backward incompatibility problem when parsing dimensionless units.

0.7.1 (2016-02-23)

  • Use NIST as source for most of the unit information.
  • Added message to assertQuantityEqual.
  • Added detection of circular dependencies in definitions.

0.7 (2016-02-20)

  • Added Systems and groups. (Issue #215, #315)
  • Implemented references for wraps decorator. (Issue #195)
  • Added check decorator to UnitRegistry. (Issue #283, thanks kaidokert)
  • Added compact conversion. (See #224, thanks Ryan Dwyer)
  • Added compact formating code. (Issue #240)
  • New Unit Class. (thanks Matthieu Dartiailh)
  • Refactor UnitRegistry. (thanks Matthieu Dartiailh)
  • Move definitions, errors, and converters into their own modules. (thanks Matthieu Dartiailh)
  • UnitsContainer is now immutable (Issue #202, thanks Matthieu Dartiailh)
  • New parser and evaluator. (Issue #226, thanks Aaron Coleman)
  • Added support for Unicode identifiers.
  • Added m_as as way top retrieve the magnitude in different units. (Issue #227)
  • Added Short form for magnitude and units. (Issue #234)
  • Improved deepcopy. (Issue #252, thanks Emilien Kofman)
  • Improved testing infrastructure.
  • Improved docs. (thanks Ryan Dwyer, Martin Thoma, Andrea Zonca)
  • Fixed short names on electron_volt and hartree.
  • Fixed definitions of scruple and drachm. (Issue #262, thanks takowl)
  • Fixed troy ounce to 480 ‘grains’. (thanks elifab)
  • Added ‘quad’ as a unit of energy (= 10**15 Btu). (thanks Ed Schofield)
  • Added “hectare” as a supported unit of area and ‘ha’ as the symbol for hectare. (thanks Ed Schofield)
  • Added peak sun hour and Langley. (thanks Ed Schofield)
  • Added photometric units: lumen & lux. (Issue #230, thanks janpipek)
  • A fraction magnitude quantity is conserved (Issue #323, thanks emilienkofman)
  • Improved conversion performance by removing unnecessart try/except. (Issue #251)
  • Added to_tuple and from_tuple to facilitate serialization.
  • Fixed support for NumPy 1.10 due to a change in the Default casting rule (Issue #320)
  • Infrastructure: Added doctesting.
  • Infrastructure: Better way to specify exclude matrix in travis.

0.6 (2014-11-07)

  • Fix operations with measurments and user defined units. (Issue #204)
  • Faster conversions through caching and other performance improvements. (Issue #193, thanks MatthieuDartiailh)
  • Better error messages on Quantity.__setitem__. (Issue #191)
  • Fixed abbreviation of fluid_ounce. (Issue #187, thanks hsoft)
  • Defined Angstrom symbol. (Issue #181, thanks JonasOlson)
  • Removed fetching version from git repo as it triggers XCode installation on OSX. (Issue #178, thanks deanishe)
  • Improved context documentation. (Issue #176 and 179, thanks rsking84)
  • Added Chemistry context. (Issue #179, thanks rsking84)
  • Fix help(UnitRegisty) (Issue #168)
  • Optimized “get_dimensionality” and “get_base_name”. (Issue #166 and #167, thanks jbmohler)
  • Renamed ureg.parse_units parameter “to_delta” to “as_delta” to make clear. that no conversion happens. Accordingly, the parameter/property “default_to_delta” of UnitRegistry was renamed to “default_as_delta”. (Issue #158, thanks dalit)
  • Fixed problem when adding two uncertainties. (thanks dalito)
  • Full support for Offset units (e.g. temperature) (Issue #88, #143, #147 and #161, thanks dalito)

0.5.2 (2014-07-31)

  • Changed travis config to use miniconda for faster testing.
  • Added wheel configuration to setup.cfg.
  • Ensure resource streams are closed after reading.
  • Require setuptools. (Issue #169)
  • Implemented real, imag and T Quantity properties. (Issue #171)
  • Implemented __int__ and __long__ for Quantity (Issue #170)
  • Fixed SI prefix error on ureg.convert. (Issue #156, thanks jdreaver)
  • Fixed parsing of multiparemeter contexts. (Issue #174)

0.5.1 (2014-06-03)

  • Implemented a standard way to change the registry used in unpickling operations. (Issue #148)
  • Fix bug where conversion would fail due to caching. (Issue #140, thanks jdreaver)
  • Allow assigning Not a Number to a quantity array. (Issue #127)
  • Decoupled Quantity in place and not in place unit conversion methods.
  • Return None in functions that modify quantities in place.
  • Improved testing infrastructure to check for unwanted warnings.
  • Added test function at the package level to run all tests.

0.5 (2014-05-07)

  • Improved test suite helper functions.
  • Print honors default format w/o format(). (Issue #132, thanks mankoff)
  • Fixed sum() by treating number zero as a special case. (Issue #122, thanks rec)
  • Improved behaviour in ScaleConverter, OffsetConverter and Quantity.to. (Issue #120)
  • Reimplemented loading of default definitions to allow Pint in a cx_freeze or similar package. (Issue #118, thanks jbmohler)
  • Implemented parsing of pretty printed units. (Issue #117, thanks jpgrayson)
  • Fixed representation of dimensionless quantities. (Issue #112, thanks rec)
  • Raise error when invalid formatting code is given. (Issue #111, thanks rec)
  • Default registry to lazy load, raise error on redefinition (Issue #108, thanks rec, aepsil0n)
  • Added condensed format. (Issue #107, thanks rec)
  • Added UnitRegistry () operator to parse expression replacing []. (Issue #106, thanks rec)
  • Optional case insensitive unit parsing. (Issue #105, thanks rec, jeremyfreeman, dbrnz)
  • Change the Quantity mutability depending on magnitude type. (Issue #104, thanks rec)
  • Implemented API to list compatible units. (Issue #89)
  • Implemented cache of key UnitRegistry methods.
  • Rewrote the Measurement class to use uncertainties. (Issue #24)

0.4.2 (2014-02-14)

  • Python 2.6 support (Issue #96, thanks tiagocoutinho)
  • Fixed symbol for inch. (Issue #102, thanks cybertoast)
  • Stop raising AttributeError when wrapping funcs without all of the attributes. (Issue #100, thanks jturner314)
  • Fixed warning appearing in Py2.x when comparing a Numpy Array with an empty string. (Issue #98, thanks jturner314)
  • Add links to AUR packages in docs. (Issue #91, thanks jturner314)
  • Fixed garbage collection related problem. (Issue #92, thanks jturner314)

0.4.1 (2014-01-12)

  • Integer Division with Arrays. (Issue #80, thanks jdreaver)
  • Improved Documentation. (Issue #83, thanks choloepus)
  • Removed ‘h’ alias for hour due to conflict with Planck’s constant. (Issue #82, thanks choloepus)
  • Improved get_base_units for non-multiplicative units. (Issue #85, thanks exxus)
  • Refactored code for multiplication. (Issue #84, thanks jturner314)
  • Removed ‘R’ alias for roentgen as it collides with molar_gas_constant. (Issue #87, thanks rsking84)
  • Improved naming of temperature units and multiplication of non-multiplicative units. (Issue #86, tahsnk exxus)

0.4 (2013-12-17)

  • Introduced Contexts: relation between incompatible dimensions. (Issue #65)
  • Fixed get_base_units for non multiplicative units. (Related to issue #66)
  • Implemented default formatting for quantities.
  • Changed comparison between Quantities containing NumPy arrays. (Issue #75) - BACKWARDS INCOMPATIBLE CHANGE
  • Fixes for NumPy 1.8 due to changes in handling binary ops. (Issue #73)

0.3.3 (2013-11-29)

  • ParseHelper can now parse units named like python keywords. (Issue #69)
  • Fix comparison of quantities. (Issue #74)
  • Fix Inequality operator. (Issue #70, thanks muggenhor)
  • Improved travis configuration. (thanks muggenhor)

0.3.2 (2013-10-22)

  • Fix get_dimensionality for non multiplicative units. (Issue #66)
  • Proper handling of @import directive inside a file read using pkg_resources. (Issue #68)

0.3.1 (2013-09-15)

  • fix right division on python 2.7 (Issue #58, thanks natezb)
  • fix formatting of fractional exponentials between 0 and 1. (Issue #62, thanks jdreaver)
  • fix installation as egg. (Issue #61)
  • fix handling of strange values as input of Quantity. (Issue #53)
  • math operations between quantities of different registries now raise a ValueError. (Issue #52)

0.3 (2013-09-02)

  • support for IPython autocomplete and rich display. (Issues #30 and #31)
  • support for @import directive in definitions file. (Issue #22)
  • support for wrapping functions to make them pint-aware. (Issue #16)
  • support for comparing UnitsContainer to string. (Issue #35)
  • fix error raised while converting from a single unit to one expressed as the relation between many. (Issue #29)
  • fix error raised when unit symbol is missing. (Issue #41)
  • fix error raised when magnitude is Decimal. (Issue #46, thanks danielsokolowski)
  • support for non-installed pint. (Issue #42, thanks danielsokolowski)
  • support for application of numpy function on non-ndarray magnitudes. (Issue #44)
  • support for math operations on dimensionless Quantities (written with units). (Issue #45)
  • fix obtaining dimensionless quantity from string. (Issue #50)
  • fix adding and comparing numbers to a dimensionless quantity (written with units). (Issue #54)
  • Support for iter in Quantity. (Issue #55, thanks natezb)

0.2.1 (2013-07-02)

  • fix error raised while converting from a single unit to one expressed as the relation between many. (Issue #29)

0.2 (2013-05-13)

  • support for Measurement (Quantity +/- error).
  • implemented buckingham pi theorem for dimensional analysis.
  • support for temperature units and temperature difference units.
  • parser can infers if the user mean temperature or temperature difference.
  • support for derived dimensions (e.g. [speed] = [length] / [time]).
  • refactored the code into multiple files.
  • refactored code to isolate definitions and converters.
  • refactored formatter out of UnitParser class.
  • added tox and travis config files for CI.
  • comprehensive NumPy testing including almost all ufuncs.
  • full NumPy support (features is not longer experimental).
  • fixed bug preventing from having independent registries. (Issue #10, thanks bwanders)
  • forces real division as default for Quantities. (Issue #7, thanks dbrnz)
  • improved default unit definition file. (Issue #13, thanks r-barnes)
  • smarter parser supporting spaces as multiplications and other nice features. (Issue #13, thanks r-barnes)
  • moved testsuite inside package.
  • short forms of binary prefixes, more units and fix to less than comparison. (Issue #20, thanks muggenhor)
  • pint is now zip-safe (Issue #23, thanks muggenhor)

Version 0.1.3 (2013-01-07)

  • abbreviated quantity string formating.
  • complete Python 2.7 compatibility.
  • implemented pickle support for Quantities objects.
  • extended NumPy support.
  • various bugfixes.

Version 0.1.2 (2012-08-12)

  • experimenal NumPy support.
  • included default unit definitions file. (Issue #1, thanks fish2000)
  • better testing.
  • various bugfixes.
  • fixed some units definitions. (Issue #4, thanks craigholm)

Version 0.1.1 (2012-07-31)

  • better packaging and installation.

Version 0.1 (2012-07-26)

  • first public release.
Release History

Release History

0.7.2

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.7.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.7

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.6

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.5.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.5.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.5

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.4.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.4.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.4

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
Pint-0.7.2.tar.gz (149.2 kB) Copy SHA256 Checksum SHA256 Source Mar 2, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting