Python API
The PDG Python API provides a high-level tool for programmatically accessing PDG data. For most users, this is the recommended way to access PDG data in machine-readable format. The Python API provides straightforward navigation from particles to their properties and the corresponding information included in the Review of Particle Physics. After the initial installation, the Python API does not require an Internet connection.
The Python API is implemented in Python package pdg and uses
a PDG database file as its default data repository.
The database file corresponding to the current edition of the Review of Particle Physics
at the time of releasing a given version of the package is installed together with the package.
When the Review of Particle Physics is updated, a new version of the pdg
package with the latest data is released.
To access the data from other editions, additional database files can be downloaded from the PDG website and used with the Python API. Since SQLAlchemy is used for all database access, the necessary database tables could be copied from the SQLite database file into an existing database system (as long as it is supported by SQLAlchemy), and the Python API could then be used with that database system.
The pdg
package is released as open source software and can be found at
github.com/particledatagroup/api.
Requirements
The PDG Python API supports Python 3 and requires SQLAlchemy version 1.4 or greater. For the time being, Python 2.7 is still supported.
Installation
The PDG Python API can be installed like any other Python package available from PyPI.
For example, the following commands will first create and activate a Python 3 virtual environment using venv
and then download and install package pdg
and its dependencies:
python3 -m venv pdg.venv
source pdg.venv/bin/activate
python -m pip install pdg
(Use virtualenv
instead of venv
for Python versions below 3.3.)
If a Python virtual environment was already activated, only the following command is needed:
python -m pip install pdg
Alternatively, to add the pdg
package to one’s system Python installation if the system Python
installation is not marked as being externally managed (if it is, there will be an error message
error: externally-managed-environment
), one can use
python -m pip install --user pdg
Usage
Any use of the PDG Python API starts with importing the package and connecting the API to a database file:
import pdg
api = pdg.connect()
As discussed below, connect()
takes two optional arguments:
The URL of the database to use. The default is to use the SQLite database file installed with the
pdg
package.Whether the API should operate in pedantic mode or not. Pedantic mode is disabled by default.
Connecting to a different database
To connect e.g. to a SQLite database file pdgall-2023-v0.1.sqlite
, which was downloaded from the
PDG website into the current directory, one would use
api = pdg.connect('sqlite:///pdgall-2023-v0.1.sqlite')
Pedantic mode
Given the nature of the PDG dataset, there are many special cases and sometimes additional knowledge is needed to determine the correct answer. For example, when asking for the mass of the top quark, in most cases the mass resulting from direct measurements is expected, but sometimes the user may want the mass determined from cross-section measurements. By default, if the user asks for a single value (rather than an iterable over all values), the API will either make an assumption that is expected to be correct in most cases, or simply return the value listed first in the Summary Tables or Particle Listings. If this default behaviour is not desirable, the API can connect in pedantic mode to the database:
api = pdg.connect(pedantic=True)
Then, rather than making assumptions in cases where the answer is ambiguous, a PdgAmbiguousValueError
will be raised.
Thus, taking the example above of the top quark mass,
pdg.connect().get_particle_by_name('t').mass
will return a value of about 173 GeV (2024 edition), while
pdg.connect(pedantic=True).get_particle_by_name('t').mass
will raise pdg.errors.PdgAmbiguousValueError: Ambiguous best property for t mass (Q007/2024)
.
Getting information about the database being used
After connecting to a database, the API object can be printed for a summary of edition, citation, versions and license
information. These and more quantities (see api.info_keys()
) can be accessed as properties of the API object or by
using api.info(key)
. For example
api.edition
provides the edition (publication year) of the Review of Particle Physics from which the data is taken.
Examples
After retrieving the desired particle, one can then either directly get the desired quantity such as particle mass or quantum numbers, or obtain an iterator over the desired information such as all exclusive branching fractions for which PDG has data. A few examples with complete code snippets are given below.
Particle Monte Carlo number, mass and quantum numbers
Note: The Monte Carlo particle numbering scheme was substantially updated and extended in 2012. The Python API follows the particle numbering used in the current version of the PDG table of particle information where certain excited baryons follow the pre-2012 scheme. A further revision and/or extension of the numbering scheme is anticipated in the near future.
The following code snippet could be used to print the Monte Carlo particle number, mass (without rounding or errors), and spin of the negative pion:
import pdg
api = pdg.connect()
pi_minus = api.get_particle_by_name('pi-')
print('MC ID = ', pi_minus.mcid)
print('mass = ', pi_minus.mass, 'GeV')
print('spin J = ', pi_minus.quantum_J)
Branching fractions
The following code snippet prints all exclusive branching fractions of the charged B meson with their description, ‘True’ if the value denotes a limit, and the raw value (as an unrounded floating point number or None).
import pdg
api = pdg.connect()
for bf in api.get_particle_by_name('B+').exclusive_branching_fractions():
print('%-60s %4s %s' % (bf.description, bf.is_limit, bf.value))
Decays
For branching fractions one can access the particles in the corresponding decay as a list of decay products (PdgDecayProduct
).
Each PdgDecayProduct
specifies the item (PdgItem
) that appears, a multiplier, and whether the item needs to decay
in a specific way. PdgItems
can represent a particle of a specific charge (e.g. a pi+), a generic particle such
as a kaon without specifying its charge, a lepton (which could be either an electron or a muon), or a textual description
such as “>= 0 neutrals”.
In a simple case, all decay products appear with multiplicity 1 and are particles with specified charge. For example:
pion_decay = api.get('S008.1')
pion_decay.description # 'pi+ --> mu+ nu_mu'
len(pion_decay.decay_products) # 2
pion_decay.decay_products[0].multiplier # 1
pion_decay.decay_products[0].item.name # 'mu+'
pion_decay.decay_products[0].item.particle.mcid # -13
By querying the decay products one can easily filter out specific decay modes. For example, the following code snippet prints all exclusively measured B0 decays that produce a J/psi:
import pdg
api = pdg.connect()
for decay in api.get_particle_by_name('B0').exclusive_branching_fractions():
decay_products = [p.item.name for p in decay.decay_products]
if 'J/psi(1S)' in decay_products:
print(format(decay.description,'40s'), decay.display_value_text)
Particle properties (except branching fractions)
The following code snippet prints all properties other than branching fractions of the charged pion (retrieved this time via Monte Carlo number rather than name). For each property, the PDG Identifier, the description, and the rounded value with error is shown.
import pdg
api = pdg.connect()
for p in api.get_particle_by_mcid(211).properties():
print('%16s: %-60s %s' % (p.pdgid, p.description, p.display_value_text))
Detailed software documentation
Detailed information on all public classes, methods and utility functions provided by the PDG Python API is given below, based on the inline code documentation.
pdg package
Python API to access PDG data.
The Python package pdg provides access to the particle physics data published by the Particle Data Group (PDG) in the Review of Particle Physics.
For documentation see https://pdgapi.lbl.gov/doc.
For general information about PDG and the Review of Particle Physics please visit https://pdg.lbl.gov.
- pdg.connect(database_url=None, pedantic=False)[source]
Connect to PDG database and return configured PDG API object.
Submodules
- pdg.api module
PdgApi
PdgApi.default_edition
PdgApi.doc_data_type_keys()
PdgApi.doc_key_value()
PdgApi.doc_value_type_keys()
PdgApi.editions
PdgApi.get()
PdgApi.get_all()
PdgApi.get_canonical_name()
PdgApi.get_particle_by_mcid()
PdgApi.get_particle_by_name()
PdgApi.get_particles()
PdgApi.get_particles_by_name()
PdgApi.info()
PdgApi.info_keys()
- pdg.data module
PdgConvertedValue
PdgData
PdgLifetime
PdgMass
PdgProperty
PdgProperty.best_summary()
PdgProperty.comment
PdgProperty.confidence_level
PdgProperty.display_value_text
PdgProperty.error
PdgProperty.error_negative
PdgProperty.error_positive
PdgProperty.has_best_summary()
PdgProperty.is_limit
PdgProperty.n_summary_table_values()
PdgProperty.scale_factor
PdgProperty.summary_values()
PdgProperty.units
PdgProperty.value
PdgSummaryValue
PdgSummaryValue.comment
PdgSummaryValue.confidence_level
PdgSummaryValue.description
PdgSummaryValue.display_in_percent
PdgSummaryValue.display_power_of_ten
PdgSummaryValue.display_value_text
PdgSummaryValue.error
PdgSummaryValue.error_negative
PdgSummaryValue.error_positive
PdgSummaryValue.get_error()
PdgSummaryValue.get_error_negative()
PdgSummaryValue.get_error_positive()
PdgSummaryValue.get_value()
PdgSummaryValue.in_summary_table
PdgSummaryValue.is_limit
PdgSummaryValue.is_lower_limit
PdgSummaryValue.is_upper_limit
PdgSummaryValue.pdgid
PdgSummaryValue.pprint()
PdgSummaryValue.scale_factor
PdgSummaryValue.units
PdgSummaryValue.value
PdgSummaryValue.value_type
PdgSummaryValue.value_type_key
PdgWidth
- pdg.decay module
- pdg.errors module
- pdg.particle module
PdgItem
PdgParticle
PdgParticle.branching_fractions()
PdgParticle.charge
PdgParticle.exclusive_branching_fractions()
PdgParticle.has_lifetime_entry
PdgParticle.has_mass_entry
PdgParticle.has_width_entry
PdgParticle.inclusive_branching_fractions()
PdgParticle.is_baryon
PdgParticle.is_boson
PdgParticle.is_lepton
PdgParticle.is_meson
PdgParticle.is_quark
PdgParticle.lifetime
PdgParticle.lifetime_error
PdgParticle.lifetimes()
PdgParticle.mass
PdgParticle.mass_error
PdgParticle.masses()
PdgParticle.mcid
PdgParticle.name
PdgParticle.properties()
PdgParticle.quantum_C
PdgParticle.quantum_G
PdgParticle.quantum_I
PdgParticle.quantum_J
PdgParticle.quantum_P
PdgParticle.width
PdgParticle.width_error
PdgParticle.widths()
PdgParticleList
- pdg.units module
- pdg.utils module
License
The data obtained from the PDG Python API is subject to the license used by the corresponding edition of the Review of Particle Physics. Starting with the 2024 edition, the Review of Particle Physics is published under a CC BY 4.0 license.