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.2.0.tar.gz (10.1 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.2.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: magic_case-0.2.0.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.11

File hashes

Hashes for magic_case-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a43081b9ef76fec95646dbfa4417b90e3f1a8410e60c0074eb47de9931e1a160
MD5 20ba46be17e855955b8e12391668e2a4
BLAKE2b-256 a47158bb9b09b12823bbe7dda330f7abc5c3edf63c9a88b9462f888bdb3e0fe7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: magic_case-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.11

File hashes

Hashes for magic_case-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9a5c90b3cd61e4956a5ccebaac8dc22753787532789cfa74885fc33ab0c9d9e5
MD5 e1bd0a88deeb09e075fd03476e3c0122
BLAKE2b-256 f793eb04c58d1a5ac0db31322415f51f8bdd2cb491ceca56404a2c51a00903ee

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