Compression and Archives Modules
zipapp
Packages Python source into executable ZIP applications with an entry point in __main__.py. The archive requires an appropriate interpreter and importable dependencies. Native extension modules generally cannot be loaded directly from the archive. Treat a Python application archive as executable code; only run trusted packages.
Formal Syntax & Structure
python syntaxpython
import zipappReturn Value
module
Module namespace available through import; import is a statement, not a value-returning expression.
Working Example
Example Snippetpython
import zipappfrom pathlib import Pathfrom tempfile import TemporaryDirectoryfrom zipfile import ZipFilewith TemporaryDirectory() as folder: source = Path(folder)/"app" source.mkdir() (source/"__main__.py").write_text("print('ready')", encoding="utf-8") target = Path(folder)/"app.pyz" zipapp.create_archive(source, target) with ZipFile(target) as archive: print("__main__.py" in archive.namelist())