Skip to main content

A versatile Python utility library that offers a wide range of helper functions, classes, and modules to expedite development tasks and simplify common operations

Project description

SimpleUtilz.py - Python Utility Library

SimpleUtilz is a versatile Python utility library that offers a wide range of helper functions, classes, and modules to expedite development tasks and simplify common operations. With SimpleUtilz, you can streamline your Python projects and enhance productivity through a collection of useful functionalities.

Installation

You can install SimpleUtilz using pip:

pip install simpleutilz

Functionality and Usage

File Handling Functions

create_directory(directory_path) Create a directory if it does not exist.

from simpleutilz.simpleutilz import create_directory

directory_path = '/path/to/directory'
create_directory(directory_path)

delete_file(file_path) Delete a file if it exists.

from simpleutilz.simpleutilz import delete_file

file_path = '/path/to/file.txt'
delete_file(file_path)

Data Manipulation Tools

merge_dicts(*dicts) Merge multiple dictionaries into a single dictionary.

from simpleutilz.simpleutilz import merge_dicts

dict1 = {'a': 1, 'b': 2}
dict2 = {'c': 3, 'd': 4}
merged_dict = merge_dicts(dict1, dict2)
print(merged_dict)  # Output: {'a': 1, 'b': 2, 'c': 3, 'd': 4}

String Utilities

capitalize_first_letter(input_string) Capitalize the first letter of a given string.

from simpleutilz.simpleutilz import capitalize_first_letter

input_string = 'hello world'
capitalized_string = capitalize_first_letter(input_string)
print(capitalized_string)  # Output: 'Hello world'

remove_whitespace(input_string) Remove leading and trailing whitespace from a string.

from simpleutilz.simpleutilz import remove_whitespace

input_string = '   hello world   '
cleaned_string = remove_whitespace(input_string)
print(cleaned_string)  # Output: 'hello world'

Date and Time Utilities

get_formatted_datetime(format_str="%Y-%m-%d %H:%M:%S") Get the current date and time in a formatted string.

from simpleutilz.simpleutilz import get_formatted_datetime

formatted_time = get_formatted_datetime("%Y-%m-%d")
print(formatted_time)  # Output: '2023-07-20'

Logging Module

log_error(message) Log an error message to the console or a file (if configured).

import logging
from simpleutilz.simpleutilz import log_error

logging.basicConfig(filename='error.log', level=logging.ERROR)
try:
    # Some code that may raise an exception
    raise ValueError("Something went wrong!")
except Exception as e:
    log_error(str(e))

Network Utilities

download_file(url, save_path) Download a file from a given URL and save it to the specified path.

from simpleutilz.simpleutilz import download_file

file_url = 'https://example.com/some_file.txt'
save_path = '/path/to/save/file.txt'
download_file(file_url, save_path)

extract_zip(zip_file_path, extract_to) Extract files from a ZIP archive to the specified directory.

from simpleutilz.simpleutilz import extract_zip

zip_file_path = '/path/to/archive.zip'
extract_to = '/path/to/extract'
extract_zip(zip_file_path, extract_to)

extract_tar(tar_file_path, extract_to) Extract files from a TAR archive to the specified directory.

from simpleutilz.simpleutilz import extract_tar

tar_file_path = '/path/to/archive.tar.gz'
extract_to = '/path/to/extract'
extract_tar(tar_file_path, extract_to)

get_domain_from_url(url) Extract the domain name from a given URL.

from simpleutilz.simpleutilz import get_domain_from_url

url = 'https://www.example.com/some/page.html'
domain = get_domain_from_url(url)
print(domain)  # Output: 'www.example.com'

Other Utilities

generate_random_string(length=10) Generate a random string of a specified length.

from simpleutilz.simpleutilz import generate_random_string

random_str = generate_random_string(8)
print(random_str)  # Output: 'JwB45XzQ'

is_prime(number) Check if a given number is a prime number.

from simpleutilz.simpleutilz import is_prime

number = 17
if is_prime(number):
    print(f"{number} is a prime number.")
else:
    print(f"{number} is not a prime number.")

load_json(file_path) Load JSON data from a file and return it as a Python dictionary.

from simpleutilz.simpleutilz import load_json

file_path = '/path/to/data.json'
data = load_json(file_path)
print(data)  # Output: {'name': 'John Doe', 'age': 30, 'email': 'john@example.com'}

calculate_average(numbers) Calculate the average of a list of numbers.

from simpleutilz.simpleutilz import calculate_average

numbers = [12, 34, 56, 78, 90]
average = calculate_average(numbers)
print(average)  # Output: 54.

calculate_median(numbers) Calculate the median of a list of numbers.

from simpleutilz.simpleutilz import calculate_median

numbers = [12, 34, 56, 78, 90]
median = calculate_median(numbers)
print(median)  # Output: 56

flatten_list(nested_list) Flatten a nested list into a single-dimensional list.

from simpleutilz.simpleutilz import flatten_list

nested_list = [[1, 2, 3], [4, [5, 6]], [7], 8]
flattened_list = flatten_list(nested_list)
print(flattened_list)  # Output: [1, 2, 3, 4, 5, 6, 7, 8]

remove_duplicates(input_list) Remove duplicates from a list while preserving the order.

from simpleutilz.simpleutilz import remove_duplicates

input_list = [1, 2, 2, 3, 4, 3, 5]
unique_list = remove_duplicates(input_list)
print(unique_list)  # Output: [1, 2, 3, 4, 5]

is_valid_email(email) Check if a given string is a valid email address.

from simpleutilz.simpleutilz import is_valid_email

email = 'john@example.com'
if is_valid_email(email):
    print(f"{email} is a valid email address.")
else:
    print(f"{email} is not a valid email address.")

is_valid_url(url) Check if a given string is a valid URL.

from simpleutilz.simpleutilz import is_valid_url

url = 'https://www.example.com'
if is_valid_url(url):
    print(f"{url} is a valid URL.")
else:
    print(f"{url} is not a valid URL.")

is_valid_ipv4(ip) Check if a given string is a valid IPv4 address.

from simpleutilz.simpleutilz import is_valid_ipv4

ip = '192.168.1.1'
if is_valid_ipv4(ip):
    print(f"{ip} is a valid IPv4 address.")
else:
    print(f"{ip} is not a valid IPv4 address.")

read_config_file(config_file_path) Read a configuration file (e.g., .ini, .yaml) and return it as a dictionary.

from simpleutilz.simpleutilz import read_config_file

config_file_path = '/path/to/config.ini'
config_data = read_config_file(config_file_path)
print(config_data)

write_config_file(config_dict, file_path) Write a dictionary as a configuration file.

from simpleutilz.simpleutilz import write_config_file

config_dict = {'Section1': {'key1': 'value1', 'key2': 'value2'}, 'Section2': {'key3': 'value3'}}
file_path = '/path/to/config.ini'
write_config_file(config_dict, file_path)

generate_encryption_key() Generate a new encryption key.

from simpleutilz.simpleutilz import generate_encryption_key

encryption_key = generate_encryption_key()
print(encryption_key)

encrypt_string(text, key) Encrypt a string using a symmetric encryption algorithm.

from simpleutilz.simpleutilz import encrypt_string

text = 'This is a secret message.'
key = b'some_random_key'
encrypted_text = encrypt_string(text, key)
print(encrypted_text)

decrypt_string(encrypted_text, key) Decrypt an encrypted string using the same key.

from simpleutilz.simpleutilz import decrypt_string

encrypted_text = b'encrypted_data_here'
key = b'some_random_key'
decrypted_text = decrypt_string(encrypted_text, key)
print(decrypted_text)

convert_pdf_to_text(pdf_file_path) Convert a PDF file to plain text.

from simpleutilz.simpleutilz import convert_pdf_to_text

pdf_file_path = '/path/to/sample.pdf'
pdf_text = convert_pdf_to_text(pdf_file_path)
print(pdf_text)

Convert Hex to Denary

from simpleutilz.simpleColours import convert_value_to_denary

hexValue = '#ffffff'
denary = convert_value_to_denary(hexValue, "hex")
print(denary)

Convert RGB to Denary

from simpleutilz.simpleColours import convert_value_to_denary

rgbValue = (255, 255, 255)
denary = convert_value_to_denary(rgbValue, "rgb")
print(denary)

Convert RGBA to Denary

from simpleutilz.simpleColours import convert_value_to_denary

rgbaValue = (255, 255, 255, 1)
denary = convert_value_to_denary(rgbaValue, "rgba")
print(denary)

Convert Binary to Denary

from simpleutilz.simpleColours import convert_value_to_denary

binaryValue = '11111111'
denary = convert_value_to_denary(binaryValue, "binary")
print(denary)

Convert RGB code to Colour in English

from simpleutilz.simpleColours import RGB_to_colour

rgbValue = (255, 255, 255)
colour = RGB_to_colour(rgbValue)
print(colour)

Convert Hex code to Colour in English

from simpleutilz.simpleColours import hex_to_colour

hexValue = '#ffffff'
colour = hex_to_colour(hexValue)
print(colour)

Convert RGBA code to Colour in English

from simpleutilz.simpleColours import RGBA_to_colour

rgbaValue = (255, 255, 255, 1)
colour = RGBA_to_colour(rgbaValue)
print(colour)

Convert Binary code to Colour in English

from simpleutilz.simpleColours import binary_to_colour

binaryValue = '11111111'
colour = binary_to_colour(binaryValue)
print(colour)

Contributing

Contributions to SimpleUtilz are welcome! If you find any bugs, have new ideas, or want to improve the existing functionality, please open an issue or submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

The SimpleUtilz library offers an extensive array of functions to simplify tasks and boost productivity in Python projects. The README.md provides detailed explanations and examples for each function, enabling users to grasp the functionalities swiftly and incorporate them seamlessly into their projects. Should you encounter any issues or have suggestions for improvements, do not hesitate to contribute or reach out to me!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simpleutilz-1.1.6.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simpleutilz-1.1.6-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file simpleutilz-1.1.6.tar.gz.

File metadata

  • Download URL: simpleutilz-1.1.6.tar.gz
  • Upload date:
  • Size: 18.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for simpleutilz-1.1.6.tar.gz
Algorithm Hash digest
SHA256 a9b4d8ccb74240e0d23215934b38a0ba4d9f2b72386ebb3cdb4ab4cd8e616ac6
MD5 21478ca9696750c2fb4fc0124cdb5f2d
BLAKE2b-256 1b8b467596003673de1012734a22bf8bea9c2c7d2aa66f1606690d52a952edf5

See more details on using hashes here.

File details

Details for the file simpleutilz-1.1.6-py3-none-any.whl.

File metadata

  • Download URL: simpleutilz-1.1.6-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for simpleutilz-1.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 ec5d3fe1a912286237f9039faa9f9965d419c0e4e324a1e04f203b724703f10d
MD5 93c00b0cfb305ab602127a4d8ac6b153
BLAKE2b-256 69e9095135cb034d528e03e5e2f905865fe79675be15ee54ad4bd81f1727e0eb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page