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.13.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

MoreUtilspy-0.13-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for moreutilspy-0.13.tar.gz
Algorithm Hash digest
SHA256 e21d80c54768230b88e6631475d5ad2604b4ab24a0400fa0f87bf4c56bbc1a1c
MD5 858d76333bbd9519f712172145c38ce4
BLAKE2b-256 8de829fa7b22714b5f70f81c20aad2a79321f7bc1ac60eab5d076a3409762959

See more details on using hashes here.

File details

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

File metadata

  • Download URL: MoreUtilspy-0.13-py3-none-any.whl
  • Upload date:
  • Size: 9.6 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.13-py3-none-any.whl
Algorithm Hash digest
SHA256 0156648aca4b345d76b5ca7ce39a6d3c3d8aeb5bb4f55b42470c1863c6ff800f
MD5 1ce86b74dc637536f145ce6d81533f5c
BLAKE2b-256 5ca248933bc0e99207032bf7bb05e429b130e0d89459814297829fe97dfac002

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