or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/pypi-stringcase

String case converter with 15 functions for transforming strings between different case formats.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/stringcase@1.2.x

To install, run

npx @tessl/cli install tessl/pypi-stringcase@1.2.0

index.mddocs/

StringCase

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.

Package Information

  • Package Name: stringcase
  • Language: Python
  • Installation: pip install stringcase

Core Imports

import stringcase

Function-specific imports:

from stringcase import camelcase, snakecase, pascalcase

Basic Usage

import stringcase

# Convert between common case formats
stringcase.camelcase('foo_bar_baz')     # => "fooBarBaz"
stringcase.snakecase('fooBarBaz')       # => "foo_bar_baz"
stringcase.pascalcase('foo_bar_baz')    # => "FooBarBaz"
stringcase.constcase('foo_bar_baz')     # => "FOO_BAR_BAZ"

# Handle different input formats
stringcase.spinalcase('FooBarBaz')      # => "foo-bar-baz"
stringcase.pathcase('foo-bar-baz')      # => "foo/bar/baz"
stringcase.titlecase('foo_bar_baz')     # => "Foo Bar Baz"

# Special formatting functions
''.join(stringcase.alphanumcase('_Foo., Bar'))   # => "FooBar"
stringcase.trimcase(' foo bar baz ')    # => "foo bar baz"

Capabilities

Core Case Conversion

Standard case conversion functions for common programming and text formatting patterns.

def camelcase(string):
    """
    Convert string into camel case.
    
    Args:
        string: String to convert (any type, converted to string internally)
        
    Returns:
        str: Camel case string (e.g., "fooBarBaz")
    """

def pascalcase(string):
    """
    Convert string into pascal case.
    
    Args:
        string: String to convert (any type, converted to string internally)
        
    Returns:
        str: Pascal case string (e.g., "FooBarBaz")
    """

def snakecase(string):
    """
    Convert string into snake case.
    Join punctuation with underscore.
    
    Args:
        string: String to convert (any type, converted to string internally)
        
    Returns:
        str: Snake cased string (e.g., "foo_bar_baz")
    """

def constcase(string):
    """
    Convert string into upper snake case.
    Join punctuation with underscore and convert letters into uppercase.
    
    Args:
        string: String to convert (any type, converted to string internally)
        
    Returns:
        str: Const cased string (e.g., "FOO_BAR_BAZ")
    """

def spinalcase(string):
    """
    Convert string into spinal case.
    Join punctuation with hyphen.
    
    Args:
        string: String to convert (any type, converted to string internally)
        
    Returns:
        str: Spinal cased string (e.g., "foo-bar-baz")
    """

Formatted Case Conversion

Case conversion functions for specific formatting contexts like paths, sentences, and titles.

def pathcase(string):
    """
    Convert string into path case.
    Join punctuation with slash.
    
    Args:
        string: String to convert (any type, converted to string internally)
        
    Returns:
        str: Path cased string (e.g., "foo/bar/baz")
    """

def dotcase(string):
    """
    Convert string into dot case.
    Join punctuation with dot.
    
    Args:
        string: String to convert (any type, converted to string internally)
        
    Returns:
        str: Dot cased string (e.g., "foo.bar.baz")
    """

def backslashcase(string):
    """
    Convert string into backslash case.
    Join punctuation with backslash.
    
    Args:
        string: String to convert (any type, converted to string internally)
        
    Returns:
        str: Backslash cased string (e.g., "foo\\bar\\baz")
    """

def sentencecase(string):
    """
    Convert string into sentence case.
    First letter capped and each punctuation joined with space.
    
    Args:
        string: String to convert (any type, converted to string internally)
        
    Returns:
        str: Sentence cased string (e.g., "Foo bar baz")
    """

def titlecase(string):
    """
    Convert string into title case.
    First letter capped while each word is capitalized and joined with space.
    
    Args:
        string: String to convert (any type, converted to string internally)
        
    Returns:
        str: Title cased string (e.g., "Foo Bar Baz")
    """

Basic Case Operations

Fundamental case operations for uppercase, lowercase, and capitalization.

def uppercase(string):
    """
    Convert string into upper case.
    
    Args:
        string: String to convert (any type, converted to string internally)
        
    Returns:
        str: Uppercase string (e.g., "FOOBARBAZ")
    """

def lowercase(string):
    """
    Convert string into lower case.
    
    Args:
        string: String to convert (any type, converted to string internally)
        
    Returns:
        str: Lowercase string (e.g., "foobarbaz")
    """

def capitalcase(string):
    """
    Convert string into capital case.
    First letter will be uppercase.
    
    Args:
        string: String to convert (any type, converted to string internally)
        
    Returns:
        str: Capital case string (e.g., "Foobarbaz")
    """

String Processing Utilities

Special utility functions for string cleaning and filtering.

def trimcase(string):
    """
    Convert string into trimmed string.
    
    Args:
        string: String to convert (any type, converted to string internally)
        
    Returns:
        str: Trimmed string with leading/trailing whitespace removed
    """

def alphanumcase(string):
    """
    Cuts all non-alphanumeric symbols.
    Removes all characters except 0-9, a-z and A-Z.
    
    Args:
        string: String to convert (any type, converted to string internally)
        
    Returns:
        filter: Filter object containing alphanumeric characters (use ''.join() to get string)
    """

Usage Examples

Converting Between Common Cases

import stringcase

# From snake_case to other formats
input_str = "hello_world_example"
stringcase.camelcase(input_str)    # => "helloWorldExample"
stringcase.pascalcase(input_str)   # => "HelloWorldExample"
stringcase.spinalcase(input_str)   # => "hello-world-example"
stringcase.constcase(input_str)    # => "HELLO_WORLD_EXAMPLE"

# From camelCase to other formats
input_str = "helloWorldExample"
stringcase.snakecase(input_str)    # => "hello_world_example"
stringcase.titlecase(input_str)    # => "Hello World Example"
stringcase.pathcase(input_str)     # => "hello/world/example"

Handling Edge Cases

import stringcase

# Handle None values
stringcase.camelcase(None)         # => "none"
stringcase.snakecase(None)         # => "none"

# Handle empty strings
stringcase.camelcase('')           # => ""
stringcase.pascalcase('')         # => ""

# Handle strings with leading punctuation
stringcase.camelcase('_foo_bar')   # => "fooBar"
stringcase.pascalcase('.foo_bar')  # => "FooBar"

Path and File Formatting

import stringcase

# Convert identifiers to path-like formats
component_name = "UserProfileManager"
stringcase.pathcase(component_name)      # => "user/profile/manager"
stringcase.dotcase(component_name)       # => "user.profile.manager"
stringcase.backslashcase(component_name) # => "user\\profile\\manager"

Text Processing

import stringcase

# Clean up text input
user_input = "_Hello, World! 123"
''.join(stringcase.alphanumcase(user_input))  # => "HelloWorld123"
stringcase.sentencecase(user_input)  # => "Hello world"
stringcase.titlecase(user_input)     # => " Hello World"

# Format for display
stringcase.trimcase("  spaced text  ")  # => "spaced text"