FunStrings is a comprehensive Python package that provides a wide range of functions for string manipulation, analysis, and transformation. It's designed to make working with strings easier and more efficient for developers, students, and educators.
- Features
- Installation
- Quick Start
- Documentation
- For Students and Educators
- Contributing
- License
- Connect
FunStrings includes 44 utility functions organized into eight categories:
- Reverse String: Return the reversed string
- Count Vowels: Count the number of vowels in the string
- Count Consonants: Count the number of consonants
- Check Palindrome: Determine whether the string is a palindrome
- To Upper/Lower: Convert the string to uppercase or lowercase
- Word Count: Count the words in the string
- Sort Characters: Return the string with its characters sorted
- Remove Whitespace: Remove all whitespace from the string
- Word Frequencies: Return frequency count of each word
- Longest Word: Find the longest word in the text
- Shortest Word: Find the shortest word in the text
- Average Word Length: Calculate average word length
- Is Pangram: Check if text contains all alphabet letters
- Snake to Camel: Convert snake_case to camelCase
- Camel to Snake: Convert camelCase to snake_case
- Rotate String: Rotate string by n positions
- Shuffle String: Randomly shuffle characters
- Reverse Words: Reverse order of words but not letters
- Extract Numbers: Extract all numbers from text
- Extract Emails: Extract email addresses from text
- Extract URLs: Extract URLs from text
- Mask Sensitive: Mask all but last n chars with '*'
- Find Repeated Words: Find all repeated words in text
- Remove HTML Tags: Strip all HTML tags from text
- Remove Emojis: Remove emojis from text
- Remove Special Characters: Keep only letters and numbers
- Expand Contractions: Convert "don't" → "do not"
- Correct Whitespace: Remove weird spaces, tabs, newlines
- Unique Words: Return list of unique words
- Most Common Word: Return most frequent word
- Sentence Count: Number of sentences in text
- Average Sentence Length: Average words per sentence
- Character Ratio: Uppercase/lowercase/number ratio
- Generate N-grams: Generate list of n-grams
- Strip Accents: Remove accents (café → cafe)
- Lemmatize Text: Reduce words to base form
- Is ASCII: Check if text only contains ASCII
- Is Valid Email: Validate if a string is a proper email
- Is Valid URL: Validate if a string is a proper URL
- Is Valid IP: Check if string is a valid IP address
- Is Valid Date: Check if a string matches a date format
- Contains Special Characters: Check if special symbols are present
You can install FunStrings directly from PyPI:
pip install funstrings
Or install from source:
pip install git+https://github.com/nilkanth02/funstrings.git
import funstrings
# Basic operations
text = "Hello, World!"
print(funstrings.reverse_string(text)) # !dlroW ,olleH
print(funstrings.count_vowels(text)) # 3
# Text analysis
sentence = "The quick brown fox jumps over the lazy dog"
print(funstrings.is_pangram(sentence)) # True
print(funstrings.longest_word(sentence)) # quick
# Transformations
snake = "hello_world_example"
print(funstrings.snake_to_camel(snake)) # helloWorldExample
# Pattern-based
text_with_emails = "Contact us at [email protected] or [email protected]"
print(funstrings.extract_emails(text_with_emails)) # ['[email protected]', '[email protected]']
# Data cleaning
html_text = "<p>Hello <b>World</b></p>"
print(funstrings.remove_html_tags(html_text)) # Hello World
print(funstrings.expand_contractions("I don't know")) # I do not know
# Text analysis helpers
print(funstrings.sentence_count("Hello! How are you? I'm fine.")) # 3
print(funstrings.most_common_word("hello world hello python")) # hello
# ML/NLP preprocessing
print(funstrings.generate_ngrams("hello", 2)) # ['he', 'el', 'll', 'lo']
print(funstrings.strip_accents("café")) # cafe
# Validation
print(funstrings.is_valid_email("[email protected]")) # True
print(funstrings.is_valid_url("https://example.com")) # True
For detailed documentation and examples, visit the GitHub repository.
FunStrings is designed to be educational and beginner-friendly. It includes:
- Detailed docstrings with examples
- Comprehensive tutorials in the
tutorials/
directory - Example scripts in the
examples/
directory - Type hints for better IDE integration
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch:
git checkout -b feature-name
- Commit your changes:
git commit -m 'Add some feature'
- Push to the branch:
git push origin feature-name
- Submit a pull request
Please make sure to update tests as appropriate.
This project is licensed under the MIT License - see the LICENSE file for details.
- GitHub: nilkanth02
- LinkedIn: Nilkanth Ahire