Downloads and installs files
Simple light API to download and install files. If the file appears to be a
compressed file by ending with zip, tar.gz, tgz etc, then also un-compress
the file after it is downloaded. The process flow follows:
- Check to see if the installed file exists. If not download it.
- Otherwise, if the file has been downloaded uncompress it.
- If the file could not be downloaded, uncompressed, or a file from the uncompressed file isn't found an error is thrown.
A destination location can be specified in the configuration. It is also
possible to install it in the ~/.cache/<package name> where package name is
the name the installed package. For example, that would be zensols.install
for the package installed for this repository.
Documentation
Obtaining
The easiest way to install the command line program is via the pip installer:
pip3 install zensols.install
Binaries are also available on pypi.
Usage
The below code is given in the example.
First create the installer configuration with each file to be installed as a
resource as a file install.conf:
[build_resource]
class_name = zensols.install.Resource
url = https://github.com/plandes/zenbuild/archive/refs/tags/general_build.zip
# we have to give the name of the diretory in the zip file so the program knows
# what to unzip; otherwise it is named from the section, or file if `None`
name = zenbuild-general_build
# a file in the compressed archive to access; also used to indicate it was
# (already) extracted
sub_path = src/python/gtagutil
# uncomment below to keep the `zenbuild-general_build.zip` zip file
#clean_up = False
[downloader]
class_name = zensols.install.Downloader
#use_progress_bar = False
[installer]
class_name = zensols.install.Installer
# providing the `downloader` is optional
downloader = instance: downloader
# uncomment the below line, then comment out `base_directory` to use the
# package name (using the zensols.cli.ApplicationFactory--see example); using
# `package_resource` will in install a ~/.<package name> install directory
base_directory = path: install_dir
# give the installer access to the resource
resources = instance: list: build_resource
Now use the configuration to create an Installer and access an file to be uncompressed via a Resource:
import logging
from zensols.config import IniConfig, ImportConfigFactory
from zensols.install import Resource, Installer
logging.basicConfig(level=logging.INFO)
# create the installer
fac = ImportConfigFactory(IniConfig('install.conf'))
installer: Installer = fac.instance('installer')
# print the resources the installer contains
res: Resource
for res in self.installer.resources:
res.write_to_log(logger, depth=1)
# iterate over the paths the installer creates from the resources
path: Path
for path in self.installer:
logger.info(f'resource path: {path}')
# install the files
installer.install()
# access a file
ufile: Path = self.installer.get_singleton_path()
print(f'uncompressed file: {ufile}, exists: {ufile.is_file()}')
# optionally remove any installed files
self.installer.clear()
This code creates a new directory with the un-zipped files in install_dir:
INFO:zensols.install.installer:installing zenbuild-general_build to install_dir/zenbuild-general_build
INFO:zensols.install.download:creating directory: install_dir
INFO:zensols.install.download:downloading https://github.com/plandes/zenbuild/archive/refs/tags/general_build.zip to install_dir/zenbuild-general_build.zip
general_build.zip: 16.4kB [00:00, 40.1kB/s]
INFO:zensols.install.installer:uncompressing install_dir/zenbuild-general_build.zip to install_dir
patool: Extracting install_dir/zenbuild-general_build.zip ...
patool: ... install_dir/zenbuild-general_build.zip extracted to `install_dir'.
INFO:zensols.install.installer:cleaning up downloaded file: install_dir/zenbuild-general_build.zip
First the program checks to see if the target directory (name property in the
zip_resource section) exists. It then downloads it when it can't find either
the target directory or the downloaded file.
If the program is run a second time, there will be no output since the installed directory now exists.
Changelog
An extensive changelog is available here.
Community
Please star this repository and let me know how and where you use this API. Contributions as pull requests, feedback, and any input is welcome.
License
Copyright (c) 2021 - 2026 Paul Landes
Metadata
Release files for zensols-install 1.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| zensols_install-1.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Release files / zensols_install-1.4.0-py3-none-any.whl
| Download URL | zensols_install-1.4.0-py3-none-any.whl |
|---|---|
| Size | 13.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
857bf2a6cdbdf67d64a66f7aefd704e93742bf89c531f6581aaabe780c156d36
|
|
BLAKE2b-256 checksum How to use checksums |
595a9b510fc7f71c567d9ba31967be3687b61175ea692a2144d85f9fe43daab6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.11
|
Security for zensols-install 1.4.0
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.