PyHeck

PyHeck is a case conversion library. It exists to provide case conversion between common cases like CamelCase and snake_case. It is intended to be unicode aware, internally, consistent, and reasonably well performing.

PyHeck is merely a wrapper around a Rust library heck. Most of this documentation is copied lovingly from the heck docs.

Note

Each pyheck function has a _many counterpart that operates on a sequence of strings. For example, the snake function converts a single string to snake case, while snake_many converts a sequence of strings into a list of snake case strings. The _many functions achieve high performance by taking advantage of Rust’s parallel features, so you should use them in places where they make sense.

Installation

pip install pyheck

Note: requires Python >= 3.7.

API

kebab(s)

Convert to kebab-case.

In kebab-case, word boundaries are indicated by hyphens.

Example

>>> from pyheck import kebab
>>> kebab("We are going to inherit the earth.")
'we-are-going-to-inherit-the-earth'
kebab_many(strings)

Convert list of strings to kebab-case.

In kebab-case, word boundaries are indicated by hyphens.

Example

>>> from pyheck import kebab_many
>>> kebab_many(["We are going", "to inherit the earth."])
['we-are-going', 'to-inherit-the-earth']
lower_camel(s)

Convert to lowerCamelCase.

In lowerCamelCase, word boundaries are indicated by capital letters, excepting the first word.

Example

>>> from pyheck import lower_camel
>>> lower_camel("It is we who built these palaces and cities.")
'itIsWeWhoBuiltThesePalacesAndCities'
lower_camel_many(strings)

Convert a list of strings to lowerCamelCase.

In lowerCamelCase, word boundaries are indicated by capital letters, excepting the first word.

Example

>>> from pyheck import lower_camel_many
>>> lower_camel_many(["It is we", "who built these"])
['itIsWe', 'whoBuiltThese']
shouty_kebab(s)

Convert to SHOUTY-KEBAB-CASE.

In SHOUTY-KEBAB-CASE, word boundaries are indicated by hyphens and all words are in uppercase.

Example

>>> from pyheck import shouty_kebab
>>> shouty_kebab("We are going to inherit the earth.")
'WE-ARE-GOING-TO-INHERIT-THE-EARTH'
shouty_kebab_many(strings)

Convert a list of strings to SHOUTY-KEBAB-CASE.

In SHOUTY-KEBAB-CASE, word boundaries are indicated by hyphens and all words are in uppercase.

Example

>>> from pyheck import shouty_kebab_many
>>> shouty_kebab_many(["We are going", "to inherit the earth."])
['WE-ARE-GOING', 'TO-INHERIT-THE-EARTH']
shouty_snake(s)

Convert to SHOUTY_SNAKE_CASE.

In SHOUTY_SNAKE_CASE, word boundaries are indicated by underscores and all words are in uppercase.

Example

>>> from pyheck import shouty_snake
>>> shouty_snake("That world is growing in this minute.")
'THAT_WORLD_IS_GROWING_IN_THIS_MINUTE'
shouty_snake_many(strings)

Convert a list of strings to SHOUTY_SNAKE_CASE.

In SHOUTY_SNAKE_CASE, word boundaries are indicated by underscores and all words are in uppercase.

Example

>>> from pyheck import shouty_snake_many
>>> shouty_snake_many(["That world is", "growing in this minute."])
['THAT_WORLD_IS', 'GROWING_IN_THIS_MINUTE']
snake(s)

Convert to snake_case.

In snake_case, word boundaries are indicated by underscores.

Example

>>> from pyheck import snake
>>> snake("We carry a new world here, in our hearts.")
'we_carry_a_new_world_here_in_our_hearts'
snake_many(strings)

Convert a list of strings to snake_case.

In snake_case, word boundaries are indicated by underscores.

Example

>>> from pyheck import snake_many
>>> snake_many(["DeviceType", "fooBar"])
['device_type', 'foo_bar']
title(s)

Convert to Title Case.

In Title Case, word boundaries are indicated by spaces, and every word is capitalized.

Example

>>> from pyheck import title
>>> title("We have always lived in slums and holes in the wall.")
'We Have Always Lived In Slums And Holes In The Wall'
title_many(strings)

Convert a list of strings to Title Case.

In Title Case, word boundaries are indicated by spaces, and every word is capitalized.

Example

>>> from pyheck import title_many
>>> title_many(["We have always", "lived in slums"])
['We Have Always', 'Lived In Slums']
upper_camel(s)

Convert to UpperCamelCase.

In UpperCamelCase, word boundaries are indicated by capital letters, including the first word.

Example

>>> from pyheck import upper_camel
>>> upper_camel("We are not in the least afraid of ruins.")
'WeAreNotInTheLeastAfraidOfRuins'
upper_camel_many(strings)

Convert a list of strings to UpperCamelCase.

In UpperCamelCase, word boundaries are indicated by capital letters, including the first word.

Example

>>> from pyheck import upper_camel_many
>>> upper_camel_many(["We are not", "in the least"])
['WeAreNot', 'InTheLeast']

Why use PyHeck?

PyHeck offers 5-10x performance benefits over the established case conversion library, inflection.

However not all the functions overlap between the two libraries, and some apparently similar functions may differ in subtle ways. So be careful to check edge cases in whichever library you choose.