Registry / serialization / inflect

inflect

JSON →
library7.5.0pypypi✓ verified 52d ago

Inflect.py is a Python library designed to correctly generate plurals, singular nouns, ordinals, indefinite articles (a/an), and word-based representations of numbers. Its functionality is primarily focused on the English language. As of version 7.5.0, it maintains an active development and release cadence, with regular updates addressing features, bug fixes, and compatibility.

serialization
pip install inflect
Install & Compatibility
Where this runs
tested against v7.5.0 · 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.925 runs
installs and imports cleanly · install 0.0s · import 5.620s · 19.1MB
glibc
py 3.103.925 runs
installs and imports cleanly · install 1.8s · import 4.854s · 20MB
17MB installed
● package 17MB
Code
Verified usage

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

engine
import inflect p = inflect.engine()
The primary way to interact with the library is through an instance of the engine class.

This quickstart demonstrates common `inflect` functionalities: pluralizing nouns conditionally, generating ordinal numbers, converting numerals to words, and selecting indefinite articles ('a' or 'an').

import inflect p = inflect.engine() # Pluralization word = 'cat' count = 5 print(f"The plural of '{word}' is '{p.plural(word)}'") print(f"I saw {count} {p.plural_noun(word, count)}.") # Ordinal numbers number = 21 print(f"The ordinal of {number} is {p.ordinal(number)}") # Numbers to words big_number = 1234567 print(f"'{big_number}' in words is '{p.number_to_words(big_number)}'") # Indefinite articles print(f"An apple and {p.an('historical object')}")
Debug
Known issues
breakingVersion 7.0.0 removed methods that were renamed in an earlier 0.2.0 release. If your code uses very old aliases, they will cease to function.
fix
Refer to the `inflect` documentation for current method names and update your code accordingly. These typically involve methods for singular/plural inflection.
affects: >=7.0.0
gotchaWhen using methods like `plural_noun()`, ensure you pass the *singular* form of the word. Similarly, `singular_noun()` expects the *plural* form. Passing the incorrect base form can lead to undefined or incorrect inflections.
fix
Always provide the correct base form (singular for pluralization, plural for singularization) to the respective `inflect.engine()` methods.
affects: All versions
gotchaOlder versions (pre-7.2.0, particularly in the v6.x series) experienced compatibility issues with Pydantic, leading to `ValueError` (e.g., `ValueError: Field default cannot be set in Annotated`). This was often due to Pydantic 1 vs. 2 conflicts. While v7.2.0 replaced Pydantic with Typeguard, users with existing Pydantic installations in their environment might still encounter conflicts if older `inflect` versions are used or if a new conflict arises.
fix
Upgrade `inflect` to the latest v7.x version. If issues persist, ensure your environment's Pydantic (if present) and `inflect` versions are compatible, or isolate `inflect` in a separate virtual environment.
affects: Primarily pre-7.2.0; potential for environment conflicts in any version.
gotchaFor combining multiple inflections within a single string, the `p.inflect()` string-interpolating method is generally more readable and efficient than concatenating multiple method calls.
fix
Consider using `print(p.inflect('num({0}) plural_noun(error) plural_verb(was) detected.'.format(errors)))` instead of `print(p.num(errors), p.plural_noun(' error'), p.plural_verb(' was'), ' detected.')`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'inflect'
The 'inflect' library is not installed in the current Python environment or the environment is not properly activated.
fix
pip install inflect
ValueError: `Field` default cannot be set in `Annotated`
This error arises from compatibility issues between older versions of 'inflect' (pre-7.2.0) and Pydantic v2.x, as 'inflect' versions 7.2.0 and later replaced Pydantic with Typeguard.
fix
Upgrade 'inflect' to the latest version (7.2.0 or higher) using `pip install --upgrade inflect`, or downgrade Pydantic to a 1.x version using `pip install 'pydantic<2'`.
Incorrect pluralization/singularization output (e.g., p.plural("cats") returns "catses")
The 'plural()' methods (like `p.plural()`, `p.plural_noun()`) expect a singular form of the word, and 'singular_noun()' expects a plural form. Passing the incorrect base form results in undefined or incorrect inflections.
fix
Always provide the correct base form (singular for pluralization, plural for singularization) to the respective `inflect.engine()` methods. For example, use `p.plural('cat')` for pluralizing 'cat' and `p.singular_noun('people')` for singularizing 'people'.
AttributeError: module 'inflect' has no attribute 'plural'
Methods like 'plural' are available on an inflect.engine() object, not directly on the inflect module itself.
fix
import inflect
p = inflect.engine()
word = p.plural("cat")
TypeError: inflect.engine() takes no arguments
The inflect.engine() constructor does not accept any arguments; configuration is done via attributes on the returned engine object.
fix
import inflect
p = inflect.engine()
# Configuration options are set on the engine instance, e.g.:
p.classical(all=False)
p.no("and")
Upgrade
Version history
7.5.0latest on PyPI
Audit
Dependencies
more-itertoolsrequiredRuntime dependency for iterable utilities.
typeguardrequiredRuntime dependency for runtime type checking (introduced in v7.2.0 to replace Pydantic).
typing_extensionsrequiredRuntime dependency for backported typing features, even for Python 3.9+ environments.
Agent activity
20 hits · last 30 days
node
6
seranking-bot
4
ahrefsbot
3
Amazon
1
Resources