Written and maintained by CASRAI Editorial Board
Published · Last updated
On this page
scipy.constants is the SciPy module that holds physical and mathematical constants and unit-conversion factors. Its documentation describes it as “Physical and mathematical constants and units”, and in current releases its physical constants come from the 2022 CODATA recommended values. This guide covers what a research workflow needs: reading the uncertainty that comes with each value, finding the exact key, and recording which constants set you used.
What scipy.constants is used for in research
Analysis code often needs the speed of light, Planck’s constant or the gravitational constant, plus conversion factors such as electron volts to joules or degrees to radians. Typing these in by hand invites transcription errors and leaves no record of where the number came from. scipy.constants supplies them in SI units from one maintained source, so the value in your script can be traced to a named CODATA edition.
The module has three parts:
- Named attributes such as
scipy.constants.c(speed of light),scipy.constants.h(Planck constant) andscipy.constants.G(Newtonian constant of gravitation). - The
physical_constantsdatabase, where each entry isphysical_constants[name] = (value, unit, uncertainty). - Unit and prefix constants, for example
kilo(103),milli(10-3),micro(10-6), and binary prefixes such askibi(210) andmebi(220).
Install or access (official source only)
SciPy’s own install page (scipy.org/install) shows the command python -m pip install scipy, and tells you to first create and activate a virtual environment with venv. For new users it also points to project tools such as uv or pixi. The constants module ships with SciPy, so nothing else is needed:
python -m pip install scipy
python -c "from scipy import constants; print(constants.c)"
Pinning the environment matters for results you will publish. See the CASRAI definition of a computational environment and the guide to writing a software management plan.
Step-by-step: look up a constant and read its uncertainty
- Import the module.
from scipy import constants - Find the exact key. Keys in
physical_constantsare descriptive names, not symbols.constants.find("gravitation")returns the list of keys containing that string. In SciPy 1.18.0 it returned['Newtonian constant of gravitation', 'Newtonian constant of gravitation over h-bar c']. - Read the tuple.
constants.physical_constants["Newtonian constant of gravitation"]returned(6.6743e-11, 'm^3 kg^-1 s^-2', 1.5e-15): the value, its unit, and its uncertainty. - Or use the helpers.
constants.value(key),constants.unit(key)andconstants.precision(key)return the value, the unit and the relative precision for the same key. - Use the named attribute when one exists.
constants.creturned299792458.0andconstants.his the Planck constant (the docs list it as 6.62607015e-34 J Hz-1).
A full example, using the key found in step 2:
from scipy import constants
key = "Newtonian constant of gravitation"
value, unit, uncertainty = constants.physical_constants[key]
print(value, unit, uncertainty)
print(constants.precision(key)) # relative precision
Output and how to read it
The third element of each tuple is an absolute uncertainty in the same unit as the value. The SciPy documentation states that exact CODATA values are listed with an uncertainty of 0.0. That is visible in practice: the speed of light entry returned (299792458.0, 'm s^-1', 0.0), while the gravitational constant carries a non-zero uncertainty of 1.5e-15 (same unit as its value). precision(key) is different: it returns the relative precision, which for the gravitational constant came out near 2.2e-05.
| Call | What it returns | Result in SciPy 1.18.0 |
|---|---|---|
physical_constants[key] |
(value, unit, uncertainty) | (6.6743e-11, 'm^3 kg^-1 s^-2', 1.5e-15) for the gravitational constant |
constants.value(key) |
the value | 6.6743e-11 |
constants.unit(key) |
the unit string | m^3 kg^-1 s^-2 |
constants.precision(key) |
relative precision | about 2.2e-05 |
constants.find("gravitation") |
list of keys containing the string | two keys (see step 2) |
Unit conversion constants
The unit constants are expressed in SI. The documentation describes eV as one electron volt in joules, degree as a degree in radians, inch as one inch in metres and hour as one hour in seconds. In SciPy 1.18.0 these returned 1.602176634e-19, 0.017453292519943295, 0.0254 and 3600.0. So energy_in_joules = energy_in_ev * constants.eV.
Temperature
constants.convert_temperature(val, old_scale, new_scale) converts among the Celsius, Kelvin, Fahrenheit and Rankine scales. convert_temperature(100, 'Celsius', 'Kelvin') returned 373.15.
Which CODATA edition are you using?
The current SciPy reference states that the constants database contains the 2022 CODATA recommended values, and the NIST page of fundamental physical constants presents the 2022 CODATA values (NIST notes the next scheduled adjustment is the 2026 CODATA). Older SciPy documentation, such as the 1.4 and 1.5 releases, describes the 2018 CODATA values. A constant that is not an exact definition can therefore differ between SciPy versions. For any published calculation:
- record the SciPy version (
scipy.__version__) in your methods or software management plan; - record the exact key string or attribute name you used;
- re-run results after a major upgrade and compare, as part of computational reproducibility practice.
Troubleshooting
A lookup by name fails
Keys are full descriptive names, for example “Newtonian constant of gravitation”, not “G”. If a key you typed from memory does not work, run constants.find("part of the name") and copy the exact key from the list. In SciPy 1.18.0 a missing key raised KeyError when indexing physical_constants.
A ConstantWarning appears
SciPy documents ConstantWarning as the warning for accessing a constant that is no longer in the current CODATA data set. Treat it as a signal that the constant is no longer in the current CODATA set, and check the NIST CODATA listing before relying on it.
Results differ from an older paper or script
Compare the CODATA edition of the SciPy version used for each run (see the section above). A different CODATA edition is one possible cause, so check it before debugging your own code.
Import errors
Confirm SciPy is installed in the active environment with python -m pip show scipy, and that you created and activated the virtual environment before installing.
Free alternatives
| Option | What it gives you | Source |
|---|---|---|
astropy.constants |
Constants as Quantity objects with provenance and uncertainty metadata. Its documented examples show “Reference = CODATA 2022”, and older editions (codata2010, codata2014, codata2018) can be selected. Written for astronomy. |
docs.astropy.org/en/stable/constants/ |
| NIST CODATA values | The internationally recommended 2022 values of the fundamental physical constants, as a reference list to check a SciPy value against. | physics.nist.gov/cuu/Constants/ |
Frequently asked questions
What is scipy.constants?
It is the SciPy module of physical and mathematical constants and units. Current documentation says its physical constants are based on the 2022 CODATA recommended values.
How do I find the value of a physical constant in SciPy?
Use constants.find("keyword") to get the exact key, then constants.physical_constants[key] for the (value, unit, uncertainty) tuple, or constants.value(key).
What does an uncertainty of 0.0 mean?
The documentation states that exact CODATA values have an uncertainty of 0.0. The speed of light entry is an example.
Are SciPy constants in SI units?
The unit constants are given in SI (eV in joules, inch in metres, hour in seconds, degree in radians), and the physical_constants entries carry a unit string such as m^3 kg^-1 s^-2.
Which related SciPy tasks have their own guides?
See scipy.integrate.quad, SciPy least_squares and SciPy sparse matrices.
Sources (official documentation)
- SciPy reference, Constants (scipy.constants), checked 2026-10-29.
- SciPy, Installing SciPy, checked 2026-10-29.
- NIST, Fundamental Physical Constants (CODATA 2022), checked 2026-10-29.
- Astropy documentation, astropy.constants, checked 2026-10-29.
- Example outputs in this guide were produced with SciPy 1.18.0 on 2026-10-29.







