Inflection

raw JSON →
0.5.1 verified Tue May 12 auth: no python install: verified quickstart: verified maintenance

Inflection is a Python library that provides string transformation utilities, porting the functionality of Ruby on Rails' inflector. It handles pluralization, singularization, and various case conversions like CamelCase to snake_case. The current version is 0.5.1, released in August 2020, indicating an irregular release cadence and a maintenance status.

pip install inflection
error ModuleNotFoundError: No module named 'inflection'
cause The 'inflection' library is not installed in your Python environment or the Python interpreter cannot find it.
fix
Install the library using pip: pip install inflection
error AttributeError: module 'inflection' has no attribute 'pluralise'
cause You are trying to call a method that does not exist or is misspelled. The library uses 'pluralize' (American English spelling), not 'pluralise'.
fix
Correct the method name to the accurate spelling, e.g., inflection.pluralize('word')
error NameError: name 'inflection' is not defined
cause This typically occurs when you've imported specific functions from the 'inflection' module (e.g., `from inflection import pluralize`) but then try to access them via the module name as if the entire module was imported (e.g., `inflection.pluralize`).
fix
Either import the entire module (import inflection) or call the function directly without the module prefix (pluralize('word') after from inflection import pluralize).
error TypeError: expected string or bytes-like object
cause An 'inflection' function was called with an argument of an incorrect type, such as an integer or a list, when it expected a string.
fix
Ensure that the input provided to the 'inflection' function is a string, converting it if necessary: inflection.pluralize(str(123))
breaking Version 0.4.0 dropped support for Python 2.x (2.6, 2.7) and older Python 3.x versions (3.3, 3.4), as well as PyPy. The library now requires Python 3.5 or newer. Ensure your environment meets this requirement before upgrading or using.
fix Upgrade to Python 3.5+ or pin the `inflection` version to <0.4.0 for older Python environments.
gotcha The `pluralize` and `singularize` functions are specifically designed for English words and may not produce correct results for other languages. The library is a direct port of Ruby on Rails' inflector, which primarily targets English.
fix Use a dedicated internationalization (i18n) library for pluralization and singularization in non-English languages.
gotcha The `camelize()` function defaults to `uppercase_first_letter=True`, resulting in `UpperCamelCase`. If `lowerCamelCase` is desired, you must explicitly set this parameter to `False`. For example, `inflection.camelize('foo_bar', False)` returns 'fooBar'.
fix Specify `uppercase_first_letter=False` in `camelize()` calls if `lowerCamelCase` is intended.
python os / libc status wheel install import disk
3.10 alpine (musl) - - 0.00s 17.8M
3.10 slim (glibc) - - 0.00s 18M
3.11 alpine (musl) - - 0.00s 19.7M
3.11 slim (glibc) - - 0.00s 20M
3.12 alpine (musl) - - 0.00s 11.6M
3.12 slim (glibc) - - 0.00s 12M
3.13 alpine (musl) - - 0.00s 11.2M
3.13 slim (glibc) - - 0.00s 12M
3.9 alpine (musl) - - 0.00s 17.3M
3.9 slim (glibc) - - 0.00s 18M

The quickstart demonstrates basic string transformations: `camelize` for case conversion, `pluralize` for converting singular words to their plural form, and `singularize` for converting plurals to singulars.

import inflection

# Convert a snake_case string to CamelCase
result_camel = inflection.camelize("my_variable_name")
print(f"CamelCase: {result_camel}")

# Pluralize a word
result_plural = inflection.pluralize("mouse")
print(f"Plural: {result_plural}")

# Singularize a word
result_singular = inflection.singularize("data")
print(f"Singular: {result_singular}")