Skip to main content

Lightweight utilities for converting strings between common cases

Project description

Magic Case

Lightweight utilities for converting strings between common cases, built on a simple BaseCase abstraction.

  • Cases: SnakeCase, CamelCase, PascalCase, KebabCase, UpperCase, SentenceCase, TitleCase
  • Composable: Construct from raw strings or from another case class
  • Zero deps: No runtime dependencies

Installation

Using uv (recommended):

uv add magic-case>=0.2.0

Standard pip:

pip install "magic-case>=0.2.0"

Quick start

from magic_case import SnakeCase, CamelCase, PascalCase, KebabCase, UpperCase, SentenceCase, TitleCase

print(SnakeCase('hello_world').get())     # hello_world
print(CamelCase('helloWorld').get())      # helloWorld
print(PascalCase('HelloWorld').get())     # HelloWorld
print(KebabCase('hello-world').get())     # hello-world
print(UpperCase('hello_world').get())     # HELLO_WORLD
print(SentenceCase('hello world').get())  # Hello world
print(TitleCase('hello world').get())     # Hello World

Convert between cases

Construct from another case to re-render with a different style:

from magic_case import SnakeCase, CamelCase, PascalCase

snake = SnakeCase('hello_world')
print(CamelCase(snake).get())   # helloWorld
print(PascalCase(snake).get())  # HelloWorld

API

  • BaseCase
    • words: List[str] normalized to lowercase
    • get() -> str returns the rendered string (same as str(instance))
    • Subclasses implement:
      • _split_into_words(text: str) -> List[str]
      • __str__(self) -> str
  • Concrete cases
    • SnakeCase, CamelCase, PascalCase, KebabCase, UpperCase, SentenceCase, TitleCase

Requirements

  • Python 3.8+

License

MIT

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

magic_case-0.3.0.tar.gz (47.9 kB view details)

Uploaded Source

Built Distribution

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

magic_case-0.3.0-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file magic_case-0.3.0.tar.gz.

File metadata

  • Download URL: magic_case-0.3.0.tar.gz
  • Upload date:
  • Size: 47.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for magic_case-0.3.0.tar.gz
Algorithm Hash digest
SHA256 223afc35fca9d932fe47e0125a856f265785052fe64c715acc0c216d03966c1d
MD5 8ad9692fce133e0ef770f692f24a4181
BLAKE2b-256 ca156e44a72f9ea131dca5352822468ccc0a173cada76472cc3f0e49943babb7

See more details on using hashes here.

File details

Details for the file magic_case-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: magic_case-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for magic_case-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ee9d0aaf7c8972fdcf69e0394e472d3873ab79b420ebd35266ea424125dd9863
MD5 2deb9b8e26dbd322da9ede4775a1c217
BLAKE2b-256 6411926b6c6ed0ef05273878d2c2fab139eb53ae81a29110621a781cb394c477

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