https://github.com/makukha/caseutil
Case convert and verify for Python: snake_case, camelCase, kebab-case, and more.
https://github.com/makukha/caseutil
case case-converter cli python python2 python3 string-case text-case text-case-converter
Last synced: 10 months ago
JSON representation
Case convert and verify for Python: snake_case, camelCase, kebab-case, and more.
- Host: GitHub
- URL: https://github.com/makukha/caseutil
- Owner: makukha
- License: mit
- Created: 2024-07-27T12:50:24.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-13T18:25:30.000Z (12 months ago)
- Last Synced: 2025-03-23T18:38:49.453Z (11 months ago)
- Topics: case, case-converter, cli, python, python2, python3, string-case, text-case, text-case-converter
- Language: Python
- Homepage: http://caseutil.readthedocs.io
- Size: 157 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
- Support: .github/SUPPORT.md
Awesome Lists containing this project
README
# caseutil ⇄ 🐍🐫🍢
> Case conversion and verification for Python: snake_case, camelCase, kebab-case, etc.
[](https://github.com/makukha/caseutil/blob/main/LICENSE)
[](https://pypi.python.org/pypi/caseutil)
[](https://pypi.org/project/caseutil)
[](https://github.com/makukha/caseutil)
[](https://github.com/makukha/caseutil)
[](https://github.com/makukha/multipython)
[](https://caseutil.readthedocs.io/en/latest/?badge=latest)
[](https://github.com/makukha/docsub)
[](http://mypy.readthedocs.io)
[](https://github.com/astral-sh/ruff)
[](https://github.com/astral-sh/ruff)
[](https://www.bestpractices.dev/projects/9342)
# Features
* 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
## Supported cases
### [Classification](https://caseutil.readthedocs.io/en/latest/classification/)


| 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` |
# Installation
```shell
$ pip install caseutil
```
## Use cases
* [Basic usage](#basic-usage)
* [Cases enum](#cases-enum)
* [Arbitrary cases](#arbitrary-cases)
* [Detect cases](#detect-cases)
* [Custom separators](#custom-separators)
* [Tokenization](#tokenization)
* [Unicode support *(not implemented)*](#unicode-support-not-implemented)
### Basic usage
```pycon
>>> from caseutil import is_snake, to_snake
>>> is_snake('Foo bar-baz')
False
>>> to_snake('Foo bar-baz')
'foo_bar_baz'
```
### Cases enum
All supported cases are gathered in `Case` enum:
```python
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'
```
### Arbitrary cases
Use functions `is_case()` and `to_case()` to deal with arbitrary supported case:
```pycon
>>> from caseutil import Case, is_case, to_case
>>> is_case(Case.CAMEL, 'myVarName')
True
>>> to_case(Case.CONST, 'myVarName')
'MY_VAR_NAME'
```
### Detect cases
Use function `get_cases()` to determine case (or cases, if
[ambiguous](https://caseutil.readthedocs.io/en/latest/classification/#ambiguity)):
```pycon
>>> from caseutil import get_cases
>>> get_cases('fooBar')
('camel',)
>>> get_cases('My var-name') # mixed case
()
>>> get_cases('Title') # matches multiple cases
('ada', 'pascal', 'sentence', 'title', 'train')
```
### Custom separators
Use function `words()`:
```pycon
>>> from caseutil import words, to_lower
>>> '/'.join(words(to_lower('myVarName')))
'my/var/name'
>>> '.'.join(words('myVarName'))
'my.Var.Name'
```
### Tokenization
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](https://caseutil.readthedocs.io/en/latest/tokenize).
```pycon
>>> from caseutil import words
>>> words('!some_reallyMESsy text--wit4Digits.3VeryWh3re--')
['some', 'really', 'ME', 'Ssy', 'text', 'wit4', 'Digits', '3Very', 'Wh3re']
```
### Unicode support *(not implemented)*
Only ASCII names are supported. Unicode support is planned.
## Command line
```shell
$ caseutil -c const "hi there"
HI_THERE
```
Invoke as Python module:
```shell
$ python -m caseutil -c const "hi there"
HI_THERE
```
When reading from stdin, each line is processed separately:
```shell
$ echo "hi_there\nsee you" | python -m caseutil -c camel
hiThere
seeYou
```
### CLI Reference
```text
$ caseutil --help
usage: caseutil [-h] (--version | -c | -d) [text]
Convert, detect, or match text case.
When stdin is used as input, each line is tokenized and processed separately.
cases:
ada,camel,cobol,const,kebab,lower,pascal,sentence,snake,title,train,upper
positional arguments:
text text to be converted; if missing, stdin is used
options:
-h, --help show this help message and exit
--version show program's version number and exit
-c, --convert convert [text] or stdin to
-d, --detect detect cases in [text] or stdin
```
# Alternatives
[70+ packages](https://caseutil.readthedocs.io/en/latest/alternatives/)
# Contributing
See [Contributing](.github/CONTRIBUTING.md) guidelines.
# Authors
* [Michael Makukha](https://github.com/makukha)
## See also
* [Project changelog](https://github.com/makukha/caseutil/tree/main/CHANGELOG.md)