Metadata-Version: 2.4
Name: endf-parserpy
Version: 0.19.0
Summary: A Python package for reading, writing, verifying and translating ENDF-6 files
Author: Georg Schnabel
License: MIT
Project-URL: Repository, https://github.com/iaea-nds/endf-parserpy
Project-URL: Documentation, https://endf-parserpy.readthedocs.io/en/stable/
Project-URL: Issues, https://github.com/iaea-nds/endf-parserpy/issues
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: End Users/Desktop
Classifier: Operating System :: OS Independent
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: fast
Requires-Dist: numpy>=1.20; extra == "fast"
Provides-Extra: cli
Requires-Dist: lark>=1.0.0; extra == "cli"
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Requires-Dist: lark>=1.1; extra == "test"
Dynamic: license-file

# endf-parserpy - an ENDF-6 toolkit for Python

[![PyPI version](https://img.shields.io/pypi/v/endf-parserpy)](https://pypi.org/project/endf-parserpy/)
[![Python versions](https://img.shields.io/pypi/pyversions/endf-parserpy)](https://pypi.org/project/endf-parserpy/)
[![Tests](https://github.com/IAEA-NDS/endf-parserpy/actions/workflows/test_package.yml/badge.svg)](https://github.com/IAEA-NDS/endf-parserpy/actions/workflows/test_package.yml)
[![Documentation](https://readthedocs.org/projects/endf-parserpy/badge/?version=latest)](https://endf-parserpy.readthedocs.io/en/latest/)

`endf-parserpy` is a Python package for reading
and writing [ENDF-6](https://doi.org/10.2172/2007538) files.
This functionality in combination with Python's
powerful facilities for data handling enables you to
perform various actions on ENDF-6 files, such as:

- Access any information easily
- Modify, delete, and insert data
- Perform format validation
- Convert to and from other file formats, such as JSON
- Merge data from multiple ENDF-6 files into a single file
- Read and write files containing multiple materials (tapes)
- Compare ENDF-6 files and generate meaningful reports of their differences
- Construct ENDF-6 files from scratch


Many of these actions can also be performed from the command line
through the `endf-cli` tool.

The support for the ENDF-6 format is comprehensive, and some special
NJOY2016 output formats are supported as well. The package has been
tested on the various sublibraries of the major nuclear data
libraries, such as
[ENDF/B](https://www.nndc.bnl.gov/endf/),
[JEFF](https://www.oecd-nea.org/dbdata/jeff/),
and [JENDL](https://wwwndc.jaea.go.jp/jendl/jendl.html).
Files that bundle several materials — including PENDF tapes
that repeat the same material at different temperatures — are
supported both as plain lists of materials and through a lazy,
memory-bounded `EndfFile` interface for large files.
Parsing and writing are heavily optimized; see
[Performance](#performance) below for concrete figures.


## Install endf-parserpy

This package is available on the
[Python Package Index](https://pypi.org/project/endf-parserpy/)
and can be installed using `pip`:

```sh
python -m pip install endf-parserpy --upgrade
```

The optional NumPy dependency, installed with
`python -m pip install "endf-parserpy[fast]"`, is needed for
`array_type="numpy"`, the fastest parsing mode, and speeds up the
scan of multi-material files, which otherwise runs in pure Python.
Parsing with the other array types does not need NumPy.


## Documentation

The documentation is available online
[@readthedocs](https://endf-parserpy.readthedocs.io).
See the `README.md` in the `docs/` subdirectory
for instructions on building the documentation locally.


## Simple example

The following code snippet demonstrates
how to read an ENDF-6 file, change the
`AWR` variable in the MF3/MT1 section
and write the modified data to a new
ENDF-6 file:

```python
from endf_parserpy import EndfParserFactory
parser = EndfParserFactory.create()
# fastest variant, returning arrays of numbers as numpy arrays:
# parser = EndfParserFactory.create(array_type="numpy")
endf_dict = parser.parsefile('input.endf')
endf_dict[3][1]['AWR'] = 99.99
# raises FileExistsError if output.endf exists (overwrite=True replaces it)
parser.writefile('output.endf', endf_dict)
```


## How it works

Support for the ENDF-6 format in `endf-parserpy` is not hand-coded
section by section. The format is described by *recipes*, written in a
formal language that mirrors the record layout of the
[ENDF-6 formats manual](https://doi.org/10.2172/2007538). This is the
complete recipe for an MF3 section (cross sections):

```
[MAT, 3, MT/ ZA, AWR, 0, 0, 0, 0] HEAD
[MAT, 3, MT/ QM, QI, 0, LR, NR, NP / E / xs] TAB1 (xstable)
SEND
```

This single description drives everything else:

- reading and writing in pure Python: `EndfParserPy` interprets the
  recipe at run time,
- the C++ reading *and* writing code of the fast backend
  (`EndfParserCpp`), generated by a compiler included in the package,
- the structure of the Python dictionaries you work with: the variable
  names in the recipe are the keys in the dictionary, so the formats
  manual directly documents the data you get. The recipe files also
  carry the manual's variable descriptions as comments, making them
  readable documentation of the format itself.

Because reading and writing in both parsers and the dictionary layout
all follow from the same recipe, they are consistent with each other
and with the format description by construction.

The recipes are ordinary data, and the same machinery is open to you:
custom or extended formats — special NJOY output, laboratory-internal
conventions, format extensions — can be described as recipes and used
directly with `EndfParserPy`, and a recipe can be compiled into a
dedicated fast C++ parser module with a documented procedure. See
[format extensions](https://endf-parserpy.readthedocs.io/en/latest/guide/format_extensions.html)
and
[accelerated parsing and writing](https://endf-parserpy.readthedocs.io/en/latest/guide/accelerated_parsing_and_writing.html)
in the documentation.


## Performance

With the C++ backend and `array_type="numpy"`, `endf-parserpy` reads
the complete neutron sublibrary of ENDF/B-VIII.1 — 558 files, 1.3 GB —
in about 2 seconds and writes it back to ENDF-6 text in about
8 seconds (single core of an Intel Core i7-1165G7 laptop, warm file
cache; measured on the development version of November 2026). Every
value is fully interpreted during parsing, and written output is
formatted field by field.

The [Performance](https://endf-parserpy.readthedocs.io/en/latest/performance.html)
page of the documentation gives the results for both parsers and all
array types, by sublibrary and file size, with the peak memory and the
command that reproduces them; they are refreshed for each release.


## Citation

If you want to cite this package,
please use the following reference:

```
G. Schnabel, D. L. Aldama, R. Capote, "How to explain ENDF-6 to computers: A formal ENDF format description language", arXiv:2312.08249, DOI:10.48550/arXiv.2312.08249
```


## License

This code is distributed under the MIT license augmented
by an IAEA clause, see the accompanying license file for more information.

Copyright (c) 2022-2026 International Atomic Energy Agency (IAEA)


## Acknowledgments

Daniel Lopez Aldama made significant contributions
to the development of this package. He debugged the
ENDF-6 recipe files and helped in numerous discussions
to convey a good understanding of the technical details of
the ENDF-6 format that enabled the creation of this package.


## Development and AI assistance

endf-parserpy, including the formal recipe language, the parser
architecture and the compiler that translates recipes into C++ code,
was designed and developed without AI assistance from its beginning
in 2022 up to and including version 0.16 (May 2026). Starting with
version 0.17, AI coding assistance (Claude Fable 5 and Claude Opus 5.5
by Anthropic) has been used extensively, in particular, but not
exclusively, for the multi-material interface (`TapeIndex`, `EndfFile`
and the multi-material support of `endf-cli`, version 0.17), the
support for numpy arrays (`array_type="numpy"`, version 0.18), finding
and fixing bugs, and the performance optimization of the recipe
compiler and the generated C++ backend.

All AI-assisted changes were reviewed and tested before inclusion.
Beyond the test suite, changes to reading and writing were checked on
evaluated nuclear data files, by read-write-read round trips and by
comparing the parse results and the written output with those of the
previous version. For the larger changes, this covered all files of
the ENDF/B-VIII.1 neutron sublibrary and of the ENDF/B-VIII.0 thermal
scattering, decay data and electro-atomic sublibraries. The optimized
number conversion of the C++ parser is tested against a reference
conversion, exhaustively for the number layouts it accelerates, and
its vectorized variants against the scalar one.
