DEV Community

Raees Yousaf
Raees Yousaf

Posted on

Python Tricks: Convert Strings to CamelCase, PascalCase, Kebab-Case, Snake_Case in One Line

Have you ever wasted time writing boilerplate code just to convert strings between cases — camelCase, snake_case, PascalCase, or kebab-case?
If yes, then here’s some good news: PyStringToolkit makes all these conversions possible in just one line.

PyStringToolkit is a lightweight and intuitive Python library offering a rich set of utilities for string manipulation and transformation. Whether you’re building web applications, preprocessing text for machine learning, or just want cleaner and more readable code this toolkit simplifies the process with clean and reusable functions.”

Let’s just see how it works:

Installation and Usage:
pip install pystringtoolkit

from pystringtoolkit import to_snake_case, to_camel_case, to_pascal_case, 
to_kebab_case, to_upper_case, to_lower_case, to_title_case, 
to_alternating_case,invert_cases

print(to_snake_case("Hello World!"))  # hello_world
print(to_camel_case("hello world"))  # helloWorld
print(to_pascal_case("hello world"))  # HelloWorld
print(to_kebab_case("Hello World"))  # hello-world
print(to_upper_case("hello"))  # HELLO
print(to_lower_case("Hello"))  # hello
print(to_title_case("hello world"))  # Hello World
print(to_alternating_case("yEsssssss"))   #YeSsSsSsS
print(invert_cases("Hello")) #hELLO
Enter fullscreen mode Exit fullscreen mode

For getting latest versions and other information:
https://pypi.org/project/pystringtoolkit/

For the full documentaion please visit:
https://pystringtoolkit-documentation.readthedocs.io/en/main/getting-started/

If you want to know about source code and make your contribution in this open-source, here’s github link: https://github.com/RaeesFatima/pystringtoolkit

Top comments (0)