Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:Python zipapp

From ReverseEngineering.wiki
Format
Developer CPython (Lib/zipapp.py)
Magic optional '#!' interpreter line, then 50 4B 03 04 (ZIP)
Extensions .pyz, .pyzw
License PSF-2.0
On this wiki Facts · Code · Notes · Topics

A Python application archive (.pyz, .pyzw): an ordinary ZIP file containing a __main__.py, optionally preceded by a #! shebang line that the ZIP reader skips because it locates the central directory from the end of the file; run with python app.pyz.

Identification

  • A zipapp is a normal ZIP archive. Python's zipapp.create_archive optionally writes a shebang line #!<interpreter>\n before the ZIP data, so the file may begin with #! instead of PK; ZIP readers still work because the end-of-central-directory record is found from the end of the file (Fact:Python zipapp/behavior/Shebang prefix and main .py).
  • The interpreter runs a directory or zip that contains __main__.py; with the -m module:function option the tool generates a __main__.py (stored UTF-8) whose body is # -*- coding: utf-8 -*-, import <module>, <module>.<fn>(). Files are stored uncompressed unless the --compress option is used (ZIP_DEFLATED).
  • python -m zipapp archive.pyz --info prints the interpreter from the shebang; the shebang is encoded UTF-8 on Windows and in the file-system encoding elsewhere.
  • Extraction: unzip it. The members are usually source .py files, not bytecode (Unverified for archives made by other tools: pex, shiv and similar builders produce zipapps that may contain wheels, .pyc files or a bootstrap that unpacks to a cache directory; check the __main__.py).

Related

Briefcase (BeeWare) packages apps as platform installers around a normal Python install and does not use this format (Unverified: not read from source here). Frozen-executable packagers are in Technique:Bundled-runtime applications.

Code & repositories

See the CPython source listed in the evidence of the fact.