Skip to main content

Case convert and verify for Python: snake_case, camelCase, kebab-case, and more.

Project description

caseutil ⇄ 🐍🐫🍢

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

versions
pypi Tests Coverage PyPI - Downloads
license Documentation Status 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

Simple functions

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

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

Basic usage

>>> from caseutil import *

>>> is_snake('Foo bar-baz')
False

>>> to_snake('Foo bar-baz')
'foo_bar_baz'

Advanced usage

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'

Universal operations

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'

Cases detection

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

Custom separators

Use words() function:

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

>>> words('!some_reallyMESsy text--wit4Digits.3VeryWh3re--')
['some', 'really', 'ME', 'Ssy', 'text', 'wit4', 'Digits', '3Very', 'Wh3re']

Unicode support

Only ASCII names are supported. Unicode support is planned.

Development

This project requires Docker.

$ git clone https://github.com/makukha/caseutil.git
$ cd caseutil
$ task dev

In dev environment:

$ task version -- minor
$ task build
$ task lint
$ task format
$ task test

Alternatives

60+ packages

Contributing

See Contributing guidelines.

Authors

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

caseutil-0.7.1.tar.gz (32.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

caseutil-0.7.1-py2.py3-none-any.whl (7.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file caseutil-0.7.1.tar.gz.

File metadata

  • Download URL: caseutil-0.7.1.tar.gz
  • Upload date:
  • Size: 32.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.11

File hashes

Hashes for caseutil-0.7.1.tar.gz
Algorithm Hash digest
SHA256 2d176849f871cab997aca89b0aea4912326c98063216d6bb867ea6b99ac3ffcf
MD5 0fc9fb48ef0a89c809770c9294fdb531
BLAKE2b-256 801e57611bb2607eb445abb65bd61357be72238c8b5f6c87f89e153b2abdc280

See more details on using hashes here.

File details

Details for the file caseutil-0.7.1-py2.py3-none-any.whl.

File metadata

  • Download URL: caseutil-0.7.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.11

File hashes

Hashes for caseutil-0.7.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c61b0728b2491a0c26c0f05f0fef5355d3f7c2f84ad8a7ad38539ed70c0fa935
MD5 a69819069f0ea6bbf2749d027a1bf29d
BLAKE2b-256 b77086fb8fb246297776e9a0e2e5cc566ad741116fd70389cbfcf6dffd1c7130

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page