Skip to main content

Case Conversion

This is a port of the Sublime Text 3 plugin CaseConversion, by Davis Clark, to a regular python package. I couldn't find any other python packages on PyPI at the time (Feb 2016) that could seamlessly convert from any case to any other case without having to specify from what type of case I was converting. This plugin worked really well, so I separated the (non-sublime) python parts of the plugin into this useful python package. I also added Unicode support via python's unicodedata and extended the interface some.

Features

  • Auto-detection of case (no need to specify explicitly which case you are converting from!)
  • Acronym detection (no funky splitting on every capital letter of an all caps acronym like HTTPError!)
  • Unicode supported (non-ASCII characters are first class citizens!)
  • Dependency free!
  • Supports Python 3.10+
  • Every case conversion from/to you ever gonna need:
    • camel -> "camelCase"
    • pascal / mixed -> "PascalCase" / "MixedCase"
    • snake -> "snake_case"
    • snake / kebab / spinal / slug -> "dash-case" / "kebab-case" / "spinal-case" / "slug-case"
    • const / screaming_snake -> "CONST_CASE" / "SCREAMING_SNAKE_CASE"
    • dot -> "dot.case"
    • separate_words -> "separate words"
    • slash -> "slash/case"
    • backslash -> "backslash\case"
    • ada -> "Ada_Case"
    • http_header -> "Http-Header-Case"

Usage

Converter Class

Basic

>>> from case_conversion import Converter
>>> converter = Converter()
>>> converter.camel("FOO_BAR_STRING")
'fooBarString'

Initialize text when needing to convert the same text to multiple different cases.

>>> from case_conversion import Converter
>>> converter = Converter(text="FOO_BAR_STRING")
>>> converter.camel()
'fooBarString'
>>> converter.pascal()
'FooBarString'

Initialize custom acronyms

>>> from case_conversion import Converter
>>> converter = Converter(acronyms=["BAR"])
>>> converter.camel("FOO_BAR_STRING")
'fooBARString'

Convenience Functions

For backwards compatibility and convenience, all converters are available as top level functions. They are all shorthand for:

Converter(text, acronyms).converter_function()

>>> import case_conversion
>>> case_conversion.dash("FOO_BAR_STRING")
'foo-bar-string'

Simple acronym detection comes included, by treating strings of capital letters as a single word instead of several single letter words.

Custom acronyms can be supplied when needing to separate them from each other.

>>> import case_conversion
>>> case_conversion.snake("fooBADHTTPError")
'foo_badhttp_error'  # we wanted BAD and HTTP to be separate!
>>> case_conversion.snake("fooBarHTTPError", acronyms=['BAD', 'HTTP'])
'foo_bad_http_error'  # custom acronyms achieved!

Unicode is fully supported - even for acronyms.

>>> import case_conversion
>>> case_conversion.const(u"fóó-bar-string")
FÓÓ_BAR_STRING
>>> case_conversion.snake("fooBarHÓÓPError", acronyms=['HÓÓP'])
'foo_bar_hóóp_error'

Install

pip install case-conversion

Contribute

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

This package is being developed with uv (-> docs).

CI will run tests and lint checks. Locally you can run them with:

# runs tests with coverage
make test
# Runs linter (using ruff)
make lint
# Auto-fix linter errors (using ruff --fix)
make format
# run type check (using ty)
make tc

Credits

Credit goes to Davis Clark's as the author of the original plugin and its contributors (Scott Bessler, Curtis Gibby, Matt Morrison). Thanks for their awesome work on making such a robust and awesome case converter.

Further thanks and credit to @olsonpm for making this package dependency-free and encouraging package maintenance and best practices.

License

Using MIT license with Davis Clark's Copyright

Metadata

Release files for case-conversion 3.0.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 case-conversion 3.0.2
File Size Uploaded
case_conversion-3.0.2.tar.gz 33.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for case-conversion 3.0.2
File Interpreter ABI Platform
case_conversion-3.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 45.6 kB

Release files / case_conversion-3.0.2.tar.gz

Download URL case_conversion-3.0.2.tar.gz
Size 33.4 kB
Tags Source
SHA-256 checksum
How to use checksums
2e5098c5e20d67282a5999531e7797c412daafcf646169e42066e30cba37a097
BLAKE2b-256 checksum
How to use checksums
4792fea5d4f8f859d9fa7700644da7ad0da3e3e1daadab9230960b59240f853a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Release files / case_conversion-3.0.2-py3-none-any.whl

Download URL case_conversion-3.0.2-py3-none-any.whl
Size 12.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eb8e2834da59656966479cc03df144d00ed437161acb8046c564edb91dffeb3f
BLAKE2b-256 checksum
How to use checksums
60b896fb174191e970c26df7b23a2efb710e1c9cd7a575bf4b9e057594e28540
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Release history Release notifications | RSS feed

This release

3.0.2 This release

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.1.0

1 release file

2.0.1

1 release file

2.0.0

1 release file

1.1.0

1 release file

1.0.1

1 release file

1.0.0

1 release file

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