Skip to main content

Utilities for string case conversion.

Project description

Casefy

Active Issues

Introduction

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


Installation

The latest release can be installed using pip:

pip install -U casefy

Casefy is also available as an Arch Linux AUR package.


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

Contribute

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


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.


Related projects

  • case-conversion offers a very similar functionality as this project. I probably wouldn't have written this package if I had known of it before. However, the code of Casefy is more lightweight and just enough for most cases. If you need more functionality, e.g., detecting the case of a string, go with case-conversion.

  • Inflection presents some overlap with this project as well, allowing the transformation of strings from CamelCase to underscored_string, but also singularizing and pluralizing English words.


License

Casefy is distributed under the 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

casefy-1.1.0.tar.gz (123.9 kB view details)

Uploaded Source

Built Distribution

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

casefy-1.1.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file casefy-1.1.0.tar.gz.

File metadata

  • Download URL: casefy-1.1.0.tar.gz
  • Upload date:
  • Size: 123.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for casefy-1.1.0.tar.gz
Algorithm Hash digest
SHA256 849d6e0f80506fac70ab8e18999a4ca1eb7d8f70941682383d64aa22a7497f8f
MD5 5dd8a4a4d11b638d85f427d9eedf75eb
BLAKE2b-256 48249c732e8e3585a1dc621c9c1349e55e87070c95d3c2d57bd8c5083ec8d731

See more details on using hashes here.

File details

Details for the file casefy-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: casefy-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for casefy-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a3dfcb14d85902d90702db1e9835760237f6a73ec0ae3b7e991ad767513a3cbc
MD5 47f3ea36dbb1e3fa560a38ac84a8f713
BLAKE2b-256 f16a1766f8c163951a3c9aeb30a4e6f5de9b2eed8389e3906c4cf30fcb475be6

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