A class providing more control over libraries using pip
Project description
libManager
libManager is a Python class for managing project dependencies, including installation, information retrieval, dependency resolution, and creating a requirements.txt file.
Overview
libManager simplifies dependency management in a project. This class enables:
- Checking installed libraries.
- Automatically installing required libraries.
- Automatically deleting libraries, including their dependencies that are not used in side-libraries.
- Retrieving information about libraries.
- Generating a
requirements.txtfile for dependency management. - Installing/Deleting libraries based on
requirements.txt
Requirements
- Python 3.x
pippackage manager installed
Installation
Download the library:
pip install libManager
Import the libManager class into your project.
from lib_manager import libManager
Usage
1. Initialization
Create an instance of the libManager class:
manager = libManager()
Set target libraries manually:
manager = libManager({"numpy", "pandas"})
Or set them via requirements.txt:
manager = libManager(path_to_requirements="D:\\Projects\\Default\\requirements.txt")
Or do both 😳:
manager = libManager({"aiohttp"}, "D:\\Projects\\Telegram bot\\requirements.txt")
You can also manage to install all of the stated libraries at the beginning or not via init_at_start argument:
#By default it is set to True
libManager(init_at_start = False)
2. Retrieving a Set of Installed Libraries
Use the get_installed_libs method to retrieve a list of installed libraries:
installed_libs = manager.get_installed_libs()
3. Getting Details of The Library
If you need to get information about specific library from pip in convenient format, call the get_lib_details method:
manager.get_lib_details("numpy")
This methods returns dictionary, containing the following keys of the library:
- name: str
- version: str
- summary: str
- home-page: str
- author: str
- author-email: str
- license: str
- location: str
- requires: set[str]
- required-by: set[str]
4. Getting All Dependencies of The Library
If you need to get all libraries that are being used in the library, call the get_all_dependencies method:
dependencies: set[str] = manager.get_all_dependencies("numpy")
It should be noted that this information depends on the result of 'pip show' command. If dependencies are not stated in pip, the function will return an empty set
5. Installing Libraries
To install a set of required libraries, call the following method:
manager.init_libs()
6. Deleting Libraries
To delete all of the libraries that are stated libraries_needed, including their dependencies, call the deinit_libs method:
#Initialize libraries we need
manager = libManager({'numpy', 'pandas'})
import numpy
import pandas
#Work goes here
#Shall we clean up after hard work?
manager.deinit_libs()
It should be noted that it deletes only those libraries that are not used in other side-libraries.
7. Creating a requirements.txt File
To create a requirements.txt file, use create_actual_requirements:
manager = libManager()
manager.create_actual_requirements("*path_to_file*.py")
Thus, libManager will try to create requirements.txt based only on your project file.
However, if there are libraries that practically can not be got from the file, you can directly state them in additional_libs argument:
manager.create_actual_requirements("*path_to_file,py*", additional_libs={"aiohttp"})
8. Getting Libraries From requirements.txt File
To get libraries from requirements.txt, call add_libs_from_requirements method:
manager.add_libs_from_requirements("D:\\Projects\\Hard project\\requirements.txt")
It has to be noted that libManager only recognises file with the appropriate name.
9. Deleting Libraries From libManager by requirements.txt File
If at some point you want to stop working with libraries from requirements.txt, remove them via remove_libs_by_requirements method
manager.remove_libs_by_requirements("D:\\Projects\\Hard project\\requirements.txt")
Methods
get_installed_libs: Returns a set of installed libraries. Can focribly get update of installed libraries via settingupdateargument toTrueget_lib_details: Returns a dictionary with information about specific library. Information can also be found in pip viapip show [library_name]commandget_all_dependencies: Recursively returns a set of libraries that are needed for specific library to run. It can take a plenty of time.create_actual_requirements: Creates a requirements.txt file basing on targetfile.py.add_libs_from_requirements: Adds libraries tolibManagerfromrequirements.txt.remove_libs_by_requirements: Removes libraries fromlibManagerbasing onrequirements.txtinit_libs: Installs specified libraries basing onlibraries_needed.deinit_libs: Delets specified libraries and their dependencies basing onlibraries_needed
License
This project is licensed under the MIT License.
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 Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file libManager-0.1.2.tar.gz.
File metadata
- Download URL: libManager-0.1.2.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26826c2dcea82c6608691f8d02d09e8c0cbd5c3ec4adfb48657dadf57b247271
|
|
| MD5 |
d823309a8cf587ae46ee8e6f3010937a
|
|
| BLAKE2b-256 |
a71a26e014de5ece8a6f8ef71b9cd55eb887e8b3f12c010281d84d6c224d1f12
|
File details
Details for the file libManager-0.1.2-py3-none-any.whl.
File metadata
- Download URL: libManager-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffd35bf906993a4e99e0d70fc9e12c002c9ea845e1c132903dadcb696e36e238
|
|
| MD5 |
e0d92694c07faa2c3a84782c999ed18f
|
|
| BLAKE2b-256 |
3f6d13dd6bac3e9727d05686cecbeabbcc2125bc35fbaa472dbd31db0928855d
|