HEP Units and Constants

2.4.4 · active · verified Mon Apr 13

hepunits is a Python library that provides a comprehensive set of units and physical constants specifically tailored for the High Energy Physics (HEP) system of units. It simplifies working with quantities in HEP research by offering well-defined units like MeV and constants such as the speed of light. The library is actively maintained, with regular updates for Python version compatibility and minor feature enhancements, currently at version 2.4.4.

Warnings

Install

Imports

Quickstart

This example demonstrates how to import and use units and physical constants. It also shows the optional integration with the Pint library for more advanced quantity handling, which requires installing `hepunits[pint]`.

from hepunits import units, constants

# Accessing units
energy = 100 * units.GeV
print(f"Energy: {energy}")

# Accessing constants
speed_of_light = constants.c_light
print(f"Speed of light: {speed_of_light} in mm/ns")

# Using Pint integration (requires pip install hepunits[pint])
try:
    import hepunits.pint
    ureg = hepunits.pint.get_unit_registry()
    mass = 938.27 * ureg.MeV / ureg.c**2
    print(f"Proton mass (Pint): {mass}")
except ImportError:
    print("Pint integration not installed. Skipping Pint example.")

view raw JSON →