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
- Validation: Backed by Pydantic (v1) for normalization
Installation
Using uv (recommended):
uv add magic-case
Standard pip:
pip install magic-case
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+
pydantic>=1.10,<2(managed via pyproject)
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.1.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.1.0.tar.gz.
File metadata
- Download URL: magic_case-0.1.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 |
3118ba30f1e04492c5b1c913d749b15f27f6697207876875754ea8968c4a770f
|
|
| MD5 |
7f729a014595330454c1b6c924cece9a
|
|
| BLAKE2b-256 |
418b9a7ec562ace2d56237abbc27e63c35459a0fa7759536d0a3d063457df2af
|
File details
Details for the file magic_case-0.1.0-py3-none-any.whl.
File metadata
- Download URL: magic_case-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
068ab822729c06f55490d18fc518311aa06b0a0e62afb871c5c66d4f8113e6f3
|
|
| MD5 |
b7373de5ea4e887a89d90d01df5bf040
|
|
| BLAKE2b-256 |
7b58b830dd096a2a2d9049dabd8a0e87b6369ef7cc121bbd0faf1638826c0c88
|