Home

Awesome

<p align="center"><img width="400" src="https://github.com/dmlls/python-casefy/blob/main/docs/source/_static/images/cover.png" alt="Casefy"/></p> <p align="center" display="inline-block"> <a href="https://docs.jizt.it"> <a href="https://pypi.org/project/casefy/"> <img src="https://img.shields.io/pypi/v/casefy"/> </a> <a href="https://deepsource.io/gh/dmlls/python-casefy/?ref=repository-badge}" target="_blank"> <img alt="Active Issues" title="DeepSource" src="https://deepsource.io/gh/dmlls/python-casefy.svg/?label=active+issues&token=dbO3UyrUPWvJp6K_PVZpTcnU"/> </a> </a> </p>

Introduction

Casefy (/keɪsfaɪ/) is a lightweight Python package to convert the casing of strings. It has no third-party dependencies and supports Unicode.

<br>

Installation

The latest release can be installed using pip:

pip install -U casefy

Casefy is also available as an Arch Linux AUR package.

<br>

Examples

Note: for more details, you can check the API Reference.

import casefy

# Alphanum3ric case (removes non-alphanumeric chars)
string = casefy.alphanumcase("foo - 123 ; bar!")
print(string)  # foo123bar

# camelCase
string = casefy.camelcase("foo_bar")
print(string)  # fooBar

string = casefy.camelcase("FooBar")
print(string)  # fooBar

string = casefy.camelcase("FOO BAR")
print(string)  # fooBar

# Capital Case
string = casefy.capitalcase("fooBar")
print(string)  # FooBar

# CONST_CASE
string = casefy.constcase("fooBar")
print(string)  # FOO_BAR

# kebab-case
string = casefy.kebabcase("fooBar")
print(string)  # foo-bar

# lowercase
string = casefy.lowercase("fooBar")
print(string)  # foobar

# PascalCase
string = casefy.pascalcase("foo_bar")
print(string)  # FooBar

string = casefy.pascalcase("fooBar")
print(string)  # FooBar

# Sentence case
string = casefy.sentencecase("fooBar")
print(string)  # Foo bar

# Separator case
string = casefy.separatorcase("fooBar", separator="/")
print(string)  # foo/bar

string = casefy.separatorcase("fooBARbaz", separator="%", keep_together=["bar"])
print(string)  # foo%bar%baz

# snake_case
string = casefy.snakecase("fooBar")
print(string)  # foo_bar

string = casefy.snakecase("fooBARbaz", keep_together=["bar"])
print(string)  # foo_bar_baz

string = casefy.snakecase("FOO BAR")
print(string)  # foo_bar

# Title Case
string = casefy.titlecase("fooBarBaz")
print(string)  # Foo Bar Baz

# UPPERCASE
string = casefy.uppercase("fooBar")
print(string)  # FOOBAR

# UPPER-KEBAB-CASE
string = casefy.upperkebabcase("fooBar")
print(string)  # FOO-BAR
<br>

Contribute

If you find a bug, please open an issue. Pull Requests are also welcome!

<br>

Acknowledgements

This project started when I saw that the package python-stringcase was flagged-out-of-date in the Arch AUR Repository. The project stringcase seems not to be actively maintained anymore, so I decided to address its issues and pull requests and solve them in this new package. I kept the API as similar as possible, in order to facilitate any possible migration. I thank Taka Okunishi (author of stringcase) and its contributors for their work.

<br>

Related projects

<br>

License

Casefy is distributed under the MIT license.