Constants (astropy.constants)


astropy.constants contains a number of physical constants useful in Astronomy. Constants are Quantity objects with additional meta-data describing their provenance and uncertainties.

Getting Started

To use the constants in S.I. units, you can import the constants directly from the astropy.constants sub-package:

>>> from astropy.constants import G

or, if you want to avoid having to explicitly import all the constants you need, you can simply do:

>>> from astropy import constants as const

and then subsequently use for example const.G. Constants are fully-fledged Quantity objects, so you can easily convert them to different units for example:

>>> print(const.c)
  Name   = Speed of light in vacuum
  Value  = 299792458.0
  Uncertainty  = 0.0
  Unit  = m / s
  Reference = CODATA 2010

>>> print('km/s'))
299792.458 km / s

>>> print('pc/yr'))  
0.306601393788 pc / yr

and you can use them in conjunction with unit and other non-constant Quantity objects:

>>> from astropy import units as u
>>> F = (const.G * 3. * const.M_sun * 100 * / (2.2 * ** 2
>>> print(  
0.367669392028 N

It is possible to convert most constants to cgs using e.g.:

>>> const.c.cgs
<Quantity 29979245800.0 cm / s>

However, some constants are defined with different physical dimensions in cgs and cannot be directly converted. Because of this ambiguity, such constants cannot be used in expressions without specifying a system:

>>> 100 * const.e
Traceback (most recent call last):
TypeError: Constant u'e' does not have physically compatible units
across all systems of units and cannot be combined with other
values without specifying a system (eg. e.emu)
>>> 100 * const.e.esu  
<Quantity 4.8032045057134676e-08 Fr>


astropy.constants Package

Contains astronomical and physical constants for use in Astropy or other places.

A typical use case might be:

>>> from astropy.constants import c, m_e
>>> # ... define the mass of something you want the rest energy of as m ...
>>> m = m_e
>>> E = m * c**2
<Quantity 0.510998927603161 MeV>

The following constants are available:

Name Value Unit Description
G 6.67384e-11 m3 / (kg s2) Gravitational constant
L_bol0 3.0128e+28 W Luminosity for absolute bolometric magnitude 0
L_sun 3.846e+26 W Solar luminosity
M_earth 5.9742e+24 kg Earth mass
M_jup 1.8987e+27 kg Jupiter mass
M_sun 1.9891e+30 kg Solar mass
N_A 6.02214129e+23 1 / (mol) Avogadro’s number
R 8.3144621 J / (K mol) Gas constant
R_earth 6378136 m Earth equatorial radius
R_jup 71492000 m Jupiter equatorial radius
R_sun 695508000 m Solar radius
Ryd 10973731.6 1 / (m) Rydberg constant
a0 5.29177211e-11 m Bohr radius
alpha 0.00729735257   Fine-structure constant
atmosphere 101325 Pa Atmosphere
au 1.49597871e+11 m Astronomical Unit
b_wien 0.0028977721 m K Wien wavelength displacement law constant
c 299792458 m / (s) Speed of light in vacuum
e 1.60217657e-19 C Electron charge
eps0 8.85418782e-12 F/m Electric constant
g0 9.80665 m / s2 Standard acceleration of gravity
h 6.62606957e-34 J s Planck constant
hbar 1.05457173e-34 J s Reduced Planck constant
k_B 1.3806488e-23 J / (K) Boltzmann constant
kpc 3.08567758e+19 m Kiloparsec
m_e 9.10938291e-31 kg Electron mass
m_n 1.67492735e-27 kg Neutron mass
m_p 1.67262178e-27 kg Proton mass
mu0 1.25663706e-06 N/A2 Magnetic constant
muB 9.27400968e-24 J/T Bohr magneton
pc 3.08567758e+16 m Parsec
sigma_T 6.65245873e-29 m2 Thomson scattering cross-section
sigma_sb 5.670373e-08 W / (K4 m2) Stefan-Boltzmann constant
u 1.66053892e-27 kg Atomic mass


Constant A physical or astronomical constant.
EMConstant An electromagnetic constant.

Class Inheritance Diagram

Inheritance diagram of astropy.constants.constant.Constant, astropy.constants.constant.EMConstant