Skip to main content

caseutil ⇄ 🐍🐫🍢

Case conversion and verification for Python: snake_case, camelCase, kebab-case, etc.

license pypi python versions tests coverage tested with multipython docs status uses docsub mypy uv Ruff openssf best practices

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

Cases 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

$ pip install caseutil

Use cases

Basic usage

>>> 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:

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:

>>> 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):

>>> 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():

>>> 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.

>>> 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

$ 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

CLI Reference

$ caseutil --help
usage: caseutil [-h] (--version | -c <case> | -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 <case>  convert [text] or stdin to <case>
  -d, --detect          detect cases in [text] or stdin

Alternatives

70+ packages

Contributing

See Contributing guidelines.

Authors

See also

Metadata

Release files for caseutil 0.7.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for caseutil 0.7.2
File Size Uploaded Provenance
caseutil-0.7.2.tar.gz 122.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for caseutil 0.7.2
File Interpreter ABI Platform
caseutil-0.7.2-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 131.4 kB

Release files / caseutil-0.7.2.tar.gz

Download URL caseutil-0.7.2.tar.gz
Size 122.5 kB
Tags Source
SHA-256 checksum
How to use checksums
36e5283590e67e33749d6c1ddb913dcfabb870749215776f7b411f9eb8e361e6
BLAKE2b-256 checksum
How to use checksums
5dde8cdaf896811af1f1d64833e511baa9dec13b4ca24cf4c34f1b45daeee82a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.13

Release files / caseutil-0.7.2-py2.py3-none-any.whl

Download URL caseutil-0.7.2-py2.py3-none-any.whl
Size 8.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
11c06c3379e381d0c3633e910be5463e28fa983c42cd086382da5f73ea587a91
BLAKE2b-256 checksum
How to use checksums
1ca820761d6a13a6a6f290c5ed53d8b633e20167477dff0851844ce00553cfda
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.13

Security for caseutil 0.7.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page