DimPy - Units for Sage


The DimPy package for Sage allows computations with units to be performed, with all the necessary checks and conversions handled in the background. It can also be used together with the SageTeX package which allows Sage code to be written directly inside LaTeX documents.

Besides scalar quantities like ‘1 m’ or ‘2 s’, DimPy supports vectors and matrices containing physical quantities, and they do not have to have the same units for all components.

As of version 0.2.3, DimPy includes a module that allows quantities and functions of quantities to be plotted.

Source code and installation

The source code can be downloaded from this page. There is also a SourceForge page for DimPy.

Extract the source code and put it into a folder called dimpy in SAGE_ROOT/devel/sage/build/sage/, then it can be loaded from within Sage using from sage.dimpy import *. (SAGE_ROOT stands for the root directory of Sage on your system.)

See the Tutorial for an introduction to the most important features or the Reference Manual for in-depth information.


The code and documentation on this website were created during a summer project 2009 in the Inference Group at the Cavendish Laboratories, Cambridge.

It is based on the work of David Bate in 2008, who created DimPy 0.1.

Contact: Miriam Backens (m.backens at googlemail dot com)

Change log

  • 28 Aug 2009 (v0.2.3):
    • added new module plot
    • enabled integer arithmetic
    • fixed minus sign problem in set_preferred_product()
    • fixed bug in BaseUnitSet
    • rewrote _latex_() methods to use \mathrm{} rather than \text{}
  • 20 Aug 2009 (v0.2.2):
    • added support for engineering notation in LaTeX mode
    • added some more constants
    • added long names for physical constants (that won’t be overwritten as easily as the short ones)
    • implemented SI prefixes (long names only)
  • 17 Aug 2009 (v0.2.1):
    • extended documentation significantly
    • some minor changes to the code
  • 12 Aug 2009:
    • fixed bug in dimension checking for trig functions
    • updated tutorial to include examples of dimension checking