An optimized utility library for directory, file, image, and JSON operations.
Project description
Optimized Utility Library
Overview
This library provides optimized utility functions for directory operations, file operations, image processing, and JSON handling. It is designed to be highly efficient and easy to use, making common tasks simpler and faster.
Installation
You can install the library using pip:
pip install optimized-utility-library
Usage
Below are examples of how to use the various functionalities provided by the library.
Directory Operations
Ensure a Directory Exists
from utility_lib.common.directory_operations import ensure_dir
directory_path = "path/to/directory"
ensure_dir(directory_path)
List Files in a Directory
from utility_lib.common.directory_operations import list_files
directory_path = "path/to/directory"
files = list_files(directory_path, pattern="*.txt", recursive=True)
print(files)
Setup Multiple Directories
from utility_lib.common.directory_operations import setup_directories
config = {
"dir1": "path/to/dir1",
"dir2": "path/to/dir2"
}
setup_directories(config)
Check if a Directory Has Changed
from utility_lib.common.directory_operations import has_directory_changed
directory_path = "path/to/directory"
state_file = "path/to/state.json"
changed = has_directory_changed(directory_path, state_file)
print(changed)
Get Latest Files from a Directory
from utility_lib.common.directory_operations import get_latest_files
directory_path = "path/to/directory"
latest_files = get_latest_files(directory_path, num_files=5, file_ext=".txt")
print(latest_files)
File Operations
Read and Write Files
from utility_lib.common.file_operations import read_file, write_file
file_path = "path/to/file.txt"
content = "Hello, World!"
# Write content to a file
write_file(file_path, content)
# Read content from a file
read_content = read_file(file_path)
print(read_content)
Append to a CSV File
from utility_lib.common.file_operations import append_to_csv
row = ["name", "age", "city"]
csv_file_path = "path/to/file.csv"
append_to_csv(row, csv_file_path)
Delete a File
from utility_lib.common.file_operations import delete_file
file_path = "path/to/file.txt"
delete_file(file_path)
Image Operations
Display an Image
from utility_lib.common.image_operations import display_img
image_path = "path/to/image.jpg"
display_img(image_path)
Convert Image to Base64
from utility_lib.common.image_operations import image_to_base64
image_path = "path/to/image.jpg"
base64_string = image_to_base64(image_path)
print(base64_string)
Resize an Image
from utility_lib.common.image_operations import resize_image
image_path = "path/to/image.jpg"
output_path = "path/to/resized_image.jpg"
size = (800, 600)
resize_image(image_path, size, output_path)
JSON Operations
Load and Save JSON Data
from utility_lib.common.json_operations import load_json, save_json
json_path = "path/to/file.json"
data = {"key": "value"}
# Save JSON data to a file
save_json(json_path, data)
# Load JSON data from a file
loaded_data = load_json(json_path)
print(loaded_data)
Update JSON Key
from utility_lib.common.json_operations import update_json_key
json_data = {"key1": "value1"}
update_json_key(json_data, "key2", "value2")
print(json_data)
Get JSON Key with Default
from utility_lib.common.json_operations import get_json_key
json_data = {"key1": "value1"}
value = get_json_key(json_data, "key2", "default_value")
print(value)
LLM Image Operations
Revise Image for LLM
from utility_lib.common.llm_image_operations import revise_image_for_llm
image_path = "path/to/image.jpg"
mode = "low" # or "high"
revise_image_for_llm(image_path, mode)
Batch Revise Images for LLM
from utility_lib.common.llm_image_operations import batch_revise_images_for_llm
image_paths = ["path/to/image1.jpg", "path/to/image2.jpg"]
mode = "low"
batch_revise_images_for_llm(image_paths, mode)
Process Last N Images
from utility_lib.common.llm_image_operations import process_last_n_images
folder_path = "path/to/folder"
output_folder = "path/to/output_folder"
num_images = 10
quality = "high"
processed_images = process_last_n_images(folder_path, num_images, output_folder, quality)
print(processed_images)
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
Close
Hashes for optimized-utility-library-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f341de764e83101df432a245053a24643b3422950bf1b0acc9953a0d62dc68b |
|
MD5 | 0bb95b1fa6f0a6323e3c6c1c305657d5 |
|
BLAKE2b-256 | e74b8620b86dc17aa7737c402c7d721fe6ba8c95b73cbb87791ee8f7e8c6149f |
Close
Hashes for optimized_utility_library-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bc96e891ee26a808e6fd8a3601f0def78c2d000196e1a78b6d2d07f125b2e50 |
|
MD5 | a8f31cc0708dcc92ec7c66868ea3271c |
|
BLAKE2b-256 | ef575de81effb9ec39ea463d857dbaed94e0e6f86f15eae9a775a70d2e2ba85f |