Skip to main content

MoreUtilspy

moreutils is a Python utility package designed to handle a variety of text, number, and data transformations. It includes features for converting between different formats (e.g., numbers, dates, Roman numerals), working with text (e.g., anagrams, palindromes), and handling JSON/CSV conversions.

Installation

To install moreutilspy, use pip:

pip install moreutilspy

Usage

After installation, you can import and use the functions directly:

from moreutils import text_to_number, is_palindrome

Module: converter_utils

This module provides functions for converting numbers, dates, bytes, and more.

Functions

text_to_number(text: str) -> int

Converts a textual representation of a number into its numerical value.

Example:

text_to_number("one hundred twenty-three")  # Returns: 123
number_to_text(num: int) -> str

Converts a number to its textual representation.

Example:

number_to_text(123)  # Returns: "one hundred twenty-three"
int_to_roman(num: int) -> str

Converts an integer to a Roman numeral.

Example:

int_to_roman(2024)  # Returns: "MMXXIV"
roman_to_int(roman: str) -> int

Converts a Roman numeral to an integer.

Example:

roman_to_int("MMXXIV")  # Returns: 2024
snake_to_camel(snake_str: str) -> str

Converts a snake_case string to camelCase.

Example:

snake_to_camel("hello_world")  # Returns: "helloWorld"
camel_to_snake(camel_str: str) -> str

Converts a camelCase string to snake_case.

Example:

camel_to_snake("helloWorld")  # Returns: "hello_world"
seconds_to_text(seconds: int) -> str

Converts seconds into a human-readable format.

Example:

seconds_to_text(3665)  # Returns: "1 hours, 1 minutes, 5 seconds"
text_to_seconds(time_str: str) -> int

Converts a text representation of time to seconds.

Example:

text_to_seconds("1 hour, 1 minute, 5 seconds")  # Returns: 3665
date_to_text(date_str: str) -> str

Converts a date in YYYY-MM-DD format to a human-readable text.

Example:

date_to_text("2024-01-01")  # Returns: "January 1, 2024"
text_to_date(text: str) -> str

Converts a text representation of a date into YYYY-MM-DD format.

Example:

text_to_date("January 1 2024")  # Returns: "2024-01-01"
bytes_to_text(num_bytes: int) -> str

Converts bytes into a human-readable string.

Example:

bytes_to_text(10240)  # Returns: "10.00 KB"
text_to_bytes(size_str: str) -> int

Converts a string representation of file size into bytes.

Example:

text_to_bytes("10 KB")  # Returns: 10240

Module: text_utils

This module contains utilities for working with text strings, including palindromes, anagrams, and generating random passwords.

Functions

is_palindrome(s: str) -> bool

Checks if a string is a palindrome.

Example:

is_palindrome("racecar")  # Returns: True
are_anagrams(str1: str, str2: str) -> bool

Checks if two strings are anagrams.

Example:

are_anagrams("listen", "silent")  # Returns: True
count_vowels(s: str) -> int

Counts the number of vowels in a string.

Example:

count_vowels("hello world")  # Returns: 3
count_consonants(s: str) -> int

Counts the number of consonants in a string.

Example:

count_consonants("hello world")  # Returns: 7
reverse_words(s: str) -> str

Reverses the words in a string.

Example:

reverse_words("hello world")  # Returns: "olleh dlrow"
reverse_string(s: str) -> str

Reverses a string.

Example:

reverse_string("hello")  # Returns: "olleh"
remove_duplicates(s: str) -> str

Removes duplicate characters from a string.

Example:

remove_duplicates("mississippi")  # Returns: "misp"
is_pangram(s: str) -> bool

Checks if a string contains all letters of the alphabet.

Example:

is_pangram("The quick brown fox jumps over the lazy dog")  # Returns: True
levenshtein_distance(s1: str, s2: str) -> int

Calculates the Levenshtein distance (edit distance) between two strings.

Example:

levenshtein_distance("kitten", "sitting")  # Returns: 3
generate_password(length: int = 12) -> str

Generates a random password of the specified length.

Example:

generate_password(16)  # Returns: A 16-character random password
json_to_csv(json_data: list[dict], csv_file: str)

Converts JSON data to CSV and writes it to a file.

Example:

json_to_csv(json_data, "output.csv")
csv_to_json(csv_file: str) -> list[dict]

Converts a CSV file into JSON format.

Example:

data = csv_to_json("input.csv")

Examples

Here are a few quick examples to demonstrate how to use moreutils:

from moreutils import text_to_number, is_palindrome, generate_password

# Convert text to number
print(text_to_number("one hundred twenty-three"))  # Output: 123

# Check if a string is a palindrome
print(is_palindrome("A man a plan a canal Panama"))  # Output: True

# Generate a random password
print(generate_password(16))  # Output: A randomly generated password

License

moreutils is open source and licensed under the MIT License.

Metadata

Release files for MoreUtilspy 0.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for MoreUtilspy 0.13
File Size Uploaded
moreutilspy-0.13.tar.gz 12.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for MoreUtilspy 0.13
File Interpreter ABI Platform
MoreUtilspy-0.13-py3-none-any.whl Python 3 none any Details

Total release size: 22.0 kB

Release files / moreutilspy-0.13.tar.gz

Download URL moreutilspy-0.13.tar.gz
Size 12.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e21d80c54768230b88e6631475d5ad2604b4ab24a0400fa0f87bf4c56bbc1a1c
BLAKE2b-256 checksum
How to use checksums
8de829fa7b22714b5f70f81c20aad2a79321f7bc1ac60eab5d076a3409762959
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.1

Release files / MoreUtilspy-0.13-py3-none-any.whl

Download URL MoreUtilspy-0.13-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0156648aca4b345d76b5ca7ce39a6d3c3d8aeb5bb4f55b42470c1863c6ff800f
BLAKE2b-256 checksum
How to use checksums
5ca248933bc0e99207032bf7bb05e429b130e0d89459814297829fe97dfac002
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.1

Release history Release notifications | RSS feed

This release

0.13 This release

2 release files

0.12

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page