String case converter with 15 functions for transforming strings between different case formats.
npx @tessl/cli install tessl/pypi-stringcase@1.2.00
# StringCase
1
2
A comprehensive Python string case conversion library that transforms strings between different case formats including camelCase, PascalCase, snake_case, CONST_CASE, spinal-case, path/case, sentence case, Title Case, and more. Provides simple function-based API covering all common programming and text formatting needs.
3
4
## Package Information
5
6
- **Package Name**: stringcase
7
- **Language**: Python
8
- **Installation**: `pip install stringcase`
9
10
## Core Imports
11
12
```python
13
import stringcase
14
```
15
16
Function-specific imports:
17
18
```python
19
from stringcase import camelcase, snakecase, pascalcase
20
```
21
22
## Basic Usage
23
24
```python
25
import stringcase
26
27
# Convert between common case formats
28
stringcase.camelcase('foo_bar_baz') # => "fooBarBaz"
29
stringcase.snakecase('fooBarBaz') # => "foo_bar_baz"
30
stringcase.pascalcase('foo_bar_baz') # => "FooBarBaz"
31
stringcase.constcase('foo_bar_baz') # => "FOO_BAR_BAZ"
32
33
# Handle different input formats
34
stringcase.spinalcase('FooBarBaz') # => "foo-bar-baz"
35
stringcase.pathcase('foo-bar-baz') # => "foo/bar/baz"
36
stringcase.titlecase('foo_bar_baz') # => "Foo Bar Baz"
37
38
# Special formatting functions
39
''.join(stringcase.alphanumcase('_Foo., Bar')) # => "FooBar"
40
stringcase.trimcase(' foo bar baz ') # => "foo bar baz"
41
```
42
43
## Capabilities
44
45
### Core Case Conversion
46
47
Standard case conversion functions for common programming and text formatting patterns.
48
49
```python { .api }
50
def camelcase(string):
51
"""
52
Convert string into camel case.
53
54
Args:
55
string: String to convert (any type, converted to string internally)
56
57
Returns:
58
str: Camel case string (e.g., "fooBarBaz")
59
"""
60
61
def pascalcase(string):
62
"""
63
Convert string into pascal case.
64
65
Args:
66
string: String to convert (any type, converted to string internally)
67
68
Returns:
69
str: Pascal case string (e.g., "FooBarBaz")
70
"""
71
72
def snakecase(string):
73
"""
74
Convert string into snake case.
75
Join punctuation with underscore.
76
77
Args:
78
string: String to convert (any type, converted to string internally)
79
80
Returns:
81
str: Snake cased string (e.g., "foo_bar_baz")
82
"""
83
84
def constcase(string):
85
"""
86
Convert string into upper snake case.
87
Join punctuation with underscore and convert letters into uppercase.
88
89
Args:
90
string: String to convert (any type, converted to string internally)
91
92
Returns:
93
str: Const cased string (e.g., "FOO_BAR_BAZ")
94
"""
95
96
def spinalcase(string):
97
"""
98
Convert string into spinal case.
99
Join punctuation with hyphen.
100
101
Args:
102
string: String to convert (any type, converted to string internally)
103
104
Returns:
105
str: Spinal cased string (e.g., "foo-bar-baz")
106
"""
107
```
108
109
### Formatted Case Conversion
110
111
Case conversion functions for specific formatting contexts like paths, sentences, and titles.
112
113
```python { .api }
114
def pathcase(string):
115
"""
116
Convert string into path case.
117
Join punctuation with slash.
118
119
Args:
120
string: String to convert (any type, converted to string internally)
121
122
Returns:
123
str: Path cased string (e.g., "foo/bar/baz")
124
"""
125
126
def dotcase(string):
127
"""
128
Convert string into dot case.
129
Join punctuation with dot.
130
131
Args:
132
string: String to convert (any type, converted to string internally)
133
134
Returns:
135
str: Dot cased string (e.g., "foo.bar.baz")
136
"""
137
138
def backslashcase(string):
139
"""
140
Convert string into backslash case.
141
Join punctuation with backslash.
142
143
Args:
144
string: String to convert (any type, converted to string internally)
145
146
Returns:
147
str: Backslash cased string (e.g., "foo\\bar\\baz")
148
"""
149
150
def sentencecase(string):
151
"""
152
Convert string into sentence case.
153
First letter capped and each punctuation joined with space.
154
155
Args:
156
string: String to convert (any type, converted to string internally)
157
158
Returns:
159
str: Sentence cased string (e.g., "Foo bar baz")
160
"""
161
162
def titlecase(string):
163
"""
164
Convert string into title case.
165
First letter capped while each word is capitalized and joined with space.
166
167
Args:
168
string: String to convert (any type, converted to string internally)
169
170
Returns:
171
str: Title cased string (e.g., "Foo Bar Baz")
172
"""
173
```
174
175
### Basic Case Operations
176
177
Fundamental case operations for uppercase, lowercase, and capitalization.
178
179
```python { .api }
180
def uppercase(string):
181
"""
182
Convert string into upper case.
183
184
Args:
185
string: String to convert (any type, converted to string internally)
186
187
Returns:
188
str: Uppercase string (e.g., "FOOBARBAZ")
189
"""
190
191
def lowercase(string):
192
"""
193
Convert string into lower case.
194
195
Args:
196
string: String to convert (any type, converted to string internally)
197
198
Returns:
199
str: Lowercase string (e.g., "foobarbaz")
200
"""
201
202
def capitalcase(string):
203
"""
204
Convert string into capital case.
205
First letter will be uppercase.
206
207
Args:
208
string: String to convert (any type, converted to string internally)
209
210
Returns:
211
str: Capital case string (e.g., "Foobarbaz")
212
"""
213
```
214
215
### String Processing Utilities
216
217
Special utility functions for string cleaning and filtering.
218
219
```python { .api }
220
def trimcase(string):
221
"""
222
Convert string into trimmed string.
223
224
Args:
225
string: String to convert (any type, converted to string internally)
226
227
Returns:
228
str: Trimmed string with leading/trailing whitespace removed
229
"""
230
231
def alphanumcase(string):
232
"""
233
Cuts all non-alphanumeric symbols.
234
Removes all characters except 0-9, a-z and A-Z.
235
236
Args:
237
string: String to convert (any type, converted to string internally)
238
239
Returns:
240
filter: Filter object containing alphanumeric characters (use ''.join() to get string)
241
"""
242
```
243
244
## Usage Examples
245
246
### Converting Between Common Cases
247
248
```python
249
import stringcase
250
251
# From snake_case to other formats
252
input_str = "hello_world_example"
253
stringcase.camelcase(input_str) # => "helloWorldExample"
254
stringcase.pascalcase(input_str) # => "HelloWorldExample"
255
stringcase.spinalcase(input_str) # => "hello-world-example"
256
stringcase.constcase(input_str) # => "HELLO_WORLD_EXAMPLE"
257
258
# From camelCase to other formats
259
input_str = "helloWorldExample"
260
stringcase.snakecase(input_str) # => "hello_world_example"
261
stringcase.titlecase(input_str) # => "Hello World Example"
262
stringcase.pathcase(input_str) # => "hello/world/example"
263
```
264
265
### Handling Edge Cases
266
267
```python
268
import stringcase
269
270
# Handle None values
271
stringcase.camelcase(None) # => "none"
272
stringcase.snakecase(None) # => "none"
273
274
# Handle empty strings
275
stringcase.camelcase('') # => ""
276
stringcase.pascalcase('') # => ""
277
278
# Handle strings with leading punctuation
279
stringcase.camelcase('_foo_bar') # => "fooBar"
280
stringcase.pascalcase('.foo_bar') # => "FooBar"
281
```
282
283
### Path and File Formatting
284
285
```python
286
import stringcase
287
288
# Convert identifiers to path-like formats
289
component_name = "UserProfileManager"
290
stringcase.pathcase(component_name) # => "user/profile/manager"
291
stringcase.dotcase(component_name) # => "user.profile.manager"
292
stringcase.backslashcase(component_name) # => "user\\profile\\manager"
293
```
294
295
### Text Processing
296
297
```python
298
import stringcase
299
300
# Clean up text input
301
user_input = "_Hello, World! 123"
302
''.join(stringcase.alphanumcase(user_input)) # => "HelloWorld123"
303
stringcase.sentencecase(user_input) # => "Hello world"
304
stringcase.titlecase(user_input) # => " Hello World"
305
306
# Format for display
307
stringcase.trimcase(" spaced text ") # => "spaced text"
308
```