Skip to main content

pylhe: A Lightweight Python interface to Les Houches Event files

pylhe logo

GitHub Project DOI Scikit-HEP

RTD Docs Live Docs

PyPI version Conda-forge version Supported Python versions

GitHub Actions Status Code Coverage pre-commit.ci status Code style: black

Binder

Small and thin Python interface to read Les Houches Event (LHE) files

Why pylhe?

A small script can parse the basic particle records in a simple LHE file, but production files contain LHE3 weights and weight groups, scale and generator metadata, optional attributes and comments, compression, and generator-specific variations. pylhe provides event-generator users and analysts with a maintained and tested implementation of these details, exposed through a common typed data model. It supports streaming, writing, conversion between LHE and LHEH5, and integration with Awkward Array.

Tested Monte Carlo Generators' LHE output

LHE XML

Generator Tested Versions
MadGraph5 2.0.0, 2.2.1, 3.5.8
POWHEG-BOX-V2 r4027
Pythia 6.413, 8.3.14
Sherpa 3.0.1
Whizard 3.1.4

LHEH5

Generator Tested Versions
Sherpa 2.3.0
Pepper 1.13.1

Note: test files are provided via the scikit-hep-testdata package. Please open an issue of create directly a PR for the inclusion of new files for testing.

Install

To install pylhe from PyPI you can just do

python -m pip install pylhe

The visualization capabilities require the external dependency of Graphviz.

Get started

The example below provides a simple overview. Full functionality can be inspected from the functions provided in the pylhe module. For more information about the LHE format, see the LHE format documentation.

Reading

import itertools

# You can use LHE files from scikit-hep-testdata
from skhep_testdata import data_path

import pylhe

lhe_file = data_path("pylhe-testlhef3.lhe")
events = pylhe.LHEFile.fromfile(lhe_file).events
print(f"Number of events: {pylhe.LHEFile.count_events(lhe_file)}")

# Get event 1
event = next(itertools.islice(events, 1, 2))

# A DOT language graph of the event can be inspected as follows
print(event.graph.source)

# The graph is nicely displayed as SVG in Jupyter notebooks
event

# To save a DOT graph render the graph to a supported image format
# (refer to the Graphviz documentation for more)
event.graph.render(filename="test", format="png", cleanup=True)
event.graph.render(filename="test", format="pdf", cleanup=True)

Writing

For a full example see write or filter. The values in the sketch below are intentionally left empty since they depend on the use-case. The data structure of pylhe is:

import pylhe

file = pylhe.LHEFile(
    init=pylhe.LHEInit(
        initInfo=pylhe.LHEInitInfo(
            beamA=...,
            beamB=...,
            energyA=...,
            energyB=...,
            PDFgroupA=...,
            PDFgroupB=...,
            PDFsetA=...,
            PDFsetB=...,
            weightinStrategy=...,
            numProcesses=...,
        ),
        procInfo=pylhe.LHEProcInfo(
            xSection=...,
            error=...,
            unitWeight=...,
            procId=...,
        ),
    ),
    events=[
        pylhe.LHEEvent(
            eventinfo=pylhe.LHEEventInfo(
                nparticles=...,
                pid=...,
                weight=...,
                scale=...,
                aqed=...,
                aqcd=...,
            ),
            particles=[
                pylhe.LHEParticle(
                    id=...,
                    status=...,
                    mother1=...,
                    mother2=...,
                    color1=...,
                    color2=...,
                    px=...,
                    py=...,
                    pz=...,
                    e=...,
                    m=...,
                    lifetime=...,
                    spin=...,
                ),
            ],
            weights=None,
            attributes=None,
            optional=None,
        ),
    ],
)

# write to file, compressed if gz/gzip suffix
file.tofile("myevents.lhe.gz", lheformat=pylhe.LHEXMLFormat(compress=True))

Citation

The preferred BibTeX entry for citation of pylhe is both the published paper and the Zenodo archive:

@article{PuckNeuwirth:2026nco,
    author = "Puck Neuwirth, Alexander and Feickert, Matthew and Heinrich, Lukas and Rodrigues, Eduardo",
    title = "{pylhe: A Lightweight Python interface to Les Houches Event files}",
    eprint = "2607.29352",
    archivePrefix = "arXiv",
    primaryClass = "hep-ph",
    month = "7",
    year = "2026"
}
@software{pylhe,
  author = {Lukas Heinrich and Matthew Feickert and Eduardo Rodrigues and Alexander Puck Neuwirth},
  title = "{pylhe: v2.1.0}",
  version = {v2.1.0},
  doi = {10.5281/zenodo.1217031},
  url = {https://github.com/scikit-hep/pylhe},
}

pylhe has been referenced in:

Contributors

We hereby acknowledge the contributors that made this project possible (emoji key):

Matthew Feickert
Matthew Feickert

🚧 🎨 💻 📖
Lukas
Lukas

🚧 🎨 💻 📖
Eduardo Rodrigues
Eduardo Rodrigues

🚧 💻 📖
Alexander Puck Neuwirth
Alexander Puck Neuwirth

🚧 🎨 💻 📖
Johannes Schumann
Johannes Schumann

💻
Henry Schreiner
Henry Schreiner

💻
ariaradick
ariaradick

💻
Junghwan John Goh
Junghwan John Goh

💻
fuenfundachtzig
fuenfundachtzig

💻
Shantanu Gontia
Shantanu Gontia

💻
Tom Eichlersmith
Tom Eichlersmith

💻
Iason Krommydas
Iason Krommydas

💻 📖

This project follows the all-contributors specification.

Metadata

Release files for pylhe 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pylhe 2.1.0
File Size Uploaded
pylhe-2.1.0.tar.gz 47.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pylhe 2.1.0
File Interpreter ABI Platform
pylhe-2.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 75.8 kB

Release files / pylhe-2.1.0.tar.gz

Download URL pylhe-2.1.0.tar.gz
Size 47.4 kB
Tags Source
SHA-256 checksum
How to use checksums
bdbc359831c239f36069a2ea1d6209c16bf20aaddb407b3994ed362ac640c64b
BLAKE2b-256 checksum
How to use checksums
097695a5561d2285457e3288c759c798abdbfb6769e377dd470a318e807248af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.

Transparency log

Release files / pylhe-2.1.0-py3-none-any.whl

Download URL pylhe-2.1.0-py3-none-any.whl
Size 28.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2c91195426c9e3e376ad3245cc65a2481db878b28d8f5f26db0e1aa898e644a7
BLAKE2b-256 checksum
How to use checksums
cd8824a007a895771a5065a4f5da3ea7407ae179836a6b838038e40149177af3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 release files

2.0.0

2 release files

1.0.4

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.6

2 release files

0.0.5

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page