Package: simpleutilz
SimpleUtilz.py - Python Utility LibrarySimpleUtilzis a versatile Python utility library that offers a wide range of helper functions, classes, and modules to expedite development tasks and simplify common operations. WithSimpleUtilz, you can streamline your Python projects and enhance productivity through a collection of useful functionalities.InstallationYou can installSimpleUtilzusing pip:pip install simpleutilzFunctionality and UsageFile Handling Functionscreate_directory(directory_path)Create a directory if it does not exist.fromsimpleutilz.simpleutilzimportcreate_directorydirectory_path='/path/to/directory'create_directory(directory_path)delete_file(file_path)Delete a file if it exists.fromsimpleutilz.simpleutilzimportdelete_filefile_path='/path/to/file.txt'delete_file(file_path)Data Manipulation Toolsmerge_dicts(*dicts)
Merge multiple dictionaries into a single dictionary.fromsimpleutilz.simpleutilzimportmerge_dictsdict1={'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 Utilitiescapitalize_first_letter(input_string)Capitalize the first letter of a given string.fromsimpleutilz.simpleutilzimportcapitalize_first_letterinput_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.fromsimpleutilz.simpleutilzimportremove_whitespaceinput_string='   hello world   'cleaned_string=remove_whitespace(input_string)print(cleaned_string)# Output: 'hello world'Date and Time Utilitiesget_formatted_datetime(format_str="%Y-%m-%d %H:%M:%S")Get the current date and time in a formatted string.fromsimpleutilz.simpleutilzimportget_formatted_datetimeformatted_time=get_formatted_datetime("%Y-%m-%d")print(formatted_time)# Output: '2023-07-20'Logging Modulelog_error(message)Log an error message to the console or a file (if configured).importloggingfromsimpleutilz.simpleutilzimportlog_errorlogging.basicConfig(filename='error.log',level=logging.ERROR)try:# Some code that may raise an exceptionraiseValueError("Something went wrong!")exceptExceptionase:log_error(str(e))Network Utilitiesdownload_file(url, save_path)Download a file from a given URL and save it to the specified path.fromsimpleutilz.simpleutilzimportdownload_filefile_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.fromsimpleutilz.simpleutilzimportextract_zipzip_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.fromsimpleutilz.simpleutilzimportextract_tartar_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.fromsimpleutilz.simpleutilzimportget_domain_from_urlurl='https://www.example.com/some/page.html'domain=get_domain_from_url(url)print(domain)# Output: 'www.example.com'Other Utilitiesgenerate_random_string(length=10)Generate a random string of a specified length.fromsimpleutilz.simpleutilzimportgenerate_random_stringrandom_str=generate_random_string(8)print(random_str)# Output: 'JwB45XzQ'is_prime(number)Check if a given number is a prime number.fromsimpleutilz.simpleutilzimportis_primenumber=17ifis_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.fromsimpleutilz.simpleutilzimportload_jsonfile_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.fromsimpleutilz.simpleutilzimportcalculate_averagenumbers=[12,34,56,78,90]average=calculate_average(numbers)print(average)# Output: 54.calculate_median(numbers)Calculate the median of a list of numbers.fromsimpleutilz.simpleutilzimportcalculate_mediannumbers=[12,34,56,78,90]median=calculate_median(numbers)print(median)# Output: 56flatten_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.fromsimpleutilz.simpleutilzimportremove_duplicatesinput_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.fromsimpleutilz.simpleutilzimportis_valid_emailemail='john@example.com'ifis_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.fromsimpleutilz.simpleutilzimportis_valid_urlurl='https://www.example.com'ifis_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.fromsimpleutilz.simpleutilzimportis_valid_ipv4ip='192.168.1.1'ifis_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.fromsimpleutilz.simpleutilzimportread_config_fileconfig_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.fromsimpleutilz.simpleutilzimportwrite_config_fileconfig_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.fromsimpleutilz.simpleutilzimportgenerate_encryption_keyencryption_key=generate_encryption_key()print(encryption_key)encrypt_string(text, key)Encrypt a string using a symmetric encryption algorithm.fromsimpleutilz.simpleutilzimportencrypt_stringtext='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.fromsimpleutilz.simpleutilzimportdecrypt_stringencrypted_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.fromsimpleutilz.simpleutilzimportconvert_pdf_to_textpdf_file_path='/path/to/sample.pdf'pdf_text=convert_pdf_to_text(pdf_file_path)print(pdf_text)Convert Hex to Denaryfromsimpleutilz.simpleColoursimportconvert_value_to_denaryhexValue='#ffffff'denary=convert_value_to_denary(hexValue,"hex")print(denary)Convert RGB to Denaryfromsimpleutilz.simpleColoursimportconvert_value_to_denaryrgbValue=(255,255,255)denary=convert_value_to_denary(rgbValue,"rgb")print(denary)Convert RGBA to Denaryfromsimpleutilz.simpleColoursimportconvert_value_to_denaryrgbaValue=(255,255,255,1)denary=convert_value_to_denary(rgbaValue,"rgba")print(denary)Convert Binary to Denaryfromsimpleutilz.simpleColoursimportconvert_value_to_denarybinaryValue='11111111'denary=convert_value_to_denary(binaryValue,"binary")print(denary)Convert RGB code to Colour in Englishfromsimpleutilz.simpleColoursimportRGB_to_colourrgbValue="(255, 255, 255)"colour=RGB_to_colour(rgbValue)print(colour)Convert Hex code to Colour in Englishfromsimpleutilz.simpleColoursimporthex_to_colourhexValue='#ffffff'colour=hex_to_colour(hexValue)print(colour)Convert RGBA code to Colour in Englishfromsimpleutilz.simpleColoursimportRGBA_to_colourrgbaValue="(255, 255, 255, 1)"colour=RGBA_to_colour(rgbaValue)print(colour)Convert Binary code to Colour in Englishfromsimpleutilz.simpleColoursimportbinary_to_colourbinaryValue='11111111'colour=binary_to_colour(binaryValue)print(colour)ContributingContributions toSimpleUtilzare 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.LicenseThis project is licensed under the MIT License - see the LICENSE file for details.TheSimpleUtilzlibrary 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!