String Case Converter
Stringcase is a lightweight Python library providing functions to convert strings between various common casing conventions, such as camelCase, snake_case, PascalCase, kebab-case, and more. It is a stable, single-purpose utility with no external dependencies, currently at version 1.2.0, and typically sees infrequent updates unless new casing styles or critical bug fixes are required.
Warnings
- gotcha The `uppercamelcase` function is an explicit alias for `pascalcase`. If you expect a distinction between the two, be aware that they perform the same conversion.
- gotcha All `stringcase` functions expect a string as input. Providing non-string types (e.g., `None`, integers, lists) will typically result in a `TypeError` or `AttributeError`.
- gotcha The library primarily focuses on common English-based casing conventions and may not handle complex Unicode characters or non-Latin scripts as expected for all casing transformations. Test thoroughly with internationalized strings.
Install
-
pip install stringcase
Imports
- camelcase
from stringcase import camelcase
- snakecase
from stringcase import snakecase
- stringcase
import stringcase
Quickstart
import stringcase
# Convert to camelCase
camel = stringcase.camelcase('hello_world')
print(f"camelcase: {camel}") # Expected: helloWorld
# Convert to snake_case
snake = stringcase.snakecase('HelloWorld')
print(f"snakecase: {snake}") # Expected: hello_world
# Convert to kebab-case
kebab = stringcase.kebabcase('helloWorld')
print(f"kebabcase: {kebab}") # Expected: hello-world
# Convert to PascalCase
pascal = stringcase.pascalcase('hello-world')
print(f"pascalcase: {pascal}") # Expected: HelloWorld