Skip to content

Text Module

The rite.text module provides comprehensive text processing utilities including case conversions, slug generation, text analysis, validation, manipulation, and search operations.

Overview

text

Text Processing Module

This module provides text processing utilities similar to Python's str, string, and textwrap modules.

The text module includes functions for: - Case conversions (snake_case, camelCase, PascalCase, kebab-case, etc.) - Slug generation for URL-friendly strings - Text analysis (character frequency, word count, etc.) - String sanitization and cleaning - Text validation (email, numeric, alpha, alphanumeric) - Text manipulation (truncate, pad, wrap) - Text search (contains, starts_with, ends_with, find, count) - Morse code encoding/decoding - Random string generation

Example

from rite.text import to_snake_case, slugify to_snake_case("Hello World") 'hello_world' slugify("Hello World!") 'hello-world'

Functions

add_slug_prefix

add_slug_prefix(slug: str, prefix: str, delimiter: str = '-') -> str

Add a prefix to a slug.

Parameters:

Name Type Description Default
slug str

The original slug.

required
prefix str

The prefix to add.

required
delimiter str

The delimiter used in the slug (default: "-").

'-'

Returns:

Type Description
str

The slug with the prefix added.

Example

add_slug_prefix("world", "hello") 'hello-world' add_slug_prefix("world", "hello", delimiter="_") 'hello_world'

add_slug_suffix

add_slug_suffix(slug: str, suffix: str, delimiter: str = '-') -> str

Add a suffix to a slug.

Parameters:

Name Type Description Default
slug str

The original slug.

required
suffix str

The suffix to add.

required
delimiter str

The delimiter used in the slug (default: "-").

'-'

Returns:

Type Description
str

The slug with the suffix added.

Example

add_slug_suffix("hello", "world") 'hello-world' add_slug_suffix("hello", "world", delimiter="_") 'hello_world'

clean

clean(text: str) -> str

Remove extra whitespace from text.


text: The input text to clean.

str: The cleaned text with normalized whitespace.

unique_slug

unique_slug(slug: str, existing_slugs: set[str] | list[str], delimiter: str = '-') -> str

Generate a unique slug by appending an incremental number.

If the slug already exists in the set of existing slugs, appends an incremental number (starting from 1) until a unique slug is found.

Parameters:

Name Type Description Default
slug str

The original slug.

required
existing_slugs set[str] | list[str]

A set or list of existing slugs to check against.

required
delimiter str

The delimiter used in the slug (default: "-").

'-'

Returns:

Type Description
str

A unique slug with an incremental number if needed.

Example

unique_slug("hello-world", {"hello-world"}) 'hello-world-1' unique_slug("hello-world", {"hello-world", "hello-world-1"}) 'hello-world-2' unique_slug("hello-world", []) 'hello-world'

Modules

analysis

Modules
average_word_length
Average Word Length

Calculate average word length in text.

Functions
average_word_length
average_word_length(text: str) -> float

Calculate the average word length in text.

Parameters:

Name Type Description Default
text str

Input text string

required

Returns:

Type Description
float

Average length of words

Raises:

Type Description
ValueError

If text contains no words

Example

average_word_length("hello world") 5.0

char_frequency
Character Frequency Analysis

Count character frequency in text.

Functions
char_frequency
char_frequency(text: str) -> dict[str, int]

Count the frequency of each character in text.

Parameters:

Name Type Description Default
text str

Input text string

required

Returns:

Type Description
dict[str, int]

Dictionary mapping characters to their frequency count

Example

char_frequency("hello")

is_palindrome
Palindrome Checker

Check if text is a palindrome.

Functions
is_palindrome
is_palindrome(text: str, ignore_case: bool = True, ignore_spaces: bool = True) -> bool

Check if text is a palindrome.

Parameters:

Name Type Description Default
text str

Input text string

required
ignore_case bool

Whether to ignore case differences

True
ignore_spaces bool

Whether to ignore spaces and non-alphanumeric

True

Returns:

Type Description
bool

True if text is a palindrome, False otherwise

Example

is_palindrome("A man a plan a canal Panama") True

longest_word
Longest Word Finder

Find the longest word in text.

Functions
longest_word
longest_word(text: str) -> str

Find the longest word in text.

Parameters:

Name Type Description Default
text str

Input text string

required

Returns:

Type Description
str

The longest word

Raises:

Type Description
ValueError

If text contains no words

Example

longest_word("hello world") 'hello'

shortest_word
Shortest Word Finder

Find the shortest word in text.

Functions
shortest_word
shortest_word(text: str) -> str

Find the shortest word in text.

Parameters:

Name Type Description Default
text str

Input text string

required

Returns:

Type Description
str

The shortest word

Raises:

Type Description
ValueError

If text contains no words

Example

shortest_word("hello world") 'hello'

word_count
Word Counting

Count words in text.

Functions
word_count
word_count(text: str) -> int

Count the number of words in text.

Parameters:

Name Type Description Default
text str

Input text string

required

Returns:

Type Description
int

Number of words

Example

word_count("hello world") 2

case

Case Conversion Module

Functions for converting text between different case formats.

Modules
case_to_acronym
Functions
to_acronym_case
to_acronym_case(text: str) -> str

Convert a phrase to its acronym. Example: 'Random Access Memory' -> 'RAM'

Parameters: text (str): The phrase to convert.

Returns

str: The acronym of the phrase.

case_to_alphabet_position
Functions
to_alphabet_position_case
to_alphabet_position_case(text: str) -> str

Replaces each letter with its position in the alphabet. Example: 'ab' -> '1 2'

Parameters: text (str): The text to process.

Returns

str: A string with each letter replaced by its alphabet position.

case_to_alternate_character_deletion
Functions
to_alternate_character_deletion_case
to_alternate_character_deletion_case(text: str) -> str

Deletes every alternate character in the text. Example: 'Hello' -> 'Hlo'

Parameters: text (str): The text to process.

Returns

str: The text with every alternate character deleted.

case_to_alternate_uppercase_lowercase
Functions
to_alternate_uppercase_lowercase_case
to_alternate_uppercase_lowercase_case(text: str) -> str

Alternates between uppercase and lowercase starting from the second character. Example: 'hello world' -> 'hElLo WoRlD'

Parameters: text (str): The text to convert.

Returns

str: The text with alternating uppercase and lowercase letters.

case_to_diagonal_text
Functions
to_diagonal_text_case
to_diagonal_text_case(text: str) -> str

Creates a diagonal representation of the text. Note: This is a symbolic representation. Example: 'Hello' -> 'H e l l o'

Parameters: text (str): The text to convert.

Returns


str: The text in a diagonal representation.

case_to_first_letter_of_each_word
Functions
to_first_letter_of_each_word_case
to_first_letter_of_each_word_case(text: str) -> str

Takes the first letter of each word to form a new string. Example: 'Hello World' -> 'HW'

Parameters: text (str): The text to convert.

Returns

str: A string formed by the first letter of each word.

case_to_leet_speak
Functions
to_leet_speak_case
to_leet_speak_case(text: str) -> str

Convert the text to leet speak (1337) case. Example: 'Leet Speak' -> '1337 5p34k'

Parameters: text (str): The text to convert.

Returns

str: The text in leet speak.

case_to_pig_latin
Functions
to_pig_latin_case
to_pig_latin_case(text: str) -> str

Translates text into Pig Latin. Example: 'hello' -> 'ellohay'

Parameters: text (str): The text to translate.

Returns

str: The text in Pig Latin.

case_to_random
Functions
to_random_case
to_random_case(text: str) -> str

Randomly change the case of each character in the text. Example: 'Hello World' -> 'hElLO wOrLD'

Parameters: text (str): The text to randomize case.

Returns

str: The text with randomized case.

case_to_slug
Functions
to_slug_case
to_slug_case(text: str) -> str

Convert the text to slug case (URL-friendly format). Example: 'Hello World' -> 'hello-world'

Parameters: text (str): The text to convert to slug case.

Returns

str: The text in slug case.

case_to_spinal
Functions
to_spinal_case
to_spinal_case(text: str) -> str

Convert the text to spinal case (similar to kebab case). Lowers the case of each word and joins them with hyphens. Example: 'Hello World' -> 'hello-world'

Parameters: text (str): The text to convert.

Returns

str: The text converted to spinal case.

case_to_spongebob_meme
Functions
to_spongebob_meme_case
to_spongebob_meme_case(text: str) -> str

Alternates the case of each letter in a mocking manner, starting with uppercase. Example: 'spongebob case' -> 'SpOnGeBoB cAsE'

Parameters: text (str): The text to convert.

Returns

str: The text in Spongebob Meme case.

case_to_spongebob_mocking
Functions
to_mocking_spongebob_case
to_mocking_spongebob_case(text: str) -> str

Convert the text to 'Mocking Spongebob' case (alternating case). Example: 'Hello World' -> 'hElLo wOrLd'

Parameters: text (str): The text to convert.

Returns

str: The text in 'Mocking Spongebob' case.

case_to_swap
Functions
to_swap_case
to_swap_case(text: str) -> str

Swap the case of each character in the text. Example: 'Hello World' -> 'hELLO wORLD'

Parameters: text (str): The text whose case is to be swapped.

Returns

str: The text with swapped case.

case_to_upper_consonant
Functions
to_consonant_uppercase_case
to_consonant_uppercase_case(text: str) -> str

Convert all consonants in the text to uppercase. Example: 'Hello World' -> 'hEllO wOrld'

Parameters: text (str): The text to convert.

Returns

str: The text with uppercase consonants.

case_to_upper_first_letter
Functions
to_upper_first_letter_case
to_upper_first_letter_case(text: str) -> str

Convert only the first letter of each word in the text to uppercase, the rest to lowercase. Example: 'hello world' -> 'Hello World'

Parameters: text (str): The text to convert.

Returns

str: The text with the first letter of each word in uppercase.

case_to_upper_vowel
Functions
to_vowel_uppercase_case
to_vowel_uppercase_case(text: str) -> str

Convert all vowels in the text to uppercase. Example: 'Hello World' -> 'HEllO WOrld'

Parameters: text (str): The text to convert.

Returns

str: The text with uppercase vowels.

case_to_upside_down
Functions
to_upside_down_case
to_upside_down_case(text: str) -> str

Flips the text upside down. Note: This method uses a limited character set for flipping.

Parameters: text (str): The text to flip.

Returns

str: The flipped text.

case_to_zalgo_text
Functions
to_zalgo_text_case
to_zalgo_text_case(text: str) -> str

Add a glitch-like effect to the text with Zalgo characters. Note: This is a simplified version for demonstration.

Parameters: text (str): The text to convert.

Returns

str: The text with Zalgo effect.

to_camel_case
Camel Case Conversion

Convert text to camelCase format.

Functions
to_camel_case
to_camel_case(text: str) -> str

Convert text to camelCase.

Converts the input text to camel case where the first word is lowercase and subsequent words are capitalized.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to camelCase.

Example

to_camel_case("hello world") 'helloWorld' to_camel_case("Hello World") 'helloWorld'

to_constant_case
Constant Case Conversion

Convert text to CONSTANT_CASE format.

Functions
to_constant_case
to_constant_case(text: str) -> str

Convert text to CONSTANT_CASE.

Converts the input text to constant case (screaming snake case) by replacing spaces and special characters with underscores and converting to uppercase.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to CONSTANT_CASE.

Example

to_constant_case("Hello World") 'HELLO_WORLD' to_constant_case("helloWorld") 'HELLO_WORLD'

to_dot_case
Dot Case Conversion

Convert text to dot.case format.

Functions
to_dot_case
to_dot_case(text: str) -> str

Convert text to dot.case.

Converts the input text to dot case by replacing spaces and special characters with dots and converting to lowercase.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to dot.case.

Example

to_dot_case("Hello World") 'hello.world' to_dot_case("helloWorld") 'hello.world'

to_kebab_case
Kebab Case Conversion

Convert text to kebab-case format.

Functions
to_kebab_case
to_kebab_case(text: str) -> str

Convert text to kebab-case.

Converts the input text to kebab case by replacing spaces and special characters with hyphens and converting to lowercase.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to kebab-case.

Example

to_kebab_case("Hello World") 'hello-world' to_kebab_case("helloWorld") 'hello-world'

to_lower_case
Lowercase Conversion

Convert text to lowercase format.

Functions
to_lower_case
to_lower_case(text: str) -> str

Convert text to lowercase.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to lowercase.

Example

to_lower_case("Hello World") 'hello world'

to_pascal_case
Pascal Case Conversion

Convert text to PascalCase format.

Functions
to_pascal_case
to_pascal_case(text: str) -> str

Convert text to PascalCase.

Converts the input text to Pascal case where all words are capitalized and joined without separators.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to PascalCase.

Example

to_pascal_case("hello world") 'HelloWorld' to_pascal_case("hello_world") 'HelloWorld'

to_path_case
Path Case Conversion

Convert text to path/case format.

Functions
to_path_case
to_path_case(text: str) -> str

Convert text to path/case.

Converts the input text to path case by replacing spaces and special characters with forward slashes and converting to lowercase.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to path/case.

Example

to_path_case("Hello World") 'hello/world' to_path_case("helloWorld") 'hello/world'

to_sentence_case
Sentence Case Conversion

Convert text to Sentence case format.

Functions
to_sentence_case
to_sentence_case(text: str) -> str

Convert text to Sentence case.

Converts the input text to sentence case where only the first letter of the first word is capitalized and the rest is lowercase.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to Sentence case.

Example

to_sentence_case("hello world") 'Hello world' to_sentence_case("HELLO WORLD") 'Hello world'

to_snake_case
Snake Case Conversion

Convert text to snake_case format.

Functions
to_snake_case
to_snake_case(text: str) -> str

Convert text to snake_case.

Converts the input text to snake case by replacing spaces and special characters with underscores and converting to lowercase.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to snake_case.

Example

to_snake_case("Hello World") 'hello_world' to_snake_case("helloWorld") 'hello_world'

to_title_case
Title Case Conversion

Convert text to Title Case format.

Functions
to_title_case
to_title_case(text: str) -> str

Convert text to Title Case.

Converts the input text to title case where the first letter of each word is capitalized.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to Title Case.

Example

to_title_case("hello world") 'Hello World' to_title_case("HELLO WORLD") 'Hello World'

to_upper_case
Uppercase Conversion

Convert text to UPPERCASE format.

Functions
to_upper_case
to_upper_case(text: str) -> str

Convert text to UPPERCASE.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to UPPERCASE.

Example

to_upper_case("Hello World") 'HELLO WORLD'

char_frequency

Character Frequency Analysis

Count character frequency in text.

Functions
char_frequency
char_frequency(text: str) -> dict[str, int]

Count the frequency of each character in text.

Parameters:

Name Type Description Default
text str

Input text string

required

Returns:

Type Description
dict[str, int]

Dictionary mapping characters to their frequency count

Example

char_frequency("hello")

converters

Rite - String Converters Module

This module provides utilities for converting strings between different formats.

Functions
convert_string_to_binary
convert_string_to_binary(text: str) -> str
String to Binary Converter

Convert the text to binary form. Example: 'AB' -> '01000001 01000010'

Parameters: text (str): The text to convert.

Returns

str: The text in binary form.

convert_string_to_bool
convert_string_to_bool(val: str | None) -> bool | None
String to Boolean Converter

Convert a string representation of a boolean value to a boolean.

convert_string_to_datetime
convert_string_to_datetime(value: str | None) -> datetime | None
String to Datetime Converter

Convert a string to a timezone-aware datetime object (UTC).

Parses a timestamp like '2024-12-11 11:42:34.049271+00' or ISO-ish strings. Returns None on blank or invalid input.

Supports ISO 8601 format with optional timezone. Naive datetimes are converted to UTC.

Parameters:

Name Type Description Default
value str | None

The string to convert.

required

Returns:

Type Description
datetime | None

A timezone-aware datetime object in UTC, or None.

convert_string_to_decimal
convert_string_to_decimal(value: str | None, length: int = 3) -> Decimal | None
String to Decimal Converter

Convert a string to a Decimal, quantized to length decimal places.

Parameters:

Name Type Description Default
value str | None

The input string (or None).

required
length int

Number of decimal places to quantize to. Default is 3.

3

Returns:

Type Description
Decimal | None

Decimal quantized to length places, or None if conversion fails.

convert_string_to_float
convert_string_to_float(val: str) -> float | None

Convert a string representation of a float value to a float.

convert_string_to_int
convert_string_to_int(val: str) -> int | None

Convert a string representation of an integer value to an integer.

Modules
case_to_abbreviation
Abbreviation Case Converter

Convert text to abbreviation format.

Functions
to_abbreviation_case
to_abbreviation_case(text: str) -> str

Converts text to its abbreviation.

Example: 'As Soon As Possible' -> 'ASAP'

Parameters:

Name Type Description Default
text str

The text to abbreviate

required

Returns:

Type Description
str

The abbreviation of the text

Example

to_abbreviation_case("As Soon As Possible") 'ASAP'

case_to_ascii_value
ASCII Value Converter

Convert characters to ASCII values.

Functions
to_ascii_value_case
to_ascii_value_case(text: str) -> str

Converts each character to its ASCII value.

Parameters:

Name Type Description Default
text str

The text to convert

required

Returns:

Type Description
str

A string of ASCII values for each character

Example

to_ascii_value_case("AB") '65 66'

case_to_braille_transcription
Braille Transcription Converter

Transcribe text into simulated Braille.

Functions
to_braille_transcription_case
to_braille_transcription_case(text: str) -> str

Transcribes text into simulated Braille.

Note: This is a highly simplified and symbolic representation.

Parameters:

Name Type Description Default
text str

The text to transcribe

required

Returns:

Type Description
str

The text transcribed into simulated Braille

Example

to_braille_transcription_case("Hello") 'Braille: Hello'

case_to_double_every_second_word
Double Every Second Word Converter

Double every second word in text.

Functions
to_double_every_second_word_case
to_double_every_second_word_case(text: str) -> str

Doubles every second word in the text.

Parameters:

Name Type Description Default
text str

The text to process

required

Returns:

Type Description
str

The text with every second word doubled

Example

to_double_every_second_word_case("Hello world program") 'Hello Hello world world program program'

case_to_emoji
Emoji Converter

Replace words with corresponding emojis.

Functions
to_emoji_case
to_emoji_case(text: str) -> str

Replace certain words with corresponding emojis.

Note: This is a limited implementation; only a few words are replaced.

Parameters:

Name Type Description Default
text str

The text to convert

required

Returns:

Type Description
str

The text with words replaced by emojis

Example

to_emoji_case("I love my dog") 'I ❤️ my 🐶'

case_to_hexadecimal
Hexadecimal Converter

Convert text to hexadecimal form.

Functions
to_hexadecimal_case
to_hexadecimal_case(text: str) -> str

Convert the text to hexadecimal form.

Parameters:

Name Type Description Default
text str

The text to convert

required

Returns:

Type Description
str

The text in hexadecimal form

Example

to_hexadecimal_case("AB") '41 42'

case_to_nato_phonetic_alphabet
NATO Phonetic Alphabet Converter

Translate text to NATO phonetic alphabet.

Functions
to_nato_phonetic_alphabet_case
to_nato_phonetic_alphabet_case(text: str) -> str

Translates each letter to its corresponding NATO phonetic alphabet word.

Parameters:

Name Type Description Default
text str

The text to convert

required

Returns:

Type Description
str

The text in NATO phonetic alphabet

Example

to_nato_phonetic_alphabet_case("AB") 'Alpha Bravo'

case_to_numeric_words_to_numbers
Numeric Words to Numbers Converter

Convert numeric words to numeral equivalents.

Functions
to_numeric_words_to_numbers_case
to_numeric_words_to_numbers_case(text: str) -> str

Converts numeric words to their numeral equivalents.

Parameters:

Name Type Description Default
text str

The text to convert

required

Returns:

Type Description
str

The text with numeric words converted to numbers

Example

to_numeric_words_to_numbers_case("one two three") '1 2 3'

case_to_numeronym
Numeronym Converter

Convert words to numeronym format.

Functions
to_numeronym_case
to_numeronym_case(text: str) -> str

Converts a word into a numeronym.

Parameters:

Name Type Description Default
text str

The word to convert

required

Returns:

Type Description
str

The word converted into a numeronym

Example

to_numeronym_case("Internationalization") 'I18n'

case_to_rainbow
Rainbow Case Converter

Assign color codes to letters.

Functions
to_rainbow_case
to_rainbow_case(text: str) -> str

Assigns a different color code to each letter.

Note: Actual color cannot be represented in plain text; using symbolic representation.

Parameters:

Name Type Description Default
text str

The text to convert

required

Returns:

Type Description
str

The text with symbolic color codes

Example

to_rainbow_case("Hello") '🟥H🟧e🟨l🟩l🟦o'

case_to_substitute_numbers_with_words
Substitute Numbers with Words Converter

Replace numbers with word equivalents.

Functions
to_substitute_numbers_with_words_case
to_substitute_numbers_with_words_case(text: str) -> str

Replaces numbers in the text with their word equivalents.

Parameters:

Name Type Description Default
text str

The text to process

required

Returns:

Type Description
str

The text with numbers replaced by words

Example

to_substitute_numbers_with_words_case("I have 2 dogs and 3 cats") 'I have two dogs and three cats'

case_to_vowel_concatenation
Vowel Concatenation Converter

Concatenate all vowels from text.

Functions
to_vowel_concatenation_case
to_vowel_concatenation_case(text: str) -> str

Concatenates all vowels from the text.

Parameters:

Name Type Description Default
text str

The text to process

required

Returns:

Type Description
str

A string of all vowels concatenated

Example

to_vowel_concatenation_case("Hello World") 'eoo'

case_to_vowel_removal
Vowel Removal Converter

Remove all vowels from text.

Functions
to_vowel_removal_case
to_vowel_removal_case(text: str) -> str

Remove all vowels from the text.

Parameters:

Name Type Description Default
text str

The text to convert

required

Returns:

Type Description
str

The text with all vowels removed

Example

to_vowel_removal_case("Hello World") 'Hll Wrld'

converter_string_to_binary
Rite - String - String to Binary Converter Module

Provides functionality to convert strings to binary values.

Functions
convert_string_to_binary
convert_string_to_binary(text: str) -> str
String to Binary Converter

Convert the text to binary form. Example: 'AB' -> '01000001 01000010'

Parameters: text (str): The text to convert.

Returns

str: The text in binary form.

converter_string_to_bool
Rite - String - String to Boolean Converter Module

Provides functionality to convert strings to boolean values.

Functions
convert_string_to_bool
convert_string_to_bool(val: str | None) -> bool | None
String to Boolean Converter

Convert a string representation of a boolean value to a boolean.

converter_string_to_datetime
Rite - String - String to Datetime Converter Module

Provides functionality to convert strings to datetime values.

Functions
convert_string_to_datetime
convert_string_to_datetime(value: str | None) -> datetime | None
String to Datetime Converter

Convert a string to a timezone-aware datetime object (UTC).

Parses a timestamp like '2024-12-11 11:42:34.049271+00' or ISO-ish strings. Returns None on blank or invalid input.

Supports ISO 8601 format with optional timezone. Naive datetimes are converted to UTC.

Parameters:

Name Type Description Default
value str | None

The string to convert.

required

Returns:

Type Description
datetime | None

A timezone-aware datetime object in UTC, or None.

converter_string_to_decimal
Rite - String - String to Decimal Converter Module

Provides functionality to convert strings to decimal values.

Functions
convert_string_to_decimal
convert_string_to_decimal(value: str | None, length: int = 3) -> Decimal | None
String to Decimal Converter

Convert a string to a Decimal, quantized to length decimal places.

Parameters:

Name Type Description Default
value str | None

The input string (or None).

required
length int

Number of decimal places to quantize to. Default is 3.

3

Returns:

Type Description
Decimal | None

Decimal quantized to length places, or None if conversion fails.

converter_string_to_float
Rite - String - String to Float Converter Module

Provides functionality to convert strings to float values.

Functions
convert_string_to_float
convert_string_to_float(val: str) -> float | None

Convert a string representation of a float value to a float.

converter_string_to_int
Rite - String - String to Int Converter Module

Provides functionality to convert strings to integer values.

Functions
convert_string_to_int
convert_string_to_int(val: str) -> int | None

Convert a string representation of an integer value to an integer.

string_clean
String Cleaning

Clean and normalize string values.

Functions
string_clean
string_clean(val: str | None) -> str | None

Trim string; treat empty, 'none' and 'null' as None.

Parameters:

Name Type Description Default
val str | None

Input string value

required

Returns:

Type Description
str | None

Cleaned string or None

Example

string_clean(" hello ") 'hello' string_clean("none") None

is_palindrome

Palindrome Checker

Check if text is a palindrome.

Functions
is_palindrome
is_palindrome(text: str, ignore_case: bool = True, ignore_spaces: bool = True) -> bool

Check if text is a palindrome.

Parameters:

Name Type Description Default
text str

Input text string

required
ignore_case bool

Whether to ignore case differences

True
ignore_spaces bool

Whether to ignore spaces and non-alphanumeric

True

Returns:

Type Description
bool

True if text is a palindrome, False otherwise

Example

is_palindrome("A man a plan a canal Panama") True

longest_word

Longest Word Finder

Find the longest word in text.

Functions
longest_word
longest_word(text: str) -> str

Find the longest word in text.

Parameters:

Name Type Description Default
text str

Input text string

required

Returns:

Type Description
str

The longest word

Raises:

Type Description
ValueError

If text contains no words

Example

longest_word("hello world") 'hello'

manipulation

Manipulation Module

Text manipulation utilities.

This submodule provides utilities for manipulating text including truncation, padding, and wrapping.

Examples

from rite.text.manipulation import text_truncate, text_pad_left text_truncate("Hello World", 8) 'Hello...' text_pad_left("5", 3, "0") '005'

Modules
text_pad_left
Text Pad Left

Pad text on the left.

Examples

from rite.text.manipulation import text_pad_left text_pad_left("5", 3, "0") '005'

Functions
text_pad_left
text_pad_left(text: str, width: int, fill_char: str = ' ') -> str

Pad text on the left to width.

Parameters:

Name Type Description Default
text str

Text to pad.

required
width int

Target width.

required
fill_char str

Character to pad with.

' '

Returns:

Type Description
str

Left-padded text.

Examples:

>>> text_pad_left("5", 3, "0")
'005'
>>> text_pad_left("Hi", 5)
'   Hi'
Notes

Uses str.rjust() method.

text_pad_right
Text Pad Right

Pad text on the right.

Examples

from rite.text.manipulation import text_pad_right text_pad_right("Hi", 5) 'Hi '

Functions
text_pad_right
text_pad_right(text: str, width: int, fill_char: str = ' ') -> str

Pad text on the right to width.

Parameters:

Name Type Description Default
text str

Text to pad.

required
width int

Target width.

required
fill_char str

Character to pad with.

' '

Returns:

Type Description
str

Right-padded text.

Examples:

>>> text_pad_right("Hi", 5)
'Hi   '
>>> text_pad_right("5", 3, "0")
'500'
Notes

Uses str.ljust() method.

text_truncate
Text Truncate

Truncate text to maximum length.

Examples

from rite.text.manipulation import text_truncate text_truncate("Hello World", 5) 'Hello...'

Functions
text_truncate
text_truncate(text: str, max_length: int, suffix: str = '...') -> str

Truncate text to maximum length.

Parameters:

Name Type Description Default
text str

Text to truncate.

required
max_length int

Maximum length (including suffix).

required
suffix str

Suffix to add when truncated.

'...'

Returns:

Type Description
str

Truncated text with suffix if needed.

Examples:

>>> text_truncate("Hello World", 5)
'Hello...'
>>> text_truncate("Hi", 10)
'Hi'
Notes

Suffix length is included in max_length.

text_wrap
Text Wrap

Wrap text to specified width.

Examples

from rite.text.manipulation import text_wrap text_wrap("Hello World", 5) ['Hello', 'World']

Functions
text_wrap
text_wrap(text: str, width: int = 70) -> list[str]

Wrap text to specified width.

Parameters:

Name Type Description Default
text str

Text to wrap.

required
width int

Maximum line width.

70

Returns:

Type Description
list[str]

List of wrapped lines.

Examples:

>>> text_wrap("Hello World", 5)
['Hello', 'World']
>>> text_wrap("A long sentence", 10)
['A long', 'sentence']
Notes

Uses textwrap.wrap() from stdlib.

morse

Modules
morse_decode
Morse Code Decoder

Convert Morse code to text.

Functions
morse_decode
morse_decode(morse_code: str, separator: str = ' ') -> str

Convert Morse code to text.

Parameters:

Name Type Description Default
morse_code str

Morse code string to decode

required
separator str

Character separating Morse code symbols

' '

Returns:

Type Description
str

Decoded text string

Raises:

Type Description
ValueError

If invalid Morse code sequence encountered

Example

morse_decode(".... . .-.. .-.. ---") 'HELLO'

morse_encode
Morse Code Encoder

Convert text to Morse code.

Functions
morse_encode
morse_encode(text: str, separator: str = ' ') -> str

Convert text to Morse code.

Parameters:

Name Type Description Default
text str

Text string to encode

required
separator str

Character to separate Morse code symbols

' '

Returns:

Type Description
str

Morse code string

Example

morse_encode("HELLO") '.... . .-.. .-.. ---'

morse_decode

Morse Code Decoder

Convert Morse code to text.

Functions
morse_decode
morse_decode(morse_code: str, separator: str = ' ') -> str

Convert Morse code to text.

Parameters:

Name Type Description Default
morse_code str

Morse code string to decode

required
separator str

Character separating Morse code symbols

' '

Returns:

Type Description
str

Decoded text string

Raises:

Type Description
ValueError

If invalid Morse code sequence encountered

Example

morse_decode(".... . .-.. .-.. ---") 'HELLO'

morse_encode

Morse Code Encoder

Convert text to Morse code.

Functions
morse_encode
morse_encode(text: str, separator: str = ' ') -> str

Convert text to Morse code.

Parameters:

Name Type Description Default
text str

Text string to encode

required
separator str

Character to separate Morse code symbols

' '

Returns:

Type Description
str

Morse code string

Example

morse_encode("HELLO") '.... . .-.. .-.. ---'

random

Modules
random_alphanumeric
Random Alphanumeric Generator

Generate random alphanumeric strings.

Functions
random_alphanumeric
random_alphanumeric(length: int = 16, include_lowercase: bool = True, include_uppercase: bool = True) -> str

Generate a random alphanumeric string.

Parameters:

Name Type Description Default
length int

Length of the random string

16
include_lowercase bool

Include lowercase letters

True
include_uppercase bool

Include uppercase letters

True

Returns:

Type Description
str

Random alphanumeric string

Raises:

Type Description
ValueError

If both include_lowercase and include_uppercase are False

Example

len(random_alphanumeric(10)) 10

random_hex
Random Hexadecimal Generator

Generate random hexadecimal strings.

Functions
random_hex
random_hex(length: int = 16, uppercase: bool = False) -> str

Generate a random hexadecimal string.

Parameters:

Name Type Description Default
length int

Length of the random hex string

16
uppercase bool

Use uppercase letters for hex digits

False

Returns:

Type Description
str

Random hexadecimal string

Example

len(random_hex(10)) 10

random_string
Random String Generator

Generate secure random strings.

Functions
random_string
random_string(length: int = 16, charset: str = string.ascii_letters + string.digits) -> str

Generate a secure random string.

Parameters:

Name Type Description Default
length int

Length of the random string

16
charset str

Character set to use for generation

ascii_letters + digits

Returns:

Type Description
str

Secure random string

Example

len(random_string(20)) 20

random_alphanumeric

Random Alphanumeric Generator

Generate random alphanumeric strings.

Functions
random_alphanumeric
random_alphanumeric(length: int = 16, include_lowercase: bool = True, include_uppercase: bool = True) -> str

Generate a random alphanumeric string.

Parameters:

Name Type Description Default
length int

Length of the random string

16
include_lowercase bool

Include lowercase letters

True
include_uppercase bool

Include uppercase letters

True

Returns:

Type Description
str

Random alphanumeric string

Raises:

Type Description
ValueError

If both include_lowercase and include_uppercase are False

Example

len(random_alphanumeric(10)) 10

random_hex

Random Hexadecimal Generator

Generate random hexadecimal strings.

Functions
random_hex
random_hex(length: int = 16, uppercase: bool = False) -> str

Generate a random hexadecimal string.

Parameters:

Name Type Description Default
length int

Length of the random hex string

16
uppercase bool

Use uppercase letters for hex digits

False

Returns:

Type Description
str

Random hexadecimal string

Example

len(random_hex(10)) 10

random_string

Random String Generator

Generate secure random strings.

Functions
random_string
random_string(length: int = 16, charset: str = string.ascii_letters + string.digits) -> str

Generate a secure random string.

Parameters:

Name Type Description Default
length int

Length of the random string

16
charset str

Character set to use for generation

ascii_letters + digits

Returns:

Type Description
str

Secure random string

Example

len(random_string(20)) 20

sanitize

Functions
clean
clean(text: str) -> str

Remove extra whitespace from text.


text: The input text to clean.

str: The cleaned text with normalized whitespace.
sanitize
sanitize(text: str, replacement: str = '_') -> str

Sanitize text to create safe ASCII identifiers.


text: The input text to sanitize.
replacement: The character to replace non-alphanumeric characters.

str: The sanitized text with only ASCII alphanumeric characters.
Modules
sanitize_clean
Text Cleaning

Remove extra whitespace from text.

Functions
clean
clean(text: str) -> str

Remove extra whitespace from text.


text: The input text to clean.

str: The cleaned text with normalized whitespace.
sanitize_text
Text Sanitization

Sanitize text to create safe ASCII identifiers.

Functions
sanitize
sanitize(text: str, replacement: str = '_') -> str

Sanitize text to create safe ASCII identifiers.


text: The input text to sanitize.
replacement: The character to replace non-alphanumeric characters.

str: The sanitized text with only ASCII alphanumeric characters.

search

Search Module

Text search utilities.

This submodule provides utilities for searching within text including contains, starts_with, ends_with, find, and count operations.

Examples

from rite.text.search import text_contains, text_find text_contains("Hello World", "World") True text_find("Hello World", "World") 6

Modules
text_contains
Text Contains

Check if text contains a substring.

Examples

from rite.text.search import text_contains text_contains("Hello World", "World") True

Functions
text_contains
text_contains(text: str, substring: str) -> bool

Check if text contains substring.

Parameters:

Name Type Description Default
text str

Text to search in.

required
substring str

Substring to search for.

required

Returns:

Type Description
bool

True if substring found.

Examples:

>>> text_contains("Hello World", "World")
True
>>> text_contains("Hello", "Goodbye")
False
Notes

Case-sensitive search.

text_count
Text Count

Count substring occurrences in text.

Examples

from rite.text.search import text_count text_count("Hello Hello World", "Hello") 2

Functions
text_count
text_count(text: str, substring: str) -> int

Count substring occurrences.

Parameters:

Name Type Description Default
text str

Text to search in.

required
substring str

Substring to count.

required

Returns:

Type Description
int

Number of non-overlapping occurrences.

Examples:

>>> text_count("Hello Hello World", "Hello")
2
>>> text_count("aaa", "aa")
1
Notes

Uses str.count() which counts non-overlapping occurrences.

text_ends_with
Text Ends With

Check if text ends with suffix.

Examples

from rite.text.search import text_ends_with text_ends_with("Hello World", "World") True

Functions
text_ends_with
text_ends_with(text: str, suffix: str) -> bool

Check if text ends with suffix.

Parameters:

Name Type Description Default
text str

Text to check.

required
suffix str

Suffix to search for.

required

Returns:

Type Description
bool

True if text ends with suffix.

Examples:

>>> text_ends_with("Hello World", "World")
True
>>> text_ends_with("Hello", "World")
False
Notes

Uses str.endswith() method.

text_find
Text Find

Find substring position in text.

Examples

from rite.text.search import text_find text_find("Hello World", "World") 6

Functions
text_find
text_find(text: str, substring: str) -> int

Find substring position in text.

Parameters:

Name Type Description Default
text str

Text to search in.

required
substring str

Substring to find.

required

Returns:

Type Description
int

Index of substring or -1 if not found.

Examples:

>>> text_find("Hello World", "World")
6
>>> text_find("Hello", "Goodbye")
-1
Notes

Uses str.find() method. Returns -1 if not found.

text_starts_with
Text Starts With

Check if text starts with prefix.

Examples

from rite.text.search import text_starts_with text_starts_with("Hello World", "Hello") True

Functions
text_starts_with
text_starts_with(text: str, prefix: str) -> bool

Check if text starts with prefix.

Parameters:

Name Type Description Default
text str

Text to check.

required
prefix str

Prefix to search for.

required

Returns:

Type Description
bool

True if text starts with prefix.

Examples:

>>> text_starts_with("Hello World", "Hello")
True
>>> text_starts_with("Hello", "World")
False
Notes

Uses str.startswith() method.

slug

Slug Generation Module

Functions for generating URL-friendly slugs.

Functions
add_slug_prefix
add_slug_prefix(slug: str, prefix: str, delimiter: str = '-') -> str

Add a prefix to a slug.

Parameters:

Name Type Description Default
slug str

The original slug.

required
prefix str

The prefix to add.

required
delimiter str

The delimiter used in the slug (default: "-").

'-'

Returns:

Type Description
str

The slug with the prefix added.

Example

add_slug_prefix("world", "hello") 'hello-world' add_slug_prefix("world", "hello", delimiter="_") 'hello_world'

add_slug_suffix
add_slug_suffix(slug: str, suffix: str, delimiter: str = '-') -> str

Add a suffix to a slug.

Parameters:

Name Type Description Default
slug str

The original slug.

required
suffix str

The suffix to add.

required
delimiter str

The delimiter used in the slug (default: "-").

'-'

Returns:

Type Description
str

The slug with the suffix added.

Example

add_slug_suffix("hello", "world") 'hello-world' add_slug_suffix("hello", "world", delimiter="_") 'hello_world'

is_valid_slug
is_valid_slug(slug: str, delimiter: str = '-') -> bool

Validate if a string is a valid slug.

A valid slug contains only lowercase letters, numbers, and delimiters, and does not start or end with a delimiter.

Parameters:

Name Type Description Default
slug str

The string to validate.

required
delimiter str

The delimiter used in the slug (default: "-").

'-'

Returns:

Type Description
bool

True if the string is a valid slug, False otherwise.

Example

is_valid_slug("hello-world") True is_valid_slug("Hello-World") False is_valid_slug("-hello-world") False is_valid_slug("hello--world") False

unique_slug
unique_slug(slug: str, existing_slugs: set[str] | list[str], delimiter: str = '-') -> str

Generate a unique slug by appending an incremental number.

If the slug already exists in the set of existing slugs, appends an incremental number (starting from 1) until a unique slug is found.

Parameters:

Name Type Description Default
slug str

The original slug.

required
existing_slugs set[str] | list[str]

A set or list of existing slugs to check against.

required
delimiter str

The delimiter used in the slug (default: "-").

'-'

Returns:

Type Description
str

A unique slug with an incremental number if needed.

Example

unique_slug("hello-world", {"hello-world"}) 'hello-world-1' unique_slug("hello-world", {"hello-world", "hello-world-1"}) 'hello-world-2' unique_slug("hello-world", []) 'hello-world'

Modules
slug_add_prefix
Add Slug Prefix Function

Add a prefix to a slug.

Functions
add_slug_prefix
add_slug_prefix(slug: str, prefix: str, delimiter: str = '-') -> str

Add a prefix to a slug.

Parameters:

Name Type Description Default
slug str

The original slug.

required
prefix str

The prefix to add.

required
delimiter str

The delimiter used in the slug (default: "-").

'-'

Returns:

Type Description
str

The slug with the prefix added.

Example

add_slug_prefix("world", "hello") 'hello-world' add_slug_prefix("world", "hello", delimiter="_") 'hello_world'

slug_add_suffix
Add Slug Suffix Function

Add a suffix to a slug.

Functions
add_slug_suffix
add_slug_suffix(slug: str, suffix: str, delimiter: str = '-') -> str

Add a suffix to a slug.

Parameters:

Name Type Description Default
slug str

The original slug.

required
suffix str

The suffix to add.

required
delimiter str

The delimiter used in the slug (default: "-").

'-'

Returns:

Type Description
str

The slug with the suffix added.

Example

add_slug_suffix("hello", "world") 'hello-world' add_slug_suffix("hello", "world", delimiter="_") 'hello_world'

slug_is_valid
Is Valid Slug Function

Validate slug format.

Functions
is_valid_slug
is_valid_slug(slug: str, delimiter: str = '-') -> bool

Validate if a string is a valid slug.

A valid slug contains only lowercase letters, numbers, and delimiters, and does not start or end with a delimiter.

Parameters:

Name Type Description Default
slug str

The string to validate.

required
delimiter str

The delimiter used in the slug (default: "-").

'-'

Returns:

Type Description
bool

True if the string is a valid slug, False otherwise.

Example

is_valid_slug("hello-world") True is_valid_slug("Hello-World") False is_valid_slug("-hello-world") False is_valid_slug("hello--world") False

slug_unique
Unique Slug Function

Generate unique slugs with incremental numbers.

Functions
unique_slug
unique_slug(slug: str, existing_slugs: set[str] | list[str], delimiter: str = '-') -> str

Generate a unique slug by appending an incremental number.

If the slug already exists in the set of existing slugs, appends an incremental number (starting from 1) until a unique slug is found.

Parameters:

Name Type Description Default
slug str

The original slug.

required
existing_slugs set[str] | list[str]

A set or list of existing slugs to check against.

required
delimiter str

The delimiter used in the slug (default: "-").

'-'

Returns:

Type Description
str

A unique slug with an incremental number if needed.

Example

unique_slug("hello-world", {"hello-world"}) 'hello-world-1' unique_slug("hello-world", {"hello-world", "hello-world-1"}) 'hello-world-2' unique_slug("hello-world", []) 'hello-world'

slugify
Slugify Function

Generate URL-friendly slugs from text.

Functions
slugify
slugify(text: str, delimiter: str = '-', max_length: int | None = None, lowercase: bool = True, custom_replacements: dict[str, str] | None = None) -> str

Generate a URL-friendly slug from text.

Converts the input text to a URL-friendly slug by: - Normalizing Unicode characters - Applying custom character replacements (optional) - Converting to lowercase (optional) - Replacing spaces and special characters with delimiters - Truncating to maximum length (optional)

Parameters:

Name Type Description Default
text str

The text to convert into a slug.

required
delimiter str

The delimiter to use for separating words (default: "-").

'-'
max_length int | None

Maximum length of the slug. If None, no limit is applied.

None
lowercase bool

Convert slug to lowercase if True (default: True).

True
custom_replacements dict[str, str] | None

Dictionary of custom character replacements.

None

Returns:

Type Description
str

A URL-friendly slug.

Example

slugify("Hello World!") 'hello-world' slugify("Café au Lait", delimiter="_") 'cafe_au_lait' slugify("Hello World", max_length=8) 'hello-wo' slugify("Hello & World", custom_replacements={"&": "and"}) 'hello-and-world'

slugify

Slugify Function

Generate URL-friendly slugs from text.

Functions
slugify
slugify(text: str, delimiter: str = '-', max_length: int | None = None, lowercase: bool = True, custom_replacements: dict[str, str] | None = None) -> str

Generate a URL-friendly slug from text.

Converts the input text to a URL-friendly slug by: - Normalizing Unicode characters - Applying custom character replacements (optional) - Converting to lowercase (optional) - Replacing spaces and special characters with delimiters - Truncating to maximum length (optional)

Parameters:

Name Type Description Default
text str

The text to convert into a slug.

required
delimiter str

The delimiter to use for separating words (default: "-").

'-'
max_length int | None

Maximum length of the slug. If None, no limit is applied.

None
lowercase bool

Convert slug to lowercase if True (default: True).

True
custom_replacements dict[str, str] | None

Dictionary of custom character replacements.

None

Returns:

Type Description
str

A URL-friendly slug.

Example

slugify("Hello World!") 'hello-world' slugify("Café au Lait", delimiter="_") 'cafe_au_lait' slugify("Hello World", max_length=8) 'hello-wo' slugify("Hello & World", custom_replacements={"&": "and"}) 'hello-and-world'

text_contains

Text Contains

Check if text contains a substring.

Examples

from rite.text.search import text_contains text_contains("Hello World", "World") True

Functions
text_contains
text_contains(text: str, substring: str) -> bool

Check if text contains substring.

Parameters:

Name Type Description Default
text str

Text to search in.

required
substring str

Substring to search for.

required

Returns:

Type Description
bool

True if substring found.

Examples:

>>> text_contains("Hello World", "World")
True
>>> text_contains("Hello", "Goodbye")
False
Notes

Case-sensitive search.

text_count

Text Count

Count substring occurrences in text.

Examples

from rite.text.search import text_count text_count("Hello Hello World", "Hello") 2

Functions
text_count
text_count(text: str, substring: str) -> int

Count substring occurrences.

Parameters:

Name Type Description Default
text str

Text to search in.

required
substring str

Substring to count.

required

Returns:

Type Description
int

Number of non-overlapping occurrences.

Examples:

>>> text_count("Hello Hello World", "Hello")
2
>>> text_count("aaa", "aa")
1
Notes

Uses str.count() which counts non-overlapping occurrences.

text_ends_with

Text Ends With

Check if text ends with suffix.

Examples

from rite.text.search import text_ends_with text_ends_with("Hello World", "World") True

Functions
text_ends_with
text_ends_with(text: str, suffix: str) -> bool

Check if text ends with suffix.

Parameters:

Name Type Description Default
text str

Text to check.

required
suffix str

Suffix to search for.

required

Returns:

Type Description
bool

True if text ends with suffix.

Examples:

>>> text_ends_with("Hello World", "World")
True
>>> text_ends_with("Hello", "World")
False
Notes

Uses str.endswith() method.

text_find

Text Find

Find substring position in text.

Examples

from rite.text.search import text_find text_find("Hello World", "World") 6

Functions
text_find
text_find(text: str, substring: str) -> int

Find substring position in text.

Parameters:

Name Type Description Default
text str

Text to search in.

required
substring str

Substring to find.

required

Returns:

Type Description
int

Index of substring or -1 if not found.

Examples:

>>> text_find("Hello World", "World")
6
>>> text_find("Hello", "Goodbye")
-1
Notes

Uses str.find() method. Returns -1 if not found.

text_is_alpha

Text Is Alpha

Check if text is alphabetic.

Examples

from rite.text.validation import text_is_alpha text_is_alpha("Hello") True

Functions
text_is_alpha
text_is_alpha(text: str) -> bool

Check if text contains only alphabetic characters.

Parameters:

Name Type Description Default
text str

String to validate.

required

Returns:

Type Description
bool

True if alphabetic, False otherwise.

Examples:

>>> text_is_alpha("Hello")
True
>>> text_is_alpha("Hello123")
False
Notes

Uses str.isalpha() method.

text_is_alphanumeric

Text Is Alphanumeric

Check if text is alphanumeric.

Examples

from rite.text.validation import text_is_alphanumeric text_is_alphanumeric("Hello123") True

Functions
text_is_alphanumeric
text_is_alphanumeric(text: str) -> bool

Check if text contains only alphanumeric characters.

Parameters:

Name Type Description Default
text str

String to validate.

required

Returns:

Type Description
bool

True if alphanumeric, False otherwise.

Examples:

>>> text_is_alphanumeric("Hello123")
True
>>> text_is_alphanumeric("Hello 123")
False
Notes

Uses str.isalnum() method.

text_is_email

Text Is Email

Validate email address format.

Examples

from rite.text.validation import text_is_email text_is_email("user@example.com") True

Functions
text_is_email
text_is_email(text: str) -> bool

Check if text is valid email format.

Parameters:

Name Type Description Default
text str

String to validate.

required

Returns:

Type Description
bool

True if valid email format, False otherwise.

Examples:

>>> text_is_email("[email protected]")
True
>>> text_is_email("invalid.email")
False
Notes

Basic email validation using regex. Not RFC-compliant, for simple checks only.

text_is_numeric

Text Is Numeric

Check if text is numeric.

Examples

from rite.text.validation import text_is_numeric text_is_numeric("123") True

Functions
text_is_numeric
text_is_numeric(text: str) -> bool

Check if text contains only numeric characters.

Parameters:

Name Type Description Default
text str

String to validate.

required

Returns:

Type Description
bool

True if numeric, False otherwise.

Examples:

>>> text_is_numeric("123")
True
>>> text_is_numeric("12.34")
False
>>> text_is_numeric("abc")
False
Notes

Uses str.isnumeric() method. Returns False for floats with decimals.

text_pad_left

Text Pad Left

Pad text on the left.

Examples

from rite.text.manipulation import text_pad_left text_pad_left("5", 3, "0") '005'

Functions
text_pad_left
text_pad_left(text: str, width: int, fill_char: str = ' ') -> str

Pad text on the left to width.

Parameters:

Name Type Description Default
text str

Text to pad.

required
width int

Target width.

required
fill_char str

Character to pad with.

' '

Returns:

Type Description
str

Left-padded text.

Examples:

>>> text_pad_left("5", 3, "0")
'005'
>>> text_pad_left("Hi", 5)
'   Hi'
Notes

Uses str.rjust() method.

text_pad_right

Text Pad Right

Pad text on the right.

Examples

from rite.text.manipulation import text_pad_right text_pad_right("Hi", 5) 'Hi '

Functions
text_pad_right
text_pad_right(text: str, width: int, fill_char: str = ' ') -> str

Pad text on the right to width.

Parameters:

Name Type Description Default
text str

Text to pad.

required
width int

Target width.

required
fill_char str

Character to pad with.

' '

Returns:

Type Description
str

Right-padded text.

Examples:

>>> text_pad_right("Hi", 5)
'Hi   '
>>> text_pad_right("5", 3, "0")
'500'
Notes

Uses str.ljust() method.

text_starts_with

Text Starts With

Check if text starts with prefix.

Examples

from rite.text.search import text_starts_with text_starts_with("Hello World", "Hello") True

Functions
text_starts_with
text_starts_with(text: str, prefix: str) -> bool

Check if text starts with prefix.

Parameters:

Name Type Description Default
text str

Text to check.

required
prefix str

Prefix to search for.

required

Returns:

Type Description
bool

True if text starts with prefix.

Examples:

>>> text_starts_with("Hello World", "Hello")
True
>>> text_starts_with("Hello", "World")
False
Notes

Uses str.startswith() method.

text_truncate

Text Truncate

Truncate text to maximum length.

Examples

from rite.text.manipulation import text_truncate text_truncate("Hello World", 5) 'Hello...'

Functions
text_truncate
text_truncate(text: str, max_length: int, suffix: str = '...') -> str

Truncate text to maximum length.

Parameters:

Name Type Description Default
text str

Text to truncate.

required
max_length int

Maximum length (including suffix).

required
suffix str

Suffix to add when truncated.

'...'

Returns:

Type Description
str

Truncated text with suffix if needed.

Examples:

>>> text_truncate("Hello World", 5)
'Hello...'
>>> text_truncate("Hi", 10)
'Hi'
Notes

Suffix length is included in max_length.

text_wrap

Text Wrap

Wrap text to specified width.

Examples

from rite.text.manipulation import text_wrap text_wrap("Hello World", 5) ['Hello', 'World']

Functions
text_wrap
text_wrap(text: str, width: int = 70) -> list[str]

Wrap text to specified width.

Parameters:

Name Type Description Default
text str

Text to wrap.

required
width int

Maximum line width.

70

Returns:

Type Description
list[str]

List of wrapped lines.

Examples:

>>> text_wrap("Hello World", 5)
['Hello', 'World']
>>> text_wrap("A long sentence", 10)
['A long', 'sentence']
Notes

Uses textwrap.wrap() from stdlib.

to_camel_case

Camel Case Conversion

Convert text to camelCase format.

Functions
to_camel_case
to_camel_case(text: str) -> str

Convert text to camelCase.

Converts the input text to camel case where the first word is lowercase and subsequent words are capitalized.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to camelCase.

Example

to_camel_case("hello world") 'helloWorld' to_camel_case("Hello World") 'helloWorld'

to_constant_case

Constant Case Conversion

Convert text to CONSTANT_CASE format.

Functions
to_constant_case
to_constant_case(text: str) -> str

Convert text to CONSTANT_CASE.

Converts the input text to constant case (screaming snake case) by replacing spaces and special characters with underscores and converting to uppercase.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to CONSTANT_CASE.

Example

to_constant_case("Hello World") 'HELLO_WORLD' to_constant_case("helloWorld") 'HELLO_WORLD'

to_dot_case

Dot Case Conversion

Convert text to dot.case format.

Functions
to_dot_case
to_dot_case(text: str) -> str

Convert text to dot.case.

Converts the input text to dot case by replacing spaces and special characters with dots and converting to lowercase.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to dot.case.

Example

to_dot_case("Hello World") 'hello.world' to_dot_case("helloWorld") 'hello.world'

to_kebab_case

Kebab Case Conversion

Convert text to kebab-case format.

Functions
to_kebab_case
to_kebab_case(text: str) -> str

Convert text to kebab-case.

Converts the input text to kebab case by replacing spaces and special characters with hyphens and converting to lowercase.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to kebab-case.

Example

to_kebab_case("Hello World") 'hello-world' to_kebab_case("helloWorld") 'hello-world'

to_lower_case

Lowercase Conversion

Convert text to lowercase format.

Functions
to_lower_case
to_lower_case(text: str) -> str

Convert text to lowercase.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to lowercase.

Example

to_lower_case("Hello World") 'hello world'

to_pascal_case

Pascal Case Conversion

Convert text to PascalCase format.

Functions
to_pascal_case
to_pascal_case(text: str) -> str

Convert text to PascalCase.

Converts the input text to Pascal case where all words are capitalized and joined without separators.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to PascalCase.

Example

to_pascal_case("hello world") 'HelloWorld' to_pascal_case("hello_world") 'HelloWorld'

to_path_case

Path Case Conversion

Convert text to path/case format.

Functions
to_path_case
to_path_case(text: str) -> str

Convert text to path/case.

Converts the input text to path case by replacing spaces and special characters with forward slashes and converting to lowercase.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to path/case.

Example

to_path_case("Hello World") 'hello/world' to_path_case("helloWorld") 'hello/world'

to_sentence_case

Sentence Case Conversion

Convert text to Sentence case format.

Functions
to_sentence_case
to_sentence_case(text: str) -> str

Convert text to Sentence case.

Converts the input text to sentence case where only the first letter of the first word is capitalized and the rest is lowercase.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to Sentence case.

Example

to_sentence_case("hello world") 'Hello world' to_sentence_case("HELLO WORLD") 'Hello world'

to_snake_case

Snake Case Conversion

Convert text to snake_case format.

Functions
to_snake_case
to_snake_case(text: str) -> str

Convert text to snake_case.

Converts the input text to snake case by replacing spaces and special characters with underscores and converting to lowercase.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to snake_case.

Example

to_snake_case("Hello World") 'hello_world' to_snake_case("helloWorld") 'hello_world'

to_title_case

Title Case Conversion

Convert text to Title Case format.

Functions
to_title_case
to_title_case(text: str) -> str

Convert text to Title Case.

Converts the input text to title case where the first letter of each word is capitalized.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to Title Case.

Example

to_title_case("hello world") 'Hello World' to_title_case("HELLO WORLD") 'Hello World'

to_upper_case

Uppercase Conversion

Convert text to UPPERCASE format.

Functions
to_upper_case
to_upper_case(text: str) -> str

Convert text to UPPERCASE.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to UPPERCASE.

Example

to_upper_case("Hello World") 'HELLO WORLD'

validation

Validation Module

Text validation utilities.

This submodule provides utilities for validating text formats and content types.

Examples

from rite.text.validation import text_is_email, text_is_numeric text_is_email("user@example.com") True text_is_numeric("123") True

Modules
text_is_alpha
Text Is Alpha

Check if text is alphabetic.

Examples

from rite.text.validation import text_is_alpha text_is_alpha("Hello") True

Functions
text_is_alpha
text_is_alpha(text: str) -> bool

Check if text contains only alphabetic characters.

Parameters:

Name Type Description Default
text str

String to validate.

required

Returns:

Type Description
bool

True if alphabetic, False otherwise.

Examples:

>>> text_is_alpha("Hello")
True
>>> text_is_alpha("Hello123")
False
Notes

Uses str.isalpha() method.

text_is_alphanumeric
Text Is Alphanumeric

Check if text is alphanumeric.

Examples

from rite.text.validation import text_is_alphanumeric text_is_alphanumeric("Hello123") True

Functions
text_is_alphanumeric
text_is_alphanumeric(text: str) -> bool

Check if text contains only alphanumeric characters.

Parameters:

Name Type Description Default
text str

String to validate.

required

Returns:

Type Description
bool

True if alphanumeric, False otherwise.

Examples:

>>> text_is_alphanumeric("Hello123")
True
>>> text_is_alphanumeric("Hello 123")
False
Notes

Uses str.isalnum() method.

text_is_email
Text Is Email

Validate email address format.

Examples

from rite.text.validation import text_is_email text_is_email("user@example.com") True

Functions
text_is_email
text_is_email(text: str) -> bool

Check if text is valid email format.

Parameters:

Name Type Description Default
text str

String to validate.

required

Returns:

Type Description
bool

True if valid email format, False otherwise.

Examples:

>>> text_is_email("[email protected]")
True
>>> text_is_email("invalid.email")
False
Notes

Basic email validation using regex. Not RFC-compliant, for simple checks only.

text_is_numeric
Text Is Numeric

Check if text is numeric.

Examples

from rite.text.validation import text_is_numeric text_is_numeric("123") True

Functions
text_is_numeric
text_is_numeric(text: str) -> bool

Check if text contains only numeric characters.

Parameters:

Name Type Description Default
text str

String to validate.

required

Returns:

Type Description
bool

True if numeric, False otherwise.

Examples:

>>> text_is_numeric("123")
True
>>> text_is_numeric("12.34")
False
>>> text_is_numeric("abc")
False
Notes

Uses str.isnumeric() method. Returns False for floats with decimals.

word_count

Word Counting

Count words in text.

Functions
word_count
word_count(text: str) -> int

Count the number of words in text.

Parameters:

Name Type Description Default
text str

Input text string

required

Returns:

Type Description
int

Number of words

Example

word_count("hello world") 2

Submodules

Case Conversions

Transform text between different naming conventions and styles.

Case Conversion Module

Functions for converting text between different case formats.

Modules

to_snake_case

Snake Case Conversion

Convert text to snake_case format.

Functions
to_snake_case
to_snake_case(text: str) -> str

Convert text to snake_case.

Converts the input text to snake case by replacing spaces and special characters with underscores and converting to lowercase.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to snake_case.

Example

to_snake_case("Hello World") 'hello_world' to_snake_case("helloWorld") 'hello_world'

to_camel_case

Camel Case Conversion

Convert text to camelCase format.

Functions
to_camel_case
to_camel_case(text: str) -> str

Convert text to camelCase.

Converts the input text to camel case where the first word is lowercase and subsequent words are capitalized.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to camelCase.

Example

to_camel_case("hello world") 'helloWorld' to_camel_case("Hello World") 'helloWorld'

to_pascal_case

Pascal Case Conversion

Convert text to PascalCase format.

Functions
to_pascal_case
to_pascal_case(text: str) -> str

Convert text to PascalCase.

Converts the input text to Pascal case where all words are capitalized and joined without separators.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to PascalCase.

Example

to_pascal_case("hello world") 'HelloWorld' to_pascal_case("hello_world") 'HelloWorld'

to_kebab_case

Kebab Case Conversion

Convert text to kebab-case format.

Functions
to_kebab_case
to_kebab_case(text: str) -> str

Convert text to kebab-case.

Converts the input text to kebab case by replacing spaces and special characters with hyphens and converting to lowercase.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to kebab-case.

Example

to_kebab_case("Hello World") 'hello-world' to_kebab_case("helloWorld") 'hello-world'

to_constant_case

Constant Case Conversion

Convert text to CONSTANT_CASE format.

Functions
to_constant_case
to_constant_case(text: str) -> str

Convert text to CONSTANT_CASE.

Converts the input text to constant case (screaming snake case) by replacing spaces and special characters with underscores and converting to uppercase.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to CONSTANT_CASE.

Example

to_constant_case("Hello World") 'HELLO_WORLD' to_constant_case("helloWorld") 'HELLO_WORLD'

to_dot_case

Dot Case Conversion

Convert text to dot.case format.

Functions
to_dot_case
to_dot_case(text: str) -> str

Convert text to dot.case.

Converts the input text to dot case by replacing spaces and special characters with dots and converting to lowercase.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to dot.case.

Example

to_dot_case("Hello World") 'hello.world' to_dot_case("helloWorld") 'hello.world'

to_path_case

Path Case Conversion

Convert text to path/case format.

Functions
to_path_case
to_path_case(text: str) -> str

Convert text to path/case.

Converts the input text to path case by replacing spaces and special characters with forward slashes and converting to lowercase.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to path/case.

Example

to_path_case("Hello World") 'hello/world' to_path_case("helloWorld") 'hello/world'

to_title_case

Title Case Conversion

Convert text to Title Case format.

Functions
to_title_case
to_title_case(text: str) -> str

Convert text to Title Case.

Converts the input text to title case where the first letter of each word is capitalized.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to Title Case.

Example

to_title_case("hello world") 'Hello World' to_title_case("HELLO WORLD") 'Hello World'

to_sentence_case

Sentence Case Conversion

Convert text to Sentence case format.

Functions
to_sentence_case
to_sentence_case(text: str) -> str

Convert text to Sentence case.

Converts the input text to sentence case where only the first letter of the first word is capitalized and the rest is lowercase.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to Sentence case.

Example

to_sentence_case("hello world") 'Hello world' to_sentence_case("HELLO WORLD") 'Hello world'

to_lower_case

Lowercase Conversion

Convert text to lowercase format.

Functions
to_lower_case
to_lower_case(text: str) -> str

Convert text to lowercase.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to lowercase.

Example

to_lower_case("Hello World") 'hello world'

to_upper_case

Uppercase Conversion

Convert text to UPPERCASE format.

Functions
to_upper_case
to_upper_case(text: str) -> str

Convert text to UPPERCASE.

Parameters:

Name Type Description Default
text str

The text to convert.

required

Returns:

Type Description
str

The text converted to UPPERCASE.

Example

to_upper_case("Hello World") 'HELLO WORLD'

Slug Generation

Create URL-friendly slugs from text.

Slug Generation Module

Functions for generating URL-friendly slugs.

Modules

slugify

Slugify Function

Generate URL-friendly slugs from text.

Functions
slugify
slugify(text: str, delimiter: str = '-', max_length: int | None = None, lowercase: bool = True, custom_replacements: dict[str, str] | None = None) -> str

Generate a URL-friendly slug from text.

Converts the input text to a URL-friendly slug by: - Normalizing Unicode characters - Applying custom character replacements (optional) - Converting to lowercase (optional) - Replacing spaces and special characters with delimiters - Truncating to maximum length (optional)

Parameters:

Name Type Description Default
text str

The text to convert into a slug.

required
delimiter str

The delimiter to use for separating words (default: "-").

'-'
max_length int | None

Maximum length of the slug. If None, no limit is applied.

None
lowercase bool

Convert slug to lowercase if True (default: True).

True
custom_replacements dict[str, str] | None

Dictionary of custom character replacements.

None

Returns:

Type Description
str

A URL-friendly slug.

Example

slugify("Hello World!") 'hello-world' slugify("Café au Lait", delimiter="_") 'cafe_au_lait' slugify("Hello World", max_length=8) 'hello-wo' slugify("Hello & World", custom_replacements={"&": "and"}) 'hello-and-world'

slug_unique

Unique Slug Function

Generate unique slugs with incremental numbers.

Functions
unique_slug
unique_slug(slug: str, existing_slugs: set[str] | list[str], delimiter: str = '-') -> str

Generate a unique slug by appending an incremental number.

If the slug already exists in the set of existing slugs, appends an incremental number (starting from 1) until a unique slug is found.

Parameters:

Name Type Description Default
slug str

The original slug.

required
existing_slugs set[str] | list[str]

A set or list of existing slugs to check against.

required
delimiter str

The delimiter used in the slug (default: "-").

'-'

Returns:

Type Description
str

A unique slug with an incremental number if needed.

Example

unique_slug("hello-world", {"hello-world"}) 'hello-world-1' unique_slug("hello-world", {"hello-world", "hello-world-1"}) 'hello-world-2' unique_slug("hello-world", []) 'hello-world'

slug_add_prefix

Add Slug Prefix Function

Add a prefix to a slug.

Functions
add_slug_prefix
add_slug_prefix(slug: str, prefix: str, delimiter: str = '-') -> str

Add a prefix to a slug.

Parameters:

Name Type Description Default
slug str

The original slug.

required
prefix str

The prefix to add.

required
delimiter str

The delimiter used in the slug (default: "-").

'-'

Returns:

Type Description
str

The slug with the prefix added.

Example

add_slug_prefix("world", "hello") 'hello-world' add_slug_prefix("world", "hello", delimiter="_") 'hello_world'

slug_add_suffix

Add Slug Suffix Function

Add a suffix to a slug.

Functions
add_slug_suffix
add_slug_suffix(slug: str, suffix: str, delimiter: str = '-') -> str

Add a suffix to a slug.

Parameters:

Name Type Description Default
slug str

The original slug.

required
suffix str

The suffix to add.

required
delimiter str

The delimiter used in the slug (default: "-").

'-'

Returns:

Type Description
str

The slug with the suffix added.

Example

add_slug_suffix("hello", "world") 'hello-world' add_slug_suffix("hello", "world", delimiter="_") 'hello_world'

slug_is_valid

Is Valid Slug Function

Validate slug format.

Functions
is_valid_slug
is_valid_slug(slug: str, delimiter: str = '-') -> bool

Validate if a string is a valid slug.

A valid slug contains only lowercase letters, numbers, and delimiters, and does not start or end with a delimiter.

Parameters:

Name Type Description Default
slug str

The string to validate.

required
delimiter str

The delimiter used in the slug (default: "-").

'-'

Returns:

Type Description
bool

True if the string is a valid slug, False otherwise.

Example

is_valid_slug("hello-world") True is_valid_slug("Hello-World") False is_valid_slug("-hello-world") False is_valid_slug("hello--world") False

Text Analysis

Analyze text content and structure.

Modules

char_frequency

Character Frequency Analysis

Count character frequency in text.

Functions
char_frequency
char_frequency(text: str) -> dict[str, int]

Count the frequency of each character in text.

Parameters:

Name Type Description Default
text str

Input text string

required

Returns:

Type Description
dict[str, int]

Dictionary mapping characters to their frequency count

Example

char_frequency("hello")

word_count

Word Counting

Count words in text.

Functions
word_count
word_count(text: str) -> int

Count the number of words in text.

Parameters:

Name Type Description Default
text str

Input text string

required

Returns:

Type Description
int

Number of words

Example

word_count("hello world") 2

is_palindrome

Palindrome Checker

Check if text is a palindrome.

Functions
is_palindrome
is_palindrome(text: str, ignore_case: bool = True, ignore_spaces: bool = True) -> bool

Check if text is a palindrome.

Parameters:

Name Type Description Default
text str

Input text string

required
ignore_case bool

Whether to ignore case differences

True
ignore_spaces bool

Whether to ignore spaces and non-alphanumeric

True

Returns:

Type Description
bool

True if text is a palindrome, False otherwise

Example

is_palindrome("A man a plan a canal Panama") True

longest_word

Longest Word Finder

Find the longest word in text.

Functions
longest_word
longest_word(text: str) -> str

Find the longest word in text.

Parameters:

Name Type Description Default
text str

Input text string

required

Returns:

Type Description
str

The longest word

Raises:

Type Description
ValueError

If text contains no words

Example

longest_word("hello world") 'hello'

shortest_word

Shortest Word Finder

Find the shortest word in text.

Functions
shortest_word
shortest_word(text: str) -> str

Find the shortest word in text.

Parameters:

Name Type Description Default
text str

Input text string

required

Returns:

Type Description
str

The shortest word

Raises:

Type Description
ValueError

If text contains no words

Example

shortest_word("hello world") 'hello'

average_word_length

Average Word Length

Calculate average word length in text.

Functions
average_word_length
average_word_length(text: str) -> float

Calculate the average word length in text.

Parameters:

Name Type Description Default
text str

Input text string

required

Returns:

Type Description
float

Average length of words

Raises:

Type Description
ValueError

If text contains no words

Example

average_word_length("hello world") 5.0

Text Validation

Validate text format and content.

Validation Module

Text validation utilities.

This submodule provides utilities for validating text formats and content types.

Examples

from rite.text.validation import text_is_email, text_is_numeric text_is_email("user@example.com") True text_is_numeric("123") True

Modules

text_is_email

Text Is Email

Validate email address format.

Examples

from rite.text.validation import text_is_email text_is_email("user@example.com") True

Functions
text_is_email
text_is_email(text: str) -> bool

Check if text is valid email format.

Parameters:

Name Type Description Default
text str

String to validate.

required

Returns:

Type Description
bool

True if valid email format, False otherwise.

Examples:

>>> text_is_email("[email protected]")
True
>>> text_is_email("invalid.email")
False
Notes

Basic email validation using regex. Not RFC-compliant, for simple checks only.

text_is_numeric

Text Is Numeric

Check if text is numeric.

Examples

from rite.text.validation import text_is_numeric text_is_numeric("123") True

Functions
text_is_numeric
text_is_numeric(text: str) -> bool

Check if text contains only numeric characters.

Parameters:

Name Type Description Default
text str

String to validate.

required

Returns:

Type Description
bool

True if numeric, False otherwise.

Examples:

>>> text_is_numeric("123")
True
>>> text_is_numeric("12.34")
False
>>> text_is_numeric("abc")
False
Notes

Uses str.isnumeric() method. Returns False for floats with decimals.

text_is_alpha

Text Is Alpha

Check if text is alphabetic.

Examples

from rite.text.validation import text_is_alpha text_is_alpha("Hello") True

Functions
text_is_alpha
text_is_alpha(text: str) -> bool

Check if text contains only alphabetic characters.

Parameters:

Name Type Description Default
text str

String to validate.

required

Returns:

Type Description
bool

True if alphabetic, False otherwise.

Examples:

>>> text_is_alpha("Hello")
True
>>> text_is_alpha("Hello123")
False
Notes

Uses str.isalpha() method.

text_is_alphanumeric

Text Is Alphanumeric

Check if text is alphanumeric.

Examples

from rite.text.validation import text_is_alphanumeric text_is_alphanumeric("Hello123") True

Functions
text_is_alphanumeric
text_is_alphanumeric(text: str) -> bool

Check if text contains only alphanumeric characters.

Parameters:

Name Type Description Default
text str

String to validate.

required

Returns:

Type Description
bool

True if alphanumeric, False otherwise.

Examples:

>>> text_is_alphanumeric("Hello123")
True
>>> text_is_alphanumeric("Hello 123")
False
Notes

Uses str.isalnum() method.

Text Manipulation

Manipulate and transform text.

Manipulation Module

Text manipulation utilities.

This submodule provides utilities for manipulating text including truncation, padding, and wrapping.

Examples

from rite.text.manipulation import text_truncate, text_pad_left text_truncate("Hello World", 8) 'Hello...' text_pad_left("5", 3, "0") '005'

Modules

text_truncate

Text Truncate

Truncate text to maximum length.

Examples

from rite.text.manipulation import text_truncate text_truncate("Hello World", 5) 'Hello...'

Functions
text_truncate
text_truncate(text: str, max_length: int, suffix: str = '...') -> str

Truncate text to maximum length.

Parameters:

Name Type Description Default
text str

Text to truncate.

required
max_length int

Maximum length (including suffix).

required
suffix str

Suffix to add when truncated.

'...'

Returns:

Type Description
str

Truncated text with suffix if needed.

Examples:

>>> text_truncate("Hello World", 5)
'Hello...'
>>> text_truncate("Hi", 10)
'Hi'
Notes

Suffix length is included in max_length.

text_pad_left

Text Pad Left

Pad text on the left.

Examples

from rite.text.manipulation import text_pad_left text_pad_left("5", 3, "0") '005'

Functions
text_pad_left
text_pad_left(text: str, width: int, fill_char: str = ' ') -> str

Pad text on the left to width.

Parameters:

Name Type Description Default
text str

Text to pad.

required
width int

Target width.

required
fill_char str

Character to pad with.

' '

Returns:

Type Description
str

Left-padded text.

Examples:

>>> text_pad_left("5", 3, "0")
'005'
>>> text_pad_left("Hi", 5)
'   Hi'
Notes

Uses str.rjust() method.

text_pad_right

Text Pad Right

Pad text on the right.

Examples

from rite.text.manipulation import text_pad_right text_pad_right("Hi", 5) 'Hi '

Functions
text_pad_right
text_pad_right(text: str, width: int, fill_char: str = ' ') -> str

Pad text on the right to width.

Parameters:

Name Type Description Default
text str

Text to pad.

required
width int

Target width.

required
fill_char str

Character to pad with.

' '

Returns:

Type Description
str

Right-padded text.

Examples:

>>> text_pad_right("Hi", 5)
'Hi   '
>>> text_pad_right("5", 3, "0")
'500'
Notes

Uses str.ljust() method.

text_wrap

Text Wrap

Wrap text to specified width.

Examples

from rite.text.manipulation import text_wrap text_wrap("Hello World", 5) ['Hello', 'World']

Functions
text_wrap
text_wrap(text: str, width: int = 70) -> list[str]

Wrap text to specified width.

Parameters:

Name Type Description Default
text str

Text to wrap.

required
width int

Maximum line width.

70

Returns:

Type Description
list[str]

List of wrapped lines.

Examples:

>>> text_wrap("Hello World", 5)
['Hello', 'World']
>>> text_wrap("A long sentence", 10)
['A long', 'sentence']
Notes

Uses textwrap.wrap() from stdlib.

Search and find patterns in text.

Search Module

Text search utilities.

This submodule provides utilities for searching within text including contains, starts_with, ends_with, find, and count operations.

Examples

from rite.text.search import text_contains, text_find text_contains("Hello World", "World") True text_find("Hello World", "World") 6

Modules

text_contains

Text Contains

Check if text contains a substring.

Examples

from rite.text.search import text_contains text_contains("Hello World", "World") True

Functions
text_contains
text_contains(text: str, substring: str) -> bool

Check if text contains substring.

Parameters:

Name Type Description Default
text str

Text to search in.

required
substring str

Substring to search for.

required

Returns:

Type Description
bool

True if substring found.

Examples:

>>> text_contains("Hello World", "World")
True
>>> text_contains("Hello", "Goodbye")
False
Notes

Case-sensitive search.

text_starts_with

Text Starts With

Check if text starts with prefix.

Examples

from rite.text.search import text_starts_with text_starts_with("Hello World", "Hello") True

Functions
text_starts_with
text_starts_with(text: str, prefix: str) -> bool

Check if text starts with prefix.

Parameters:

Name Type Description Default
text str

Text to check.

required
prefix str

Prefix to search for.

required

Returns:

Type Description
bool

True if text starts with prefix.

Examples:

>>> text_starts_with("Hello World", "Hello")
True
>>> text_starts_with("Hello", "World")
False
Notes

Uses str.startswith() method.

text_ends_with

Text Ends With

Check if text ends with suffix.

Examples

from rite.text.search import text_ends_with text_ends_with("Hello World", "World") True

Functions
text_ends_with
text_ends_with(text: str, suffix: str) -> bool

Check if text ends with suffix.

Parameters:

Name Type Description Default
text str

Text to check.

required
suffix str

Suffix to search for.

required

Returns:

Type Description
bool

True if text ends with suffix.

Examples:

>>> text_ends_with("Hello World", "World")
True
>>> text_ends_with("Hello", "World")
False
Notes

Uses str.endswith() method.

text_find

Text Find

Find substring position in text.

Examples

from rite.text.search import text_find text_find("Hello World", "World") 6

Functions
text_find
text_find(text: str, substring: str) -> int

Find substring position in text.

Parameters:

Name Type Description Default
text str

Text to search in.

required
substring str

Substring to find.

required

Returns:

Type Description
int

Index of substring or -1 if not found.

Examples:

>>> text_find("Hello World", "World")
6
>>> text_find("Hello", "Goodbye")
-1
Notes

Uses str.find() method. Returns -1 if not found.

text_count

Text Count

Count substring occurrences in text.

Examples

from rite.text.search import text_count text_count("Hello Hello World", "Hello") 2

Functions
text_count
text_count(text: str, substring: str) -> int

Count substring occurrences.

Parameters:

Name Type Description Default
text str

Text to search in.

required
substring str

Substring to count.

required

Returns:

Type Description
int

Number of non-overlapping occurrences.

Examples:

>>> text_count("Hello Hello World", "Hello")
2
>>> text_count("aaa", "aa")
1
Notes

Uses str.count() which counts non-overlapping occurrences.

Sanitization

Clean and sanitize text content.

Functions

sanitize

sanitize(text: str, replacement: str = '_') -> str

Sanitize text to create safe ASCII identifiers.


text: The input text to sanitize.
replacement: The character to replace non-alphanumeric characters.

str: The sanitized text with only ASCII alphanumeric characters.

clean

clean(text: str) -> str

Remove extra whitespace from text.


text: The input text to clean.

str: The cleaned text with normalized whitespace.

Morse Code

Encode and decode Morse code.

Modules

morse_encode

Morse Code Encoder

Convert text to Morse code.

Functions
morse_encode
morse_encode(text: str, separator: str = ' ') -> str

Convert text to Morse code.

Parameters:

Name Type Description Default
text str

Text string to encode

required
separator str

Character to separate Morse code symbols

' '

Returns:

Type Description
str

Morse code string

Example

morse_encode("HELLO") '.... . .-.. .-.. ---'

morse_decode

Morse Code Decoder

Convert Morse code to text.

Functions
morse_decode
morse_decode(morse_code: str, separator: str = ' ') -> str

Convert Morse code to text.

Parameters:

Name Type Description Default
morse_code str

Morse code string to decode

required
separator str

Character separating Morse code symbols

' '

Returns:

Type Description
str

Decoded text string

Raises:

Type Description
ValueError

If invalid Morse code sequence encountered

Example

morse_decode(".... . .-.. .-.. ---") 'HELLO'

Random Generation

Generate random strings.

Modules

random_string

Random String Generator

Generate secure random strings.

Functions
random_string
random_string(length: int = 16, charset: str = string.ascii_letters + string.digits) -> str

Generate a secure random string.

Parameters:

Name Type Description Default
length int

Length of the random string

16
charset str

Character set to use for generation

ascii_letters + digits

Returns:

Type Description
str

Secure random string

Example

len(random_string(20)) 20

random_hex

Random Hexadecimal Generator

Generate random hexadecimal strings.

Functions
random_hex
random_hex(length: int = 16, uppercase: bool = False) -> str

Generate a random hexadecimal string.

Parameters:

Name Type Description Default
length int

Length of the random hex string

16
uppercase bool

Use uppercase letters for hex digits

False

Returns:

Type Description
str

Random hexadecimal string

Example

len(random_hex(10)) 10

random_alphanumeric

Random Alphanumeric Generator

Generate random alphanumeric strings.

Functions
random_alphanumeric
random_alphanumeric(length: int = 16, include_lowercase: bool = True, include_uppercase: bool = True) -> str

Generate a random alphanumeric string.

Parameters:

Name Type Description Default
length int

Length of the random string

16
include_lowercase bool

Include lowercase letters

True
include_uppercase bool

Include uppercase letters

True

Returns:

Type Description
str

Random alphanumeric string

Raises:

Type Description
ValueError

If both include_lowercase and include_uppercase are False

Example

len(random_alphanumeric(10)) 10

Examples

Basic Usage

from rite.text import to_snake_case, slugify, text_truncate

# Case conversion
text = "HelloWorld"
snake = to_snake_case(text)  # "hello_world"

# Slug generation
title = "Hello World! This is a test."
slug = slugify(title)  # "hello-world-this-is-a-test"

# Text manipulation
long_text = "This is a very long text that needs truncation"
short = text_truncate(long_text, 20)  # "This is a very l..."

Advanced Examples

from rite.text import (
    text_is_email,
    text_pad_left,
    char_frequency,
    text_contains
)

# Validation
email = "[email protected]"
is_valid = text_is_email(email)  # True

# Padding
number = "42"
padded = text_pad_left(number, 5, "0")  # "00042"

# Analysis
text = "hello world"
freq = char_frequency(text)  # {'h': 1, 'e': 1, 'l': 3, ...}

# Search
haystack = "The quick brown fox"
found = text_contains(haystack, "quick")  # True