Case conversion and verification for Python: snake_case, camelCase, kebab-case, etc.
- Verify and convert between most popular cases
- Custom separators:
'foo.bar.baz'
,'foo/bar/baz'
- Case detection
- Command line utility
caseutil
- Pure Python 2.7 to 3.14+
- No dependencies
- 100% test coverage
Case | Verify | Convert |
---|---|---|
snake_case | is_snake |
to_snake |
Ada_Case | is_ada |
to_ada |
CONST_CASE | is_const |
to_const |
camelCase | is_camel |
to_camel |
PascalCase | is_pascal |
to_pascal |
kebab-case | is_kebab |
to_kebab |
Train-Case | is_train |
to_train |
COBOL-CASE | is_cobol |
to_cobol |
lower case | is_lower |
to_lower |
UPPER CASE | is_upper |
to_upper |
Title Case | is_title |
to_title |
Sentence case | is_sentence |
to_sentence |
For more details about cases and their relations, see Cases classification.
$ pip install caseutil
$ caseutil -c const "hi there"
HI_THERE
Invoke as Python module:
$ python -m caseutil -c const "hi there"
HI_THERE
When reading from stdin, each line is processed separately:
$ echo "hi_there\nsee you" | python -m caseutil -c camel
hiThere
seeYou
>>> from caseutil import *
>>> is_snake('Foo bar-baz')
False
>>> to_snake('Foo bar-baz')
'foo_bar_baz'
All supported cases are gathered in Case
enum:
class Case(StrEnum):
ADA = 'ada'
CAMEL = 'camel'
COBOL = 'cobol'
CONST = 'const'
KEBAB = 'kebab'
LOWER = 'lower'
PASCAL = 'pascal'
SENTENCE = 'sentence'
SNAKE = 'snake'
TITLE = 'title'
TRAIN = 'train'
UPPER = 'upper'
Use functions is_case()
and to_case()
to deal with any supported case:
>>> is_case(Case.CAMEL, 'myVarName')
True
>>> to_case(Case.CONST, 'myVarName')
'MY_VAR_NAME'
Use get_cases()
function to determine case (or cases, if ambiguous):
>>> get_cases('fooBar')
('camel',)
>>> get_cases('My var-name') # mixed case
()
>>> get_cases('Title')
('ada', 'pascal', 'sentence', 'title', 'train')
Use words()
function:
>>> '/'.join(words(to_lower('myVarName')))
'my/var/name'
>>> '.'.join(words('myVarName'))
'my.Var.Name'
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 Tokenization rules.
>>> words('!some_reallyMESsy text--wit4Digits.3VeryWh3re--')
['some', 'really', 'ME', 'Ssy', 'text', 'wit4', 'Digits', '3Very', 'Wh3re']
Only ASCII names are supported. Unicode support is planned.
This project requires Docker.
git clone https://github.com/makukha/caseutil.git
cd caseutil
task dev
root@caseutil:/project# task lint
root@caseutil:/project# task format
root@caseutil:/project# task test
See Contributing guidelines.