zipapp-utils
zipapp utilities
Features
- Creating application archive (
.pyzfiles) likepython -m zipappdoes, but with convenient features. - Create shell scripts that bundle a python scripts with all of its dependencies, and can be executable on any system that has
python3 >= 3.5installed.
Demo
See Generate a shell script that bundles and runs a python script
Install, Upgrade and Uninstall
pipx (recommended)
pipx install zipapp-utils
About pipx
pip
pip install zipapp-utils
Usage
zipapp-utils
zipapp-utils is the base command.
zau is an installed alias for zipapp-utils, you can use them interchangeably.
$ zipapp-utils --help # or zau --help
usage: zipapp-utils [-h] [-V] {py2pyz,p,create-archive,ca,zipapp,create-shell-script,sh} ...
zipapp utilities
positional arguments:
{py2pyz,p,create-archive,ca,zipapp,create-shell-script,sh}
py2pyz (p) Create archive from a python script
create-archive (ca, zipapp)
Create a zipapp archive
create-shell-script (sh)
Create an ASCII shellscript that runs a zipapp archive
options:
-h, --help show this help message and exit
-V, --version show program's version number and exit
zipapp-utils py2pyz
Create archive from a python script
$ zau p --help
usage: zipapp-utils py2pyz [-h] [-d DEP] [-r [REQUIREMENT]] [--output OUTPUT] [--python PYTHON] [--main MAIN] [--compress] SCRIPT
Create archive from a python script
positional arguments:
SCRIPT Python script file
options:
-h, --help show this help message and exit
-d DEP, --dep DEP Add dependency
-r [REQUIREMENT], --requirement [REQUIREMENT]
Install dependencies from the given requirements file. Defaults to "requirements.txt"
--output OUTPUT, -o OUTPUT
The name of the output archive. Required if SOURCE is an archive.
--python PYTHON, -p PYTHON
The name of the Python interpreter to use (default: no shebang line).
--main MAIN, -m MAIN The main function of the application (default: use an existing __main__.py).
--compress, -c Compress files with the deflate method. Files are stored uncompressed by default.
zipapp-utils create-archive
Create a zipapp archive (.pyz file)
$ zau ca --help
usage: zipapp-utils create-archive [-h] [--output OUTPUT] [--python PYTHON] [--main MAIN] [--compress] [--info] source
Create a zipapp archive
positional arguments:
source Source directory (or existing archive).
options:
-h, --help show this help message and exit
--output OUTPUT, -o OUTPUT
The name of the output archive. Required if SOURCE is an archive.
--python PYTHON, -p PYTHON
The name of the Python interpreter to use (default: no shebang line).
--main MAIN, -m MAIN The main function of the application (default: use an existing __main__.py).
--compress, -c Compress files with the deflate method. Files are stored uncompressed by default.
--info Display the interpreter from the archive.
zipapp-utils create-shell-script
Create an ASCII shellscript that runs a zipapp archive
$ zau sh --help
usage: zipapp-utils create-shell-script [-h] [-o OUTPUT] PYTHON_APPLICATION_ARCHIVE
Create an ASCII shellscript that runs a zipapp archive
positional arguments:
PYTHON_APPLICATION_ARCHIVE
Path to the pyz file
options:
-h, --help show this help message and exit
-o OUTPUT, --output OUTPUT
Path to the output file, or stdout if not set
Examples
Generate a shell script that bundles and runs a python script
As described in the Why did you make this? section.
See Demo for a recording of the process.
# make an executable, compressed .pyz file from the script post_status.py, with dependencies pysnc and requests-oauthlib, outputs to test.pyz
zau p post_status.py -d pysnc -d requests-oauthlib -o test.pyz -c
# run test.pyz to verify it works
./test.pyz
# create a shell script that runs test.pyz
zau sh test.pyz -o test.sh
# run test.sh to verify it works
./test.sh
# if it works, just copy the content of test.sh and paste it into a jenkins textbox that runs the script.
# make sure python3 >= 3.5 is installed on the jenkins executor node.
Why did you make this?
This project was created because I needed to run a python script with some dependencies in on a managed Jenkins environment,
and I wasn't able to install any software (including pypi packages) on the node.
I tried to bundle the pypi dependency in my script.
The closest I've tried was to use pyinstaller, which allows you to compile a single executable from a python script. It compiled and ran on my Linux box, but not on the Jenkins node because of incompatible glibc version used by python in the binary.
Then I remembered the zipapp module, which allowed me to use this script on Jenkins:
#!/usr/bin/env bash
ENCODED_PYZ_FILE='{{ encoded_pyz_file }}'
echo -n "${ENCODED_PYZ_FILE}" | base64 -d > /tmp/pyz.pyz
python3 /tmp/pyz.pyz
And voila, it worked!
So I decided to create this project to ease the process of creating such shell scripts for use on Jenkins.
Changelog
Metadata
Release files for zipapp-utils 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| zipapp-utils-0.3.1.tar.gz | 16.6 kB | Without provenance | Details for zipapp-utils-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| zipapp_utils-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for zipapp_utils-0.3.1-py3-none-any.whl |
Total release size: 34.9 kB
Release files / zipapp-utils-0.3.1.tar.gz
| Download URL | zipapp-utils-0.3.1.tar.gz |
|---|---|
| Size | 16.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2b09616a9b62ccdf3fbbda6104d51c9db13404ec0a074fd7fef805f2c0c6601d
|
|
BLAKE2b-256 checksum How to use checksums |
55eff9b884ab9eac422c1db3ce65b0da23b43aaca8c4f5bd55da64c2ca11fb02
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.0b2 CPython/3.10.4 Darwin/21.5.0
|
Release files / zipapp_utils-0.3.1-py3-none-any.whl
| Download URL | zipapp_utils-0.3.1-py3-none-any.whl |
|---|---|
| Size | 18.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4f9f52778caef362ba58ae7c9c3441e5888306f3cf497c51c9a087a5debf0039
|
|
BLAKE2b-256 checksum How to use checksums |
e51a471a9c0c1218a45be66738992c6890a718075e62902fbdba40c04e9eefe3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.0b2 CPython/3.10.4 Darwin/21.5.0
|
Security for zipapp-utils 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.