pyheck
pyheck is a Python library that provides efficient case conversion functionalities, acting as a thin wrapper around the high-performance Rust library `heck`. It supports various case conversions like snake_case, camelCase, kebab-case, and their uppercase variants. Intended to be unicode-aware, consistent, and fast, it claims 5-10x performance benefits over Python's `inflection` library for similar tasks. The current version is 0.1.5, released on February 18, 2022, indicating an infrequent release cadence since its initial development.
Common errors
-
NameError: name 'snake' is not defined
cause Attempting to use a conversion function (e.g., `snake`) without importing it from the `pyheck` package.fixEnsure the specific function is imported: `from pyheck import snake`. -
TypeError: 'module' object is not callable
cause Attempting to call the `pyheck` module directly as a function (e.g., `pyheck('some_text')`) instead of calling one of its conversion functions.fixImport and use the specific conversion function, like `from pyheck import snake; snake('some text')`.
Warnings
- gotcha When migrating from `inflection` or similar libraries, be aware that `pyheck`'s functions may not have a 1:1 overlap or identical behavior with other libraries. Always verify edge cases.
- gotcha For converting sequences of strings, prefer the `_many` counterparts (e.g., `snake_many`, `kebab_many`). These functions leverage Rust's parallel features for significantly higher performance on lists.
Install
-
pip install pyheck
Imports
- kebab
from pyheck import kebab
- snake
from pyheck import snake
- lower_camel
from pyheck import lower_camel
- kebab_many
import pyheck.kebab_many
from pyheck import kebab_many
Quickstart
from pyheck import snake, upper_camel, kebab
text1 = "Hello world from pyheck"
text2 = "another string input"
# Convert to snake_case
snake_case_text = snake(text1)
print(f"Snake case: {snake_case_text}")
# Convert to UpperCamelCase
camel_case_text = upper_camel(text1)
print(f"Upper Camel case: {camel_case_text}")
# Convert a list of strings to kebab-case efficiently
texts_to_convert = [text1, text2]
kebab_case_list = kebab_many(texts_to_convert)
print(f"Kebab case list: {kebab_case_list}")