A multi-purpose Python utility toolkit
Project description
PyUtilKit
A multi-purpose Python utility package that provides ready-to-use, frequently-needed helper functions for everyday coding tasks — saving time, reducing boilerplate, and improving code readability.
🚀 Installation
You can install PyUtilKit using pip:
pip install pyutilkit-sarvs
🧩 Core Modules
PyUtilKit is organized into several modules, each focusing on specific utility functions:
1. string_utils
String manipulation and validation utilities.
from pyutilkit.string_utils import to_snake_case, remove_punctuation, is_palindrome
# Case conversion
to_snake_case("HelloWorld") # Output: "hello_world"
to_camel_case("hello_world") # Output: "helloWorld"
to_pascal_case("hello-world") # Output: "HelloWorld"
# String manipulation
remove_punctuation("Hello, world!") # Output: "Hello world"
remove_digits("Hello123World") # Output: "HelloWorld"
remove_whitespace("Hello world", keep_single_spaces=True) # Output: "Hello world"
truncate("Hello world", 8) # Output: "Hello..."
pad_string("Hello", 10, pad_char="-", align="center") # Output: "--Hello---"
# String validation
is_palindrome("racecar") # Output: True
is_anagram("listen", "silent") # Output: True
2. file_utils
File and directory management utilities.
from pyutilkit.file_utils import read_json, write_csv, get_file_size
# File I/O
data = read_json("data.json")
write_csv("output.csv", data, delimiter=",")
content = read_text("file.txt", encoding="utf-8")
write_text("output.txt", "Hello, world!", append=True)
# File metadata
size = get_file_size("large_file.txt", unit="MB") # Get size in megabytes
last_modified = get_last_modified_time("file.txt", as_datetime=True)
extension = get_file_extension("document.pdf", with_dot=False) # Output: "pdf"
# File management
create_file("new_file.txt", "Initial content")
create_directory("new_directory", exist_ok=True)
rename_file("old_name.txt", "new_name.txt", overwrite=False)
delete_file("temp.txt", missing_ok=True)
merge_csv_files(["part1.csv", "part2.csv"], "merged.csv")
merge_json_files(["config1.json", "config2.json"], "merged.json", merge_mode="merge_objects")
3. math_utils
Mathematical utilities and statistics.
from pyutilkit.math_utils import safe_divide, mean, is_prime
# Arithmetic
safe_divide(10, 0, default=0) # Output: 0
percent_change(100, 150) # Output: 50.0
normalized = normalize([1, 2, 3, 4, 5]) # Output: [0.0, 0.25, 0.5, 0.75, 1.0]
z_scores = z_score([2, 4, 6]) # Output: [-1.0, 0.0, 1.0]
# Statistics
mean([1, 2, 3, 4, 5]) # Output: 3.0
median([1, 3, 5, 7, 9]) # Output: 5
mode([1, 2, 2, 3, 3, 3, 4]) # Output: 3
std_dev = standard_deviation([1, 2, 3, 4, 5]) # Population standard deviation
# Number theory
is_prime(17) # Output: True
factorial(5) # Output: 120
gcd(8, 12) # Output: 4
lcm(4, 6) # Output: 12
4. list_utils
List manipulation and analysis utilities.
from pyutilkit.list_utils import flatten, chunk, get_frequency
# List manipulation
flatten([1, [2, 3], [4, [5, 6]]]) # Output: [1, 2, 3, 4, 5, 6]
chunked = chunk([1, 2, 3, 4, 5, 6, 7], 3) # Output: [[1, 2, 3], [4, 5, 6], [7]]
unique = remove_duplicates([1, 2, 2, 3, 1, 4]) # Output: [1, 2, 3, 4]
# List analysis
freq = get_frequency([1, 2, 2, 3, 1, 3, 3, 4]) # Output: {1: 2, 2: 2, 3: 3, 4: 1}
most_common = most_frequent([1, 2, 2, 3, 1, 3, 3, 4], n=2) # Output: [(3, 3), (1, 2)]
least_common = least_frequent([1, 2, 2, 3, 1, 3, 3, 4], n=1) # Output: [(4, 1)]
# List transformation
str_list = to_string_list([1, 2.5, True, None]) # Output: ['1', '2.5', 'True', 'None']
int_list = to_int_list(['1', '2', '3']) # Output: [1, 2, 3]
float_list = to_float_list(['1', '2.5', '3']) # Output: [1.0, 2.5, 3.0]
📖 Full Documentation
For complete documentation of all functions and examples, visit https://github.com/Sarvesh-Kannan/PyUtilKit.
🧪 Testing
PyUtilKit includes a comprehensive test suite. To run the tests:
# Install pytest if you don't have it
pip install pytest
# Run tests
pytest -v
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
📝 License
This project is licensed under the MIT License - see the LICENSE file for details.
📬 Contact
Sarvesh Kannan - your.email@example.com
Project Link: https://github.com/Sarvesh-Kannan/PyUtilKit
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
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 pyutilkit_sarvs-0.1.0.tar.gz.
File metadata
- Download URL: pyutilkit_sarvs-0.1.0.tar.gz
- Upload date:
- Size: 20.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78841890ee375bd463122ac42c1d071d2a70ac196933350780cfe5edc6026223
|
|
| MD5 |
6b9d49a81ee2e91d3917ba1676f775ff
|
|
| BLAKE2b-256 |
630069eff74374e3d6f1c8b9437ce4443173f8dab70b1779bb67f4f9da48430c
|
File details
Details for the file pyutilkit_sarvs-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyutilkit_sarvs-0.1.0-py3-none-any.whl
- Upload date:
- Size: 24.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7c69ddaa332464f5ca531025083ebed2dcbaa2ffcdf245635789540acebced8
|
|
| MD5 |
a2ee2996ae0bb73ee46ef3c779517551
|
|
| BLAKE2b-256 |
2b468c4357a23c0035a3e342bffc02d59ac7850f2bb783c6435ec4d646017a68
|