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
BaseCasewords: List[str]normalized to lowercaseget() -> strreturns the rendered string (same asstr(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)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a43081b9ef76fec95646dbfa4417b90e3f1a8410e60c0074eb47de9931e1a160
|
|
| MD5 |
20ba46be17e855955b8e12391668e2a4
|
|
| BLAKE2b-256 |
a47158bb9b09b12823bbe7dda330f7abc5c3edf63c9a88b9462f888bdb3e0fe7
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a5c90b3cd61e4956a5ccebaac8dc22753787532789cfa74885fc33ab0c9d9e5
|
|
| MD5 |
e1bd0a88deeb09e075fd03476e3c0122
|
|
| BLAKE2b-256 |
f793eb04c58d1a5ac0db31322415f51f8bdd2cb491ceca56404a2c51a00903ee
|