Package: piphyperd
piphyperdA simple python package to leverage pip programmatically, and via CLI.piphyperdis a wrapper aroundpip; it can provide features like automation or dependencies control within your workflows.About this packageThe reasons behind this package, in alternative to the standardpip(import pip) module, are in the attempt to expose a more stable interface, when programmatically installing or managing python packages, within pipelines or automation workflows.Although it is aPythonmodule, and it is available viaimport pip, by design,pipis not supposed to be a library; every detail is subject to changes for any reason, from the import name itself to its API. It might be better to call the pip's internal APIs differently.PitfallsWhen leveragingpipprogrammatically, there are also other topics worth considering:The pip code assumes that it is in sole control of the global state of the program;pip's code is not thread-safe. If you were to run pip in a thread;pip assumes that once it has finished its work, the process terminates.Furthermore, installing packages under thesys.pathfrom a running Python process might result in unexpected or undesired behaviors.Taking everything into account, still might be necessary, or usefull, handling pip packages within code and automations, as much as possible in controlled manner. The most reliable way to do so, is leveraging pip in asubprocess:# leverage subprocess.Popen to execute pip commandspip_full_cmd:Union[Any]=sorted(self.pip_options+self.packages+self.command_args)process=subprocess.Popen([sys.executableifself.python_pathisNoneelseself.python_path,"-m","pip",command]+pip_full_cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)For further information, continue reading from the source of this topic at thethe official pypauser guide.Install the packageRefer to the officialproject pagefor further information about the package status and releases.To install the latest version, run the following command in your terminal:pipinstall--userpiphyperdAPI overviewOnce installed, you can import the package as followsfrom piphyperd import PipHyperd.
The module is wrapping pip commands in methods, exposed through the objectPipHyperd. You can initialize it by optionally passing pip commands extra options:def__init__(self,*pip_options:Any,python_path:Optional[Path]=None):"""Init method."""# Path to the python binary to useself.python_path:Optional[Path]=python_path# A list of pip packages to install || show || download || uninstallself.packages:List[str]=list()# pip command args, e.g.: pip download testpypi {command_args}self.command_args:List[str]=list()# pip options, e.g.: pip {pip_options} uninstall testpypiself.pip_options:List[str]=list(pip_options)# ...The API exposed conveniently wraps a set of pip commands that can help generating virtual environments, reports of the installed packages, outdated libraries. Thestdoutandstderrare returned by each method, allowing to store the output or to read it in a second instance.Object descriptionTo follow, a brief walkthrough through the methods exposed by thePipHyperdobject,programmaticallyand via theCLIpip freezeOutput installed pip packages in requirements format:# pythonpiphyperd.PipHyperd().freeze()# clipiphyperdfreezepip listList installed pip packages.list_outdated -- True || False to list or not the outdated packages# pythonpiphyperd.PipHyperd("--verbose").list_packages()# the argument "--verbose" is of course optional# List outdated packagespiphyperd.PipHyperd().list(True)# clipiphyperdlistpip show {{ package }}Show information about installed packages.# pythonpiphyperd.PipHyperd("--verbose").show("ansible")# clipiphyperdshow--package<package_name>pip checkVerify installed packages have compatible dependencies.# pythonpiphyperd.PipHyperd().check()# clipiphyperdcheckpipdeptreeRender installed packages with dependencies tree.# pythonpiphyperd.PipHyperd().dependencies_tree()# clipiphyperddependencies-treepip install {{ packages }}Install pip packages.# pythonpiphyperd.PipHyperd("-U").install("ansible","cryptography")# -U is of course optional, set here as example# clipiphyperdinstall--packages<package_name_1><package_name_2><package_name_n>
piphyperdinstall--package<package_name>pip download {{ package }}Download pip packages.# pythonpiphyperd.PipHyperd("-U").download("ansible","pip","cryptography",destination="/your/path/here")# the destination argument is optional# clipiphyperddownload--packagetwine==3.1.1pip uninstall {{ packages }}Uninstall pip packages.piphyperd.PipHyperd().uninstall("ansible","pip","cryptography")# the destination argument is optional# clipiphyperduninstall--packages<package_name_1><package_name_2><package_name_n>
piphyperduninstall--package<package_name>LicenseGNU General Public License v3 (GPLv3)Report a VulnerabilityIf you believe you have found a security vulnerability invenvctl, refer to theTidelift security policy.TheTideliftteam will coordinate the vunerability response and disclosure.Author InformationFrancesco CosentinoI'm a surfer, a crypto trader, and a DevSecOps Engineer with 15 years of experience designing highly-available distributed production environments and developing cloud-native apps in public and private clouds.