Case convert and verify for Python: snake_case, camelCase, kebab-case, etc.
- Verify and convert between most popular cases
- Custom separators:
'my.variable.name'
,'my/variable/name'
- Command line mode:
caseutil
- Pure Python 2.7 to 3.13+
- No dependencies
- 100% test coverage
Case | Example | Functions |
---|---|---|
snake_case | my_variable_name | is_snake , to_snake |
CONST_CASE | MY_VARIABLE_NAME | is_const , to_const |
camelCase | myVariableName | is_camel , to_camel |
PascalCase | MyVariableName | is_pascal , to_pascal |
kebab-case | my-variable-name | is_kebab , to_kebab |
lower space | my variable name | is_lower , to_lower |
UPPER SPACE | MY VARIABLE NAME | is_upper , to_upper |
Title Space | My Variable Name | is_title , to_title |
$ pip install caseutil
>>> from caseutil import *
Verify case format:
>>> is_snake('My variable-name')
False
Convert to case:
>>> to_snake('My variable-name')
'my_variable_name'
Note the support of multiple values in argument or stdin:
$ caseutil -c const "hi there"
HI_THERE
$ echo "hi_there\nsee you" | python -m caseutil -c camel
hiThere
seeYou
Use functions is_case()
and to_case()
to deal with arbitrary case:
>>> is_case('camel', 'myVariableName')
True
>>> to_case(Case.CONST, 'myVariableName')
'MY_VARIABLE_NAME'
All supported cases are gathered in Case
enum:
class Case(StrEnum):
CAMEL = 'camel'
CONST = 'const'
KEBAB = 'kebab'
LOWER = 'lower'
PASCAL = 'pascal'
SNAKE = 'snake'
TITLE = 'title'
UPPER = 'upper'
Word separators are non-word characters including underscore, and places where text case is changed from lower to upper. Digits are not treated as separators. For more details, see this example and unit tests.
>>> words('!some_reallyMESsy text--wit4Digits.3VeryWh3re--')
['some', 'really', 'ME', 'Ssy', 'text', 'wit4', 'Digits', '3Very', 'Wh3re']
For custom separators, use words()
function:
>>> '/'.join(words(to_lower('myVariableName')))
'my/variable/name'
>>> '.'.join(words('myVariableName'))
'my.Variable.Name'
Only ASCII names are supported. Unicode support is planned.
This project requires Homebrew. Other tools like PDM and Tox will be installed automatically.
git clone https://github.com/makukha/caseutil.git
cd caseutil
brew install go-task
task init install
task test
See Contributing guidelines.
- Add more test, explore edge cases
- Add Unicode support (write tests)
- Add more cases