A Python library for reading and writing compiled Papyrus Script files (.pex) for Skyrim Special Edition.
This is neither a compiler (.psc -> .pex) nor a decompiler (.pex -> .psc)!
- Fully symmetrical parse and dump methods
- Fully typed and documented models based on Pydantic
- Automated validation of Papyrus data
With pip: pip install sse-pex-interface
With uv: uv add sse-pex-interface
This example demonstrates how to load a compiled Papyrus Script, modify its header and save it again:
>>> from sse_pex_interface import PexFile
>>> from pathlib import Path
>>> with Path("myscript.pex").open("rb") as stream:
... pex_file = PexFile.parse(stream)
...
>>> print(pex_file.header)
magic=4200055006 major_version=3 minor_version=2 game_id=1 compilation_time=1767530035 source_file_name='MyScript.psc' username='Cutleast' machinename='CUTLEAST-PC'
>>> pex_file.header.username = "Someone else"
>>> with Path("myscript.pex").open("wb") as stream:
... pex_file.dump(stream)
...
>>>