Converts a string from snake case to camel case or camel case to snake case
Actively maintained. Last release 11 days ago. A safe choice.
pip install camel-converterCamel Converter
In JSON keys are frequently in camelCase format, while variable names in Python are typically snake_case. The purpose of this package is to help convert between the two formats.
Usage
-
To convert from camel case to snake case:
from camel_converter import to_snake snake = to_snake("myString")This will convert
myStringintomy_string -
To convert a dictionary's keys from camel case to snake case:
from camel_converter import dict_to_snake snake = dict_to_snake({"myString": "val 1"})This will convert
{"myString": "val 1"}into{"my_string": "val 1"}. Non-string keys will be left unchanged.This is also available as a decorator for functions that return a dictionary.
from camel_converter.decorators import dict_to_snake @dict_to_snake def my_func() -> dict[str, str]: return {"myString": "val 1"} snake = my_func()my_funcwill return{"my_string": "val 1"}. Non-string keys will be left unchanged. -
To convert from snake case to camel case:
from camel_converter import to_camel camel = to_camel("my_string")This will convert
my_stringintomyString -
To convert from a dictionary's keys from snake case to camel case:
from camel_converter import dict_to_camel camel = dict_to_camel({"my_string": "val 1"})This will convert into Non-string keys will be left unchanged.