Package your python code into one zip file, even a virtual environment.
Project description
zipapps ![PyPI](https://pypi-camo.freetls.fastly.net/fdd190c5f9d73d0fd5b2683c8cb503df65302eed/68747470733a2f2f696d672e736869656c64732e696f2f707970692f762f7a6970617070733f7374796c653d706c6173746963)
![GitHub Workflow Status](https://pypi-camo.freetls.fastly.net/cd150353a7fdb29af3a0b11e20d239d4df12fc52/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f636c6572696370792f7a6970617070732f507974686f6e2532307061636b6167653f7374796c653d706c6173746963)
![PyPI - Wheel](https://pypi-camo.freetls.fastly.net/20b6a42c5fcf5544010bddaed88b04bba09481eb/68747470733a2f2f696d672e736869656c64732e696f2f707970692f776865656c2f7a6970617070733f7374796c653d706c6173746963)
![PyPI - Python Version](https://pypi-camo.freetls.fastly.net/3834735d54ad9d121f2616fc8187c8a80c0d76a9/68747470733a2f2f696d672e736869656c64732e696f2f707970692f707976657273696f6e732f7a6970617070733f7374796c653d706c6173746963)
![PyPI - Downloads](https://pypi-camo.freetls.fastly.net/8e627ad180b1bb0fcb1667861996443046e0460a/68747470733a2f2f696d672e736869656c64732e696f2f707970692f646d2f7a6970617070733f7374796c653d706c6173746963)
![PyPI - License](https://pypi-camo.freetls.fastly.net/260a4d74718f2631f37dae423d23652f2c1fae0d/68747470733a2f2f696d672e736869656c64732e696f2f707970692f6c2f7a6970617070733f7374796c653d706c6173746963)
Package your python code into one zip file, even a virtual environment. Also compatible for win32.
Inspired by shiv, to publish applications easily. Unlike shiv, this lib will not create cache folders while running apps.
Requirements
Only python3.6+
Install
pip install zipapps -U
Usage
python3 -m zipapps -h
usage:
===========================================================================
0. package your code without any requirements
> python3 -m zipapps -c -a ./simple_package -p /usr/bin/python3 -o simple_package.pyz
> ./simple_package.pyz
OR
> python3 -m zipapps -c -a ./simple_package -o simple_package.pyz
> python3 simple_package.pyz
------------------------------------
1. use zipapps to make a standalone app which need bottle installed
> python3 -m zipapps -c -a bottle_server.py -m bottle_server:main bottle
> python3 app.pyz
OR
> python3 -m zipapps -c -a bottle_server.py -m bottle_server:main bottle
> python3 app.pyz
------------------------------------
2. use zipapps for venv
> python3 -m zipapps -c bottle
> python3 app.pyz bottle_server.py
OR
> python3 -m zipapps -c -p /usr/bin/python3 bottle
> ./app.pyz bottle_server.py
------------------------------------
3. advanced usages
3.1 more args
> python3 -m zipapps -c -a package1,package2 -o server.pyz -m package1.server:main -p /usr/bin/python3 -r requirements.txt
> ./server.pyz
3.2 unzip C-libs to cache folder for zipimport do not support .so .pyd files.
bad
> python3 -m zipapps -c lxml
> python3 app.pyz -c "import lxml.html;print(lxml.html.__file__)"
good
> python3 -m zipapps -c -u lxml lxml
> python3 app.pyz -c "import lxml.html;print(lxml.html.__file__)"
PS: all the unknown args will be used by "pip install".
===========================================================================
optional arguments:
-h, --help show this help message and exit
--output OUTPUT, -o OUTPUT
The name of the output file, defaults to "app.pyz".
--python INTERPRETER, -p INTERPRETER
The name of the Python interpreter to use (default: no shebang line).
--main MAIN, -m MAIN The main function of the application. Format like package.module:function.
--compress, -c Compress files with the deflate method, defaults to uncompressed.
--includes INCLUDES, -a INCLUDES
The files/folders of given dir path will be copied into cache-path, which can be import from PYTHONPATH). The path string will be splited by ",".
--cache-path CACHE_PATH, -cp CACHE_PATH
The cache path of zipapps to store site-packages and `includes` files, which will be treat as PYTHONPATH. If not set, will create and clean-up automately.
--unzip UNZIP, -u UNZIP
The names which need to be unzip while running, name without ext. such as .so/.pyd files(which can not be loaded by zipimport), or packages with operations of static files. If unzip is *, will unzip all files and folders.
--unzip-path UNZIP_PATH, -up UNZIP_PATH
The names which need to be unzip while running, name without ext. such as .so/.pyd files(which can not be loaded by zipimport), or packages with operations of static files. Defaults to $(appname)_unzip_cache
--shell, -s Only while `main` is not set, used for shell=True in subprocess.Popen
--strict-python-path, -spp
Ignore global PYTHONPATH, only use app_unzip_cache and app.pyz.
FAQ
- How to zip apps with C-lib requirements for
zipimport
ingore.pyd
,.so
files?- as https://docs.python.org/3/library/zipimport.html
- we can unzip those packages in temp dirs with
-u
args -
python3 -m zipapps -c -u selectolax selectolax
-
python3 app.pyz xxx.py
- How to avoid unlimited unzip cachefolder size growth?
- There is a null file named like
zip-time
in zip files and unzip folders - The same
zip-time
cache with same name will not unzip again.
- There is a null file named like
PYTHONPATH
between zipapps's zip file and global python environment?- If you set
-spp
for strictPYTHONPATH
, you will not use the globalPYTHONPATH
. - else you will use global libs as a second choice.
- If you set
- Where to Use it?
- Hadoop-Streaming's mapper & reducer.
- Simple deployment for different server with Jenkins(or other CI/CD tools).
- Distribute zipapp with embedded python.
- Other usages need to be found, and enjoy yourself.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for zipapps-2020.10.22-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7bd2015f54c36a1557ee1f6a502531017c80a6106b36551cc588fcbbac60d17 |
|
MD5 | 6478d9f87f6bedd0d89e46e2972703c2 |
|
BLAKE2b-256 | 8b04e696893a2689da3e090f85aaedc61e457fd421c6b928a451154d4a021a66 |