simpleutil


Namesimpleutil JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/your-username/example-package
SummaryA versatile Python utility library that offers a wide range of helper functions, classes, and modules to expedite development tasks and simplify common operations
upload_time2023-07-20 15:04:09
maintainer
docs_urlNone
authorYour Name
requires_python
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # simpleutils.py - Python Utility Library
`simpleutils` 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 `simpleutils`, you can streamline your Python projects and enhance productivity through a collection of useful functionalities.

## Installation
You can install ``simpleutils`` using pip:

`pip install simpleutils`
## Functionality and Usage
### File Handling Functions
`create_directory(directory_path)``
Create a directory if it does not exist.


```py
from simpleutils import create_directory

directory_path = '/path/to/directory'
create_directory(directory_path)
```
`delete_file(file_path)`
Delete a file if it exists.

```py
from simpleutils 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.


```py
from simpleutils 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.

```py
from simpleutils 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.

```py
from simpleutils 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.

```py
from simpleutils 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).

```py
import logging
from simpleutils 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.

```py
from simpleutils 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.

```py
from simpleutils 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.

```py
from simpleutils 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.

```py
from simpleutils 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.

```py
from simpleutils 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.

```py
from simpleutils 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.

```py
from simpleutils 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.
```py
from simpleutils 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.
```py
from simpleutils 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 simpleutils 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.
```py
from simpleutils 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.

```py
from simpleutils 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.

```py
from simpleutils 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.

```py
from simpleutils 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.

```py
from simpleutils 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.

```py
from simpleutils 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.
```py
from simpleutils import generate_encryption_key

encryption_key = generate_encryption_key()
print(encryption_key)
```
`encrypt_string(text, key)`
Encrypt a string using a symmetric encryption algorithm.
```py
from simpleutils 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.

```py
from simpleutils 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.

```py
from simpleutils import convert_pdf_to_text

pdf_file_path = '/path/to/sample.pdf'
pdf_text = convert_pdf_to_text(pdf_file_path)
print(pdf_text)
```
## Contributing
Contributions to `simpleutils` 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 `simpleutils` 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!

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/your-username/example-package",
    "name": "simpleutil",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Your Name",
    "author_email": "your.email@example.com",
    "download_url": "https://files.pythonhosted.org/packages/ed/fe/37ac46536f60b5246ba9edfde277669d453929696975c040b8dd9a2ccc47/simpleutil-1.0.0.tar.gz",
    "platform": null,
    "description": "# simpleutils.py - Python Utility Library\r\n`simpleutils` 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 `simpleutils`, you can streamline your Python projects and enhance productivity through a collection of useful functionalities.\r\n\r\n## Installation\r\nYou can install ``simpleutils`` using pip:\r\n\r\n`pip install simpleutils`\r\n## Functionality and Usage\r\n### File Handling Functions\r\n`create_directory(directory_path)``\r\nCreate a directory if it does not exist.\r\n\r\n\r\n```py\r\nfrom simpleutils import create_directory\r\n\r\ndirectory_path = '/path/to/directory'\r\ncreate_directory(directory_path)\r\n```\r\n`delete_file(file_path)`\r\nDelete a file if it exists.\r\n\r\n```py\r\nfrom simpleutils import delete_file\r\n\r\nfile_path = '/path/to/file.txt'\r\ndelete_file(file_path)\r\n```\r\n### Data Manipulation Tools\r\nmerge_dicts(*dicts)\r\nMerge multiple dictionaries into a single dictionary.\r\n\r\n\r\n```py\r\nfrom simpleutils import merge_dicts\r\n\r\ndict1 = {'a': 1, 'b': 2}\r\ndict2 = {'c': 3, 'd': 4}\r\nmerged_dict = merge_dicts(dict1, dict2)\r\nprint(merged_dict)  # Output: {'a': 1, 'b': 2, 'c': 3, 'd': 4}\r\n```\r\n### String Utilities\r\n`capitalize_first_letter(input_string)`\r\nCapitalize the first letter of a given string.\r\n\r\n```py\r\nfrom simpleutils import capitalize_first_letter\r\n\r\ninput_string = 'hello world'\r\ncapitalized_string = capitalize_first_letter(input_string)\r\nprint(capitalized_string)  # Output: 'Hello world'\r\n```\r\n`remove_whitespace(input_string)`\r\nRemove leading and trailing whitespace from a string.\r\n\r\n```py\r\nfrom simpleutils import remove_whitespace\r\n\r\ninput_string = '   hello world   '\r\ncleaned_string = remove_whitespace(input_string)\r\nprint(cleaned_string)  # Output: 'hello world'\r\n```\r\n### Date and Time Utilities\r\n`get_formatted_datetime(format_str=\"%Y-%m-%d %H:%M:%S\")`\r\nGet the current date and time in a formatted string.\r\n\r\n```py\r\nfrom simpleutils import get_formatted_datetime\r\n\r\nformatted_time = get_formatted_datetime(\"%Y-%m-%d\")\r\nprint(formatted_time)  # Output: '2023-07-20'\r\n```\r\n### Logging Module\r\n`log_error(message)`\r\nLog an error message to the console or a file (if configured).\r\n\r\n```py\r\nimport logging\r\nfrom simpleutils import log_error\r\n\r\nlogging.basicConfig(filename='error.log', level=logging.ERROR)\r\ntry:\r\n    # Some code that may raise an exception\r\n    raise ValueError(\"Something went wrong!\")\r\nexcept Exception as e:\r\n    log_error(str(e))\r\n```\r\n### Network Utilities\r\n`download_file(url, save_path)`\r\nDownload a file from a given URL and save it to the specified path.\r\n\r\n```py\r\nfrom simpleutils import download_file\r\n\r\nfile_url = 'https://example.com/some_file.txt'\r\nsave_path = '/path/to/save/file.txt'\r\ndownload_file(file_url, save_path)\r\n```\r\n`extract_zip(zip_file_path, extract_to)`\r\nExtract files from a ZIP archive to the specified directory.\r\n\r\n```py\r\nfrom simpleutils import extract_zip\r\n\r\nzip_file_path = '/path/to/archive.zip'\r\nextract_to = '/path/to/extract'\r\nextract_zip(zip_file_path, extract_to)\r\n```\r\n`extract_tar(tar_file_path, extract_to)`\r\nExtract files from a TAR archive to the specified directory.\r\n\r\n```py\r\nfrom simpleutils import extract_tar\r\n\r\ntar_file_path = '/path/to/archive.tar.gz'\r\nextract_to = '/path/to/extract'\r\nextract_tar(tar_file_path, extract_to)\r\n```\r\n`get_domain_from_url(url)`\r\nExtract the domain name from a given URL.\r\n\r\n```py\r\nfrom simpleutils import get_domain_from_url\r\n\r\nurl = 'https://www.example.com/some/page.html'\r\ndomain = get_domain_from_url(url)\r\nprint(domain)  # Output: 'www.example.com'\r\n```\r\n## Other Utilities\r\n`generate_random_string(length=10)`\r\nGenerate a random string of a specified length.\r\n\r\n```py\r\nfrom simpleutils import generate_random_string\r\n\r\nrandom_str = generate_random_string(8)\r\nprint(random_str)  # Output: 'JwB45XzQ'\r\n```\r\n`is_prime(number)`\r\nCheck if a given number is a prime number.\r\n\r\n```py\r\nfrom simpleutils import is_prime\r\n\r\nnumber = 17\r\nif is_prime(number):\r\n    print(f\"{number} is a prime number.\")\r\nelse:\r\n    print(f\"{number} is not a prime number.\")\r\n```\r\n`load_json(file_path)`\r\nLoad JSON data from a file and return it as a Python dictionary.\r\n\r\n```py\r\nfrom simpleutils import load_json\r\n\r\nfile_path = '/path/to/data.json'\r\ndata = load_json(file_path)\r\nprint(data)  # Output: {'name': 'John Doe', 'age': 30, 'email': 'john@example.com'}\r\n```\r\n`calculate_average(numbers)`\r\nCalculate the average of a list of numbers.\r\n```py\r\nfrom simpleutils import calculate_average\r\n\r\nnumbers = [12, 34, 56, 78, 90]\r\naverage = calculate_average(numbers)\r\nprint(average)  # Output: 54.\r\n```\r\n`calculate_median(numbers)`\r\nCalculate the median of a list of numbers.\r\n```py\r\nfrom simpleutils import calculate_median\r\n\r\nnumbers = [12, 34, 56, 78, 90]\r\nmedian = calculate_median(numbers)\r\nprint(median)  # Output: 56\r\n```\r\n`flatten_list(nested_list)`\r\nFlatten a nested list into a single-dimensional list.\r\n\r\n```\r\nfrom simpleutils import flatten_list\r\n\r\nnested_list = [[1, 2, 3], [4, [5, 6]], [7], 8]\r\nflattened_list = flatten_list(nested_list)\r\nprint(flattened_list)  # Output: [1, 2, 3, 4, 5, 6, 7, 8]\r\n```\r\n`remove_duplicates(input_list)`\r\nRemove duplicates from a list while preserving the order.\r\n```py\r\nfrom simpleutils import remove_duplicates\r\n\r\ninput_list = [1, 2, 2, 3, 4, 3, 5]\r\nunique_list = remove_duplicates(input_list)\r\nprint(unique_list)  # Output: [1, 2, 3, 4, 5]\r\n```\r\n`is_valid_email(email)`\r\nCheck if a given string is a valid email address.\r\n\r\n```py\r\nfrom simpleutils import is_valid_email\r\n\r\nemail = 'john@example.com'\r\nif is_valid_email(email):\r\n    print(f\"{email} is a valid email address.\")\r\nelse:\r\n    print(f\"{email} is not a valid email address.\")\r\n```\r\n`is_valid_url(url)`\r\nCheck if a given string is a valid URL.\r\n\r\n```py\r\nfrom simpleutils import is_valid_url\r\n\r\nurl = 'https://www.example.com'\r\nif is_valid_url(url):\r\n    print(f\"{url} is a valid URL.\")\r\nelse:\r\n    print(f\"{url} is not a valid URL.\")\r\n```\r\n`is_valid_ipv4(ip)`\r\nCheck if a given string is a valid IPv4 address.\r\n\r\n```py\r\nfrom simpleutils import is_valid_ipv4\r\n\r\nip = '192.168.1.1'\r\nif is_valid_ipv4(ip):\r\n    print(f\"{ip} is a valid IPv4 address.\")\r\nelse:\r\n    print(f\"{ip} is not a valid IPv4 address.\")\r\n```\r\n`read_config_file(config_file_path)`\r\nRead a configuration file (e.g., .ini, .yaml) and return it as a dictionary.\r\n\r\n```py\r\nfrom simpleutils import read_config_file\r\n\r\nconfig_file_path = '/path/to/config.ini'\r\nconfig_data = read_config_file(config_file_path)\r\nprint(config_data)\r\n```\r\n`write_config_file(config_dict, file_path)`\r\nWrite a dictionary as a configuration file.\r\n\r\n```py\r\nfrom simpleutils import write_config_file\r\n\r\nconfig_dict = {'Section1': {'key1': 'value1', 'key2': 'value2'}, 'Section2': {'key3': 'value3'}}\r\nfile_path = '/path/to/config.ini'\r\nwrite_config_file(config_dict, file_path)\r\n```\r\n`generate_encryption_key()`\r\nGenerate a new encryption key.\r\n```py\r\nfrom simpleutils import generate_encryption_key\r\n\r\nencryption_key = generate_encryption_key()\r\nprint(encryption_key)\r\n```\r\n`encrypt_string(text, key)`\r\nEncrypt a string using a symmetric encryption algorithm.\r\n```py\r\nfrom simpleutils import encrypt_string\r\n\r\ntext = 'This is a secret message.'\r\nkey = b'some_random_key'\r\nencrypted_text = encrypt_string(text, key)\r\nprint(encrypted_text)\r\n```\r\n`decrypt_string(encrypted_text, key)`\r\nDecrypt an encrypted string using the same key.\r\n\r\n```py\r\nfrom simpleutils import decrypt_string\r\n\r\nencrypted_text = b'encrypted_data_here'\r\nkey = b'some_random_key'\r\ndecrypted_text = decrypt_string(encrypted_text, key)\r\nprint(decrypted_text)\r\n```\r\n`convert_pdf_to_text(pdf_file_path)`\r\nConvert a PDF file to plain text.\r\n\r\n```py\r\nfrom simpleutils import convert_pdf_to_text\r\n\r\npdf_file_path = '/path/to/sample.pdf'\r\npdf_text = convert_pdf_to_text(pdf_file_path)\r\nprint(pdf_text)\r\n```\r\n## Contributing\r\nContributions to `simpleutils` 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.\r\n\r\n## License\r\nThis project is licensed under the MIT License - see the LICENSE file for details.\r\n\r\nThe `simpleutils` 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!\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A versatile Python utility library that offers a wide range of helper functions, classes, and modules to expedite development tasks and simplify common operations",
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/your-username/example-package"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0f0a9dd3b31ef6691c69170da7f17e8528789de97afb680a3ce245ddfc0dc905",
                "md5": "6bcff3392d477d71a52285accf286ed1",
                "sha256": "87628538fca2fffff61f6a3657c8f7db29ccc49dc8dd482b1ea1d73e6cea9efa"
            },
            "downloads": -1,
            "filename": "simpleutil-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6bcff3392d477d71a52285accf286ed1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 4727,
            "upload_time": "2023-07-20T15:04:08",
            "upload_time_iso_8601": "2023-07-20T15:04:08.217958Z",
            "url": "https://files.pythonhosted.org/packages/0f/0a/9dd3b31ef6691c69170da7f17e8528789de97afb680a3ce245ddfc0dc905/simpleutil-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "edfe37ac46536f60b5246ba9edfde277669d453929696975c040b8dd9a2ccc47",
                "md5": "c3457940885bc52578559213673b34f5",
                "sha256": "9d7a0d9dec4618b54d11d6fcd7c57b22eda3c5a842aacc25930b63ea3d9da988"
            },
            "downloads": -1,
            "filename": "simpleutil-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "c3457940885bc52578559213673b34f5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5006,
            "upload_time": "2023-07-20T15:04:09",
            "upload_time_iso_8601": "2023-07-20T15:04:09.594273Z",
            "url": "https://files.pythonhosted.org/packages/ed/fe/37ac46536f60b5246ba9edfde277669d453929696975c040b8dd9a2ccc47/simpleutil-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-20 15:04:09",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "your-username",
    "github_project": "example-package",
    "github_not_found": true,
    "lcname": "simpleutil"
}
        
Elapsed time: 0.45667s