This file provides guidance to agents when working with code in this repository.
particle is a pure-Python Scikit-HEP package providing a pythonic interface to the Particle Data Group (PDG) particle data tables and the standard MC particle identification (PDG ID) numbering scheme. The two central public classes are PDGID (queries on an integer ID) and Particle (full object-oriented particle record with search/lookup). The package ships its own data tables and reads them lazily at runtime.
This is a uv-managed environment; prefer uv run for Python invocations.
uv run pytest # run the full test suite
uv run pytest tests/pdgid/ # run one test directory
uv run pytest tests/particle/test_particle.py::test_name # run a single test
uv run pytest --benchmark-enable # benchmarks are disabled by default (see addopts)
prek -a --quiet # lint / format (ruff, mypy, codespell, etc.)
uv run nox # default sessions: lint, pylint, tests
uv run nox -s pylint # pylint only
uv run nox -s build # build sdist + wheel, twine check
uv run nox -s zipapp # build the self-contained particle.pyzNotes:
pytestconfig setsfilterwarnings = ["error"]andxfail_strict = true— warnings and unexpected xpasses fail the suite.- Lint enforces
from __future__ import annotationsat the top of every module (ruff isortrequired-imports). - mypy runs in
strictmode oversrcandtests.
The package is runnable as a module:
python -m particle search D0 # look up particles by name or PID
python -m particle pdgid 323 # print PDGID property table for an IDsrc/particle/ is organized into subpackages, each pairing an ID/domain class with optional literals and data:
pdgid/—PDGID(anintsubclass) plusfunctions.py, a large library of free-standing predicates (is_meson,has_bottom,charge,J, etc.) that operate on anySupportsInt.PDGIDmethods delegate to these functions; the functions are the source of truth and are also re-exported for composable use.literals.pyholds named ID aliases (e.g.pi_plus).particle/— theParticleclass (particle.py, ~1300 lines, built withattrs), plusenums.py(Charge,Parity,SpinType,Inv,Status),kinematics.py(width_to_lifetimeetc.),utilities.py,regex.py, andconvert.py(data-table generation, see below).converters/—BiMap/DirectionalMaps(bimap.py) plus per-generator converters (pythia.py,geant.py,corsika.py,evtgen.py) backed by CSV files.pythia/,geant/,corsika/,lhcb/— generator-specific ID classes (PythiaID,Geant3ID,Corsika7ID) and name mappings.data/— bundled data files plus a loader. Importparticle.dataand useparticle.data.basepath / "particle2026.csv"(usesimportlib.resources, so it works even from a zipapp). Do not hardcode filesystem paths to data.
Particle keeps lazily-populated class-level caches: _table (sorted list), _hash_table (PDGID → Particle), and _table_names. The table is not read at import — load_table() is triggered on first access (e.g. from_pdgid, findall, all). load_table(filename, append=True) lets users extend or replace the built-in table; by default it loads particle2026.csv then nuclei2026.csv. from_pdgid / from_name / findall are the main lookup entry points.
src/particle/data/README.rst documents every data file. The pipeline: the 2008 fixed-width files (mass_width_2008.fwf, mass_width_2008_ext.fwf) + LaTeX names + the year's .txt PDG download are combined by particle/convert.py into the per-year particleYYYY.csv that Particle reads. Regenerate with:
python -m particle.particle.convert regenerate <year> <version> # rebuild built-in CSVsThe pdgid.literals and particle.literals modules are generated by cog from the CSV table — edit the common_particles source (shared_literals.py) and regenerate, don't hand-edit the generated lists:
uv run nox -s generate_aliases # runs cog over the two literals.py files- Every source file begins with the BSD-3 copyright header and
from __future__ import annotations. - Supported Python is 3.10+; strict dependencies are
attrsandhepunitsonly (pandas/tabulateare dev/test extras, imported lazily where used). - Follow the Scikit-HEP developer guide.
- Releases are cut by tagging
v#.#.#on GitHub after updatingdocs/CHANGELOG.md; the version is derived from git viahatch-vcs.