textcase A feature complete Python text case conversion library. Installation Create and activate a virtual environment and then install textcase : pip install textcase Example You can convert strings into a case using the textcase.convert function: from textcase import case , convert print ( convert ( "ronnie james dio" , case . SNAKE )) # ronnie_james_dio print ( convert ( "Ronnie_James_dio" , case . CONSTANT )) # RONNIE_JAMES_DIO print ( convert ( "RONNIE_JAMES_DIO" , case . KEBAB )) # ronnie-james-dio print ( convert ( "RONNIE-JAMES-DIO" , case . CAMEL )) # ronnieJamesDio print ( convert ( "ronnie-james-dio" , case . PASCAL )) # RonnieJamesDio print ( convert ( "RONNIE JAMES DIO" , case . LOWER )) # ronnie james dio print ( convert ( "ronnie james dio" , case . UPPER )) # RONNIE JAMES DIO print ( convert ( "ronnie-james-dio" , case . TITLE )) # Ronnie James Dio print ( convert ( "ronnie james dio" , case . SENTENCE )) # Ronnie james dio By default, textcase.convert and textcase.converter.CaseConverter.convert will split along a set of default word boundaries, that is underscores _ , , hyphens - , , spaces , , changes in capitalization from lowercase to uppercase aA , , adjacent digits and letters a1 , 1a , A1 , 1A , , , , , and acroynms AAa (as in HTTPRequest ). For more precision, you can specify boundaries to split based on the word boundaries of a particular case. For example, splitting from snake case will only use underscores as word boundaries: from textcase import boundary , case , convert print ( convert ( "2020-04-16_my_cat_cali" , case . TITLE )) # 2020 04 16 My Cat Cali print ( convert ( "2020-04-16_my_cat_cali" , case . TITLE , ( boundary . UNDERSCORE ,))) # 2020-04-16 My Cat Cali This library can detect acronyms in camel-like strings. It also ignores any leading, trailing, or duplicate delimiters: from textcase import case , convert print ( convert ( "IOStream" , case . SNAKE )) # io_stream print ( convert ( "myJSONParser" , case . SNAKE )) # my_jso...
First seen: 2025-04-01 23:49
Last seen: 2025-04-02 09:50