pyelftools reads ELF and DWARF without leaving Python
Parsing ELF and DWARF in Python
At a glance
- What is it?
- pyelftools parses ELF containers and DWARF debugging data in pure Python, with no external dependencies and a construct layer shipped inside the distribution. Its packaging metadata and its repository layout disagree about one file, and the example suite is demonstrated against a single sample binary.
- Who is it for?
- Adopt pyelftools when your pipeline needs ELF and DWARF facts as Python objects and you would rather not scrape another tool's text output; the vendored construct layer is what makes that cheap. Do not adopt it as a general binary inspector, since the repository covers ELF and DWARF only, and anything outside the ELF container needs a different library.
- Can I use it commercially?
- Check first. The repository uses a licence we do not classify automatically, so read its LICENSE file before any commercial use.
- Is it still maintained?
- Yes. The repository last received commits 22 days ago.
- What is it written in?
- Mainly Python, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 24, 2026, and from our analysis. They are not legal advice.
Star history
- eliben/pyelftools2,290 ★ · +1
| Repository | 2026-10-22 | 2026-11-24 |
|---|---|---|
| eliben/pyelftools | 2.3k | 2.3k |
1 Stars in the last 33 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
Reading ELF bytes without shelling out to binutils
pyelftools is a pure-Python library for parsing and analyzing ELF files and DWARF debugging information. You import it and invoke it from your own code; there is no daemon, no service and no plugin host to configure before you get an answer. That shape is the whole point for people who want structured objects rather than a wall of text: build steps that need to walk a symbol table, analysis passes that read DWARF type information, triage scripts that must describe a binary without running it.
The package metadata tells you who the author had in mind. Alongside Topic :: File Formats it lists Topic :: Software Development :: Compilers, Debuggers and Disassemblers, and it declares Development Status :: 5 - Production/Stable. Nothing in the layout pins it to one job, though. What ships is a set of importable modules, not a command suite, so the same parse is reachable from a build plugin or from a script you run once.
Seven explicit packages, including a vendored construct layer
The setup metadata enumerates 7 packages by hand: `elftools`, `elftools.elf`, `elftools.common`, `elftools.dwarf`, `elftools.ehabi`, `elftools.construct` and `elftools.construct.lib`. Nothing is discovered automatically, so a new subpackage has to be added to that list before it ships, and the list doubles as the clearest map of the library's scope. Two names carry the architecture by themselves. The ELF container lives in one subpackage, the DWARF debugging format in another, and `elftools.common` sits underneath both.
The construct entries matter most to anyone weighing dependencies. Declarative binary parsers usually arrive as a separate package, yet these two are part of this distribution, which is how the library can promise no external dependencies and still describe records as nested structures with named fields. `elftools.ehabi` is the odd one out: unwind tables are neither ELF nor DWARF, and carrying a package for them says exception handling data is a target rather than an afterthought.
Version strings are deliberately not written down. The project table sets `dynamic = ["version"]` instead of a literal, so the number comes from the build, while a `CHANGES` file sits at the top level as the running record of what moved.
Installing from PyPI or pointing PYTHONPATH at a clone
The library sits on PyPI under the name `pyelftools` and the README tells you to install it with whichever Python package manager you already use. That is the whole installation story, because the library has no external dependencies: no compiler, no headers, no transitive wheel to resolve. A second route skips installation entirely. Clone the Git repository, then adjust `PYTHONPATH` so the checkout is importable, which is the faster loop while you are changing the parser itself.
The packaging metadata is where the real constraints live. The build needs setuptools at 46.4.0 or newer, and the project table demands Python 3.10 even though the pre-requisites paragraph in the README only says Python 3.
[build-system]
requires = ["setuptools >= 46.4.0"]
build-backend = "setuptools.build_meta"The README justifies that gap by pointing at the Status of Python versions page as the basis for the continuous integration matrix, so the stricter number in the metadata decides whether an install succeeds, and Python 3.10 is the figure to plan around.
A first pass through the bundled ELF and DWARF examples
The repository ships an `examples/` directory whose filenames do most of the documenting. On the ELF side, `elf_low_high_api.py` targets 2 access levels over the same parsed structures, `elfclass_address_size.py` reads the class and address size, `elf_notes.py` walks notes and `elf_relocations.py` walks relocation entries. `elf_show_debug_sections.py` is the one to run first on an unfamiliar binary, since it reports which debug sections exist before any DWARF parsing is attempted. The DWARF scripts go deeper: `dwarf_decode_address.py` turns an address into source lines, `dwarf_die_tree.py` walks debug information entries, `dwarf_location_info.py` and `dwarf_range_lists.py` read variable placement, and `dwarf_pubnames_types.py` resolves type names.
Two supporting entries shape how those scripts are meant to be used. Every DWARF example runs against `examples/sample_exe64.elf`, the only binary in the repository, and `examples/reference_output/` stores the expected output so a changed printout can be diffed. One sample means each script is demonstrated exactly once, so the class and address size handling reported by `elfclass_address_size.py` has a single worked example behind it. Behaviour on anything else has to come from a file you bring yourself.
The Makefile checks types with ty, not the typing group
Two make targets cover the contributor loop, and both fetch their tools on demand instead of using anything installed in your environment. Lint and type checking run through `uvx`, the runner that downloads a pinned tool, and the pins are overridable variables: RUFF_VERSION ?= 0.16.0 and TY_VERSION ?= 0.0.64. Neither tool has to be added to a requirements file, which fits a library that ships no runtime dependencies at all.
check:
$(RUFF) check .
$(TY) checkHere is the part a skim misses. The typing dependency group lists mypy[reports], pyright, typeguard and typing_extensions, yet the check target runs ty at version 0.0.64. The type checker you get from that target is not one of the four in the group, and the group itself is for editors and ad hoc runs. Wire pyright into your own editor and you are adding a check the project target never performs, so a pyright complaint will not stop it from passing.
Tests go through one entry point, the runner script the target hands the whole suite to:
python3 test/all_tests.pyNeither target prints a summary you can paste straight into a bug report, so capture the failure yourself when you open one.
The readme field names a file the repository lacks
The packaging metadata disagrees with the tree about one file. The project table sets `readme = "README.rst"`, and the top-level listing holds README.md with no README.rst beside it. Build from that state and the long description points at a path the checkout does not carry, which matters if anything automated reads the published package metadata.
Two smaller choices point the same way. The licence file keys sit commented out under an active `license = {text = "Public domain"}` line, as `#license-files = ["LICENSE"]`, so the licence text travels as a string rather than as a file that ships beside it. GitHub's own licence field reads as a custom text it cannot classify, while the classifiers in the same table say License :: Public Domain, so treat the `LICENSE` file as the authority rather than either summary.
The command-line side of the distribution is declared through script-files instead of a console_scripts table, and no project.scripts table exists in what is shown.
script-files = [
"scripts/readelf.py",
]An install therefore drops a command-line file into the scripts directory, and the entry point name is not something the project table declares.
Library call or shipped readelf script, two contracts
Two routes reach the same parsing code, and they suit different jobs. The README describes the library route plainly: you import it and invoke it from your own code, so a filtered answer stays a Python object you can keep working with. The distribution also ships `scripts/readelf.py` as a script-file entry, a command-line file that prints its findings and exits, which is the shape binutils readelf has.
That gap is a contract difference, not a matter of taste. In process you hold parsed records, so filtering on a relocation type or a DWARF tag happens in Python and costs no second parse. The command-line file hands you text, which diffs nicely in a test and reads well in a log, yet every follow-up question means parsing that text again in the shell. Pick the script for a quick look or a recorded comparison; pick the import for anything programmatic.
One wrinkle comes with that script-file entry. Its installed name collides with the readelf already on PATH on a typical Unix machine, and the repository does not document how the collision is resolved. Check what your environment resolves before you build a pipeline on top of it.
Editorial conclusion
Adopt pyelftools when your pipeline needs ELF and DWARF facts as Python objects and you would rather not scrape another tool's text output; the vendored construct layer is what makes that cheap. Do not adopt it as a general binary inspector, since the repository covers ELF and DWARF only, and anything outside the ELF container needs a different library. Before wiring it into a build, check that the README.rst named in pyproject.toml resolves in your checkout, and confirm which readelf your PATH resolves before you rely on scripts/readelf.py.
Frequently asked questions
How do I install pyelftools, and do I need a compiler?
The library is on PyPI as pyelftools and the README tells you to install it with your favourite Python package manager. It has no external dependencies, and the packaging metadata requires Python 3.10 or newer.
Does pyelftools depend on construct or any other third-party package?
No runtime dependency is declared, and the construct machinery ships inside the distribution as elftools.construct and elftools.construct.lib. That vendoring is what lets a declarative parser stay dependency-free.
What can pyelftools read besides ELF headers?
DWARF debugging information, including notes, relocations, debug sections, line programs, location information, range lists, public names and types, and debug information entry trees. The example scripts in the repository cover each of those areas.
How do I run the pyelftools tests and lint checks?
Two make targets exist: the test target hands the suite to python3 test/all_tests.py, and the check target runs ruff and ty through uvx with pinned versions 0.16.0 and 0.0.64.
Is pyelftools still maintained?
The last push was on 2026-07-30 and the repository is not archived. Version strings are dynamic rather than written into pyproject.toml, and a CHANGES file at the top level carries the running record.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/eliben-pyelftools)Star history chart for your README
[](https://hysenlabs.com/projects/eliben-pyelftools)Was this useful?