Case Converter
A robust Python package (v1.2.0) for transforming string cases such as "Hello, world!" into "helloWorld" (camelCase). It offers various conversion types including camelCase, snake_case, kebab-case, macro_case, pascalCase, cobol-case, flatcase, and titlecase. The library is actively maintained with regular updates, and designed to be lightweight with no external dependencies.
Warnings
- gotcha By default, punctuation is stripped during string conversion. If you need to retain punctuation, you must explicitly pass `strip_punctuation=False` to the conversion function.
- gotcha The library uses a default set of delimiters (' ', '-', '_') to identify word boundaries. If your input string uses other characters as delimiters that you want to be treated as such, you need to specify them using the `delims` argument.
Install
-
pip install case-converter
Imports
- camelcase
from caseconverter import camelcase
- snakecase
from caseconverter import snakecase
- * (all converters)
import caseconverter as cc # or from caseconverter import *
Quickstart
import caseconverter as cc
text = "Hello, beautiful World!"
# Convert to camelCase
camel_text = cc.camelcase(text)
print(f"Original: '{text}' -> CamelCase: '{camel_text}'")
# Convert to snake_case
snake_text = cc.snakecase(text)
print(f"Original: '{text}' -> SnakeCase: '{snake_text}'")
# Convert to MACRO_CASE and keep punctuation
macro_text_with_punc = cc.macrocase("Hello, world! How are you?", strip_punctuation=False)
print(f"Original: 'Hello, world! How are you?' -> MacroCase (with punc): '{macro_text_with_punc}'")
# Convert to kebab-case using custom delimiters
kebab_custom_delims = cc.kebabcase("first_part-second part", delims=['_', ' '])
print(f"Original: 'first_part-second part' -> KebabCase (custom delims): '{kebab_custom_delims}'")