Changelogs
zipapps is a pure-python library, to package your python code into a single zip file with its dependencies.
Depends on PEP441 + zipapp + zipimport.
What is the .pyz?
.pyz to Python is like .jar to Java.
They are both zip archive files which aggregate many packages and associated metadata and resources (text, images, etc.) into one file for distribution.
All you need is the Python Interpreter as the runtime environment.
So, what could zipapps be?
packaging tool
compress your package folder into a zip file.
single-file virtual environment
a portable site-packages.
dependences installer
lazy install requirements while first running.
set of import-path
add many venv.pyz files to PYTHONPATH automatically.
requirements.txt freezing toolkit
use venv to freeze your pip packages.
PS: The pyz extension can be modified to any character you want, such as .py and .zip.
GUI
Prefer a graphical interface? Try uv-zipapps-gui — a Tkinter GUI for zipapps configuration and Python version management.
pip install uv-zipapps-gui
uv-zipapps-gui
# or run directly without installing:
uvx uv-zipapps-gui
Install & Quick Start
pip install zipapps -U
1. Source code without dependences
- add your source code into the zip file, and set the entrypoint with
-m
python3 -m zipapps -c -a entry.py -m entry:main -o app.pyz
entry.py could be a package package_name
-m format is package.module:function
- run app.pyz
python3 app.pyz
2. Source code with dependences
zipapps with requirements
python3 -m zipapps -c -a entry.py -m entry:main -o app.pyz bottle
bottle is a pure-python lib which may not be unzipped
-u AUTO or -u=* should be set for some .so/.pyd libs
- such as
psutil
- notice that the
-u=* != -u *
you don't need to install requirements at running
- ensure the compatibility of the system environment and python version
- or add
-d of lazy install mode to skip the compatibility problem
- but comes a long-time
pip install process at the first running.
run app.pyz
python3 app.pyz
- libs with
.pyd/.so caches will be unzipped to the ./zipapps_cache/app by -u AUTO
3. Virtual environments
zipapps with requirements
python3 -m zipapps -c -u AUTO -o venv.pyz -r requirements.txt
run entry.py with venv.pyz
python3 venv.pyz entry.py
- the cache will be unzipped to
./zipapps_cache/venv for -u is not null
4. Activate the .pyz environment
- use
importlib (Recommended)
sys.path.insert(0, "some_lib_venv.pyz");importlib.import_module("ensure_zipapps")
- automatically unzip cache, and add the path to sys.path
- it can be run multiple times
- if they are all pure-python code and no need to decompress
impory sys; sys.path.insert(0, "bottle.pyz")
- use
zipimport
# 1. use zipapps lib
from zipapps.activate_zipapps import activate
activate("app.pyz")
# or use source code directly
from zipimport import zipimporter
importer = zipimporter("app.pyz")
try:
spec = importer.find_spec("ensure_zipapps")
if spec and spec.loader:
module = spec.loader.load_module("ensure_zipapps")
else:
raise ImportError("Module not found")
except AttributeError:
module = importer.load_module("ensure_zipapps")
del module
sys.modules.pop("ensure_zipapps", None)
Command line usage

Build Args
most common args:
-c
- to compress files, only for python3.7+.
-a xxx.py
- to add some files/folders into the zipped file.
-u=AUTO
- Recommended
- auto unzip the .pyd / .so files
- or
-u=* to unzip all the files
-r requirements.txt
- install requirements with
pip install
-o my_app.pyz
- output the zipped file as given path
-m app.__main__:main
-p /usr/bin/python3
-d
- Recommended
- requirements will be installed with
pip while first running in the lazy install mode
- zip file size will be very small, and the default unzip path is
SELF/zipapps_cache/
--clear-zipapps-cache, -czc
- Clear the zipapps cache folder after running, but maybe failed for .pyd/.so files.
Details:
python3 -m zipapps -h
-h, --help
- show the simple doc
--includes, --add, -a
- The given paths will be copied to
cache_path while packaging, which can be used while running. The path strings will be splited by ",".
- such as
my_package_dir,my_module.py,my_config.json
- often used for libs not from
pypi or some special config files
- the
output arg of zipapps.create_app
--output, -o
- The path of the output file, defaults to
app.pyz.
- the
output arg of zipapps.create_app
--python, -p
- The path of the Python interpreter which will be set as the
shebang line, defaults to None.
- with shebang
/usr/bin/python3 you can run app with ./app.pyz directly, no need for python3 app.pyz
- the
interpreter arg of zipapps.create_app
--main, -m
- The entry point function of the application, the
valid format is:
package.module:function
package.module
module:function
package
- the
main arg of zipapps.create_app
- WARNING: If the
--main arg is set, python3 app.pyz will not be able to used as venv like python3 app.pyz xxx.py
--compress, -c
Boolean value, compress files with the deflate method or not.
- the
compressed arg of zipapps.create_app
--unzip, -u
- The names which need to be unzipped while running, splited by ","
without ext, such as bottle,aiohttp, or the complete path like bin/bottle.py,temp.py. For .so/.pyd files(which can not be loaded by zipimport), or packages with operations of static files.
- if unzip is set to "*", then will unzip all files and folders.
- if unzip is set to AUTO, then will add the
.pyd and .so files automatically.
- Can be overwrite with environment variable
ZIPAPPS_UNZIP
- the
unzip arg of zipapps.create_app
--unzip-exclude, -ue
- The opposite of
--unzip / -u which will not be unzipped, should be used with --unzip / -u.
- Can be overwrite with environment variable
ZIPAPPS_UNZIP_EXCLUDE
--unzip-path, -up
- If
unzip arg is not null, cache files will be unzipped to the given path while running. Defaults to zipapps_cache, support some internal variables as runtime args:
$TEMP/$HOME/$SELF/$PID/$CWD as prefix, for example $HOME/zipapps_cache
TEMP means tempfile.gettempdir()
HOME means Path.home()
SELF means .pyz file path.
$PID means os.getpid()
$CWD means Path.cwd()
- And you can also overwrite it with environment variables:
ZIPAPPS_CACHE or UNZIP_PATH
- the
unzip_path arg of zipapps.create_app
-cc, --pyc, --compile, --compiled
- Compile .py to .pyc for fast import, but zipapp does not work unless you unzip it(so NOT very useful).
- the
compiled arg of zipapps.create_app
--cache-path, --source-dir, -cp
- The cache path of zipapps to store site-packages and
includes files. If not set, will create and clean-up in TEMP dir automately.
- the
cache_path arg of zipapps.create_app
--shell, -s
- Only while
main is not set, used for shell=True in subprocess.run.
- very rarely used, because extra sub-process is not welcome
- the
shell arg of zipapps.create_app
--main-shell, -ss
- Only for
main is not null, call main with subprocess.Popen: python -c "import a.b;a.b.c()". This is used for psutil ImportError of DLL load.
- very rarely used too
- the
main_shell arg of zipapps.create_app
--strict-python-path, -spp
Boolean value. Ignore global PYTHONPATH, only use zipapps_cache and app.pyz.
- the
ignore_system_python_path arg of zipapps.create_app
-b, --build-id
- The string to skip duplicate builds, it can be the paths of files/folders which splited by ",", then the modify time will be used as build_id. If build_id contains
*, will use glob function to get paths. For example, you can set requirements.txt as your build_id by python3 -m zipapps -b requirements.txt -r requirements.txt when you use pyz as venv.
- very rarely used too too
- the
build_id arg of zipapps.create_app
--zipapps, --env-paths
- Default
--zipapps arg if it is not given while running. Support $TEMP/$HOME/$SELF/$PID/$CWD prefix.
--delay, -d, --lazy-pip, --lazy-install, --lazy-pip-install
- Install packages with pip while first running, which means requirements will not be install into pyz file.
--ensure-pip
- Add the ensurepip package to your pyz file, works for embed-python(windows) or other python versions without
pip installed but lazy-install mode is enabled. [EXPERIMENTAL]
--layer-mode
- Layer mode for the
serverless use case, __main__.py / ensure_zipapps.py / activate_zipapps.py files will not be set in this mode.
--layer-mode-prefix
- Only work while
--layer-mode is set, will move the files in the given prefix folder.
--clear-zipapps-cache, -czc
- Clear the zipapps cache folder after running, but maybe failed for .pyd/.so files.
--clear-zipapps-self, -czs
- Clear the zipapps pyz file self after running.
--chmod
- os.chmod(int(chmod, 8)) for unzip files with
--chmod=777
- unix-like system only
--dump-config
- Dump zipapps build args into JSON string.
- A file path needed and
- means stdout.
--load-config
- Load zipapps build args from a JSON file.
--freeze-reqs
- Freeze package versions of pip args with venv, output to the given file path.
- equals to stdout
- logs will be redirect to
stderr
- Based on
pip + venv
- work folder is
tempfile.TemporaryDirectory, prefix='zipapps_'
- all the other (or
unknown) args will be used by pip install
- such as
-r requirements.txt
- such as
bottle aiohttp
- the
pip_args arg of zipapps.create_app
Runtime Args
available args while the .pyz is running
--zipapps