Install & Compatibility
Where this runs
tested against v0.3.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
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 5.749s · 20.3MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 2.1s · import 5.118s · 21MB
19MB installed
● package 19MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
pluralize_dj
✓ from jinja2_pluralize import pluralize_dj
This is the Django-style pluralization filter, commonly used.
pluralize_simple
✓ from jinja2_pluralize import pluralize_simple
This is the simple pluralization filter, which depends on 'inflect'.
This quickstart demonstrates how to register the `pluralize_dj` filter with a Jinja2 environment and use it in a template to handle singular and plural forms of words, including custom plural suffixes.
from jinja2 import Environment
from jinja2_pluralize import pluralize_dj
env = Environment()
env.filters['pluralize'] = pluralize_dj
template = env.from_string('I have {{ count }} dog{{ count|pluralize }}.')
# Example 1: count = 1
result1 = template.render(count=1)
print(f"Rendered for count=1: {result1}") # Expected: I have 1 dog.
# Example 2: count = 2
result2 = template.render(count=2)
print(f"Rendered for count=2: {result2}") # Expected: I have 2 dogs.
template_args = env.from_string('There {{ num_items|pluralize("is", "are") }} {{ num_items }} item{{ num_items|pluralize }}.')
# Example 3: using custom singular/plural words
result3 = template_args.render(num_items=1)
print(f"Rendered for num_items=1: {result3}") # Expected: There is 1 item.
result4 = template_args.render(num_items=3)
print(f"Rendered for num_items=3: {result4}") # Expected: There are 3 items.
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'jinja2_pluralize'
The `jinja2-pluralize` library has not been installed, or there is a typo in the import statement, or Python cannot find the installed package.
fixEnsure the package is correctly installed using pip: `pip install jinja2-pluralize`
jinja2.exceptions.TemplateSyntaxError: Unknown filter 'pluralize'
The pluralize filter from `jinja2-pluralize` was not properly registered with the Jinja2 environment before the template attempted to use it.
fixRegister the filter with your Jinja2 environment: `from jinja2 import Environment
from jinja2_pluralize import pluralize_dj
env = Environment()
env.filters['pluralize'] = pluralize_dj`
ImportError: cannot import name 'soft_unicode' from 'markupsafe'
This error typically occurs when a newer version of `MarkupSafe` (which removes `soft_unicode`) is installed, conflicting with an older version of `Jinja2` or `jinja2-pluralize` that still expects `soft_unicode` to exist.
fixDowngrade `MarkupSafe` to a compatible version, usually `MarkupSafe<2.1.0`: `pip install MarkupSafe<2.1.0`
Upgrade
Version history
0.3.0latest on PyPI · released Oct 9, 2015
Audit
Dependencies
Jinja2requiredCore templating engine this library extends.
inflectoptionalRequired for the 'pluralize_simple' filter, but not a declared dependency.