UtilityLib
UtilityLib is a unified library of basic modules that provides a collection of ready-to-use functions for various file system oprerations and data processing.
Installation
- You can install UtilityLib via pip or by copying the UtilityLib directory into your project.
- Using pip:
pip install UtilityLib - Using pip+GitHub:
pip install git+https://github.com/yourusername/UtilityLib.git
Usage/Examples
Here are some examples demonstrating how to use UtilityLib's key features:
Initialize UtilityLib's ProjectManager or any other class in the chain
UtilityLib provides flexible import options for different use cases:
# Initialize it with setting current working directory as base_path provided
from UtilityLib import ProjectManager
MyProj = ProjectManager(path_base="path/to/your/project/dir")
# Or change directory in runtime
MyProj.path_base = 'path/to/some-other/directory'
print(MyProj.config_version, MyProj.config_subversion, MyProj.path_base)
File Path Operations
# Change current working directory
# List all files (Refer UtilityLib.lib.path.EntityPath for more options )
_proj_path = MyProj.path_base
# Walk Files and Dirs using iterator (memory efficient) or list them all
_walk_dirs = _proj_path.walk_dirs
_walk_files = _proj_path.walk_filess
# List direct files and directories/folders in project
_all_files = _proj_path.files
_all_dirs = _proj_path.dirs
# Get tree of the directory (Linux's tree equivalent)
print(_proj_path.tree) # use _proj_path.tree_gen (generator method) if you think there are too many files
# Pick matching file or search multiple files
_my_single_excel_file = _proj_path.get_match('*Excel-2025*.xlsx')
_my_jpg_files = _proj_path.search("*2025*.jpg")
# Tip: rename, move, or copy using (refer )
# Create new path on go, it returns UtilityLib.lib.path.EntityPath object
_my_new_sub_path: EntityPath = (MyProj.path_base / 'New-Dir' / 'Sub-Dir').validate()
# Use EntityPath delete method to delete files or folders. You need to turn off is_protected to delete else it raises warning
_my_new_sub_path.delete(is_protected=False)
Some quick file operations
_mfpo = _my_file_path_obj = (MyProj.path_base / 'My-Excel-File.xlsx')
print(_mfpo.stem, _mfpo.name, _mfpo.suffix) # Prints file names and extension
print(_mfpo.with_suffix('.2025-05-2022.xlsx')) # Changes file extension
print(_mfpo.created) # Prints date of the file creation
print(_mfpo.updated) #
print(_mfpo.exists()) # Does file exists?
print(_mfpo.copy('/New/Location/Copy-dir/'))
print(_mfpo.copy('/New/Location/Copy-dir/with-new-name.xlsx'))
print(_mfpo.move('/New/Location/Move-dir/with-new-name.xlsx'))
Project Configuration Management
from UtilityLib import ProjectManager
# Initialize project manager with cross-platform paths
MyProj = ProjectManager(
path_bases=("/mnt/D/DataDrive", "D:/path-windows"),
version=2,
subversion=202211 # To load specific sub config
)
# Add new configuration values
MyProj.config.database.connection_string = "sqlite:///data.db"
MyProj.config.processing.batch_size = 1000
# Update existing configuration
MyProj.update_config()
# Save configuration with new subversion
MyProj.update_config(subversion=20221103)
File Compression and Cleanup
# Create compressed archive
MyProj.add_tgz_files("/data/WOS-Downloads.tgz", csv_files)
# Clean up original directory
MyProj.delete_path("/data/WOS-Downloads")
Classes and Modules
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
utilitylib-2.21.4.tar.gz
(77.3 kB
view details)
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 utilitylib-2.21.4.tar.gz.
File metadata
- Download URL: utilitylib-2.21.4.tar.gz
- Upload date:
- Size: 77.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3f7df801415757b59c12af591123825cf61fc4d50687a30bfe07351b1cc06ae
|
|
| MD5 |
6b89f6a1296ffcdbf3ccb200cc9491f0
|
|
| BLAKE2b-256 |
00c2f435259ae24d3f09a541abbab09eecf33877b883c8d27a8498efd6f84779
|
File details
Details for the file utilitylib-2.21.4-py3-none-any.whl.
File metadata
- Download URL: utilitylib-2.21.4-py3-none-any.whl
- Upload date:
- Size: 84.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b706f61b7371aee1c081afc1cc67dcea3a88e827d14947c2866bac20855054cb
|
|
| MD5 |
099f947ea501de20d575bea3e877645d
|
|
| BLAKE2b-256 |
621a86131e1ff7f09a5dfee10e86662815bc1c1282ada71b4b121a9b33877fd7
|