Format:Python zipapp
Appearance
| 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_archiveoptionally writes a shebang line#!<interpreter>\nbefore the ZIP data, so the file may begin with#!instead ofPK; 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:functionoption 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--compressoption is used (ZIP_DEFLATED). python -m zipapp archive.pyz --infoprints 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
.pyfiles, not bytecode (Unverified for archives made by other tools: pex, shiv and similar builders produce zipapps that may contain wheels,.pycfiles 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.