Skip to main content

a package containing more utilities for python

Project description

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.

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

moreutilspy-0.12.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

MoreUtilspy-0.12-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file moreutilspy-0.12.tar.gz.

File metadata

  • Download URL: moreutilspy-0.12.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.1

File hashes

Hashes for moreutilspy-0.12.tar.gz
Algorithm Hash digest
SHA256 911d7459b1c58fb48cb08e41c7c47b869b59f51579a5cf6f654fc4f51fbd5625
MD5 a2317bb30ad86a3c88f95f1416ed1210
BLAKE2b-256 8056005cdaaef0166933b971e509e11b844017be52cdaadaf9caf176ec22348e

See more details on using hashes here.

File details

Details for the file MoreUtilspy-0.12-py3-none-any.whl.

File metadata

  • Download URL: MoreUtilspy-0.12-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.1

File hashes

Hashes for MoreUtilspy-0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 9cdcd1f0b2250c5dadb011aef2ed43b5f3f26c99f84e97f621157522bde34181
MD5 b8bf73656f1eb68f277cfb65c067ee0f
BLAKE2b-256 fb17f2d547ff339ac1d388cffd7223df559238cc14576137cf5339e43552b00d

See more details on using hashes here.

Supported by

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