Registry / serialization / inflector

inflector

JSON →
library3.1.1pypypi✓ verified 23d ago

Inflector is a Python library (version 3.1.1) designed for transforming strings, primarily focusing on pluralizing and singularizing English and Spanish nouns. It also provides utilities for converting strings between various cases like CamelCase, snake_case, and human-readable formats. It serves as a port of the Ruby on Rails Inflector, with Spanish language support developed independently. The project sees infrequent but notable updates, with the latest release in January 2024.

pip install inflector
INSTALL
IMPORT
SIG · INFLECTOR
I
inflector
serializationpythonv3.1.1
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.1.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Inflector
from inflector import Inflector
import inflector inflector.pluralize('cat')
The library exposes an `Inflector` class that must be instantiated, rather than providing module-level functions directly.

This quickstart demonstrates how to import the `Inflector` class, instantiate it, and use its core methods like `pluralize`, `singularize`, `underscore`, and `camelize` for common string transformations.

from inflector import Inflector inflector = Inflector() # Pluralization print(f"Plural of 'cat': {inflector.pluralize('cat')}") print(f"Plural of 'person': {inflector.pluralize('person')}") # Singularization print(f"Singular of 'cats': {inflector.singularize('cats')}") print(f"Singular of 'people': {inflector.singularize('people')}") # CamelCase to underscore print(f"Underscore 'CamelCase': {inflector.underscore('CamelCase')}") # Underscore to CamelCase print(f"Camelize 'device_type': {inflector.camelize('device_type')}") print(f"Camelize 'device_type' (lower first): {inflector.camelize('device_type', False)}")
Debug
Known issues
gotchaUsers often confuse 'inflector' with other similar Python libraries like 'inflection' or 'inflect'. While they share similar goals, their APIs are different. 'inflector' requires class instantiation, whereas 'inflection' provides direct module-level functions, and 'inflect' uses an engine class.
fix
Ensure you are importing and using the correct library for your needs. For `inflector`, instantiate `Inflector()` first: `from inflector import Inflector; i = Inflector()`.
affects: All versions
gotchaThe `inflector` library explicitly requires you to instantiate the `Inflector` class before using its methods (e.g., `inflector_instance.pluralize('word')`). Attempting to call methods directly on the module (e.g., `inflector.pluralize('word')`) will result in an `AttributeError`.
fix
Always create an instance of the `Inflector` class: `my_inflector = Inflector()`.
affects: All versions
gotchaThis library explicitly states that it supports pluralization and singularization only for English and Spanish nouns. It does not provide comprehensive support for other languages.
fix
Verify that your use case is limited to English or Spanish, or consider alternative libraries if broader linguistic support is required.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'inflector'
The Python `inflector` library (version 3.1.1) is often installed as 'Inflector' (with a capital 'I') via pip, but users mistakenly try to import it using lowercase 'inflector'. Additionally, there are other similarly named but distinct libraries like 'inflect' and 'inflection' that can cause confusion during import.
fix
Ensure the package is installed with `pip install Inflector`. Then, import it using the correct casing as `import Inflector` or `from Inflector import Inflector`. If you intended to use a different library (e.g., 'inflect' or 'inflection'), install and import that specific library accordingly.
AttributeError: 'Inflector' object has no attribute 'some_method_name'
This error occurs when attempting to call a method that does not exist on an `Inflector` object. This can happen due to a typo in the method name or if the user is trying to use a method from a different, similarly named string transformation library (like 'inflection' or 'inflect') that is not part of the `inflector` (version 3.1.1) API.
fix
Double-check the method name for typos and consult the `inflector` library's documentation to ensure the method exists and is correctly spelled. For example, if trying to pluralize, use `Inflector.pluralize('word')`.
TypeError: argument of type 'int' is not iterable
This `TypeError` typically arises when an `inflector` method, expecting a string argument, receives an integer or another non-string type. For instance, methods like `pluralize()` or `singularize()` are designed to operate on textual input.
fix
Ensure that the arguments passed to `inflector` methods are of the expected string type. Convert non-string inputs to strings before passing them to the functions, e.g., `Inflector.pluralize(str(number))`.
Upgrade
Version history
3.1.1latest on PyPI · released Jan 12, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
inflector — pip install inflector · libregistry