Registry / web-framework / jinja2-pluralize

jinja2-pluralize

JSON →
library0.3.0pypypi✓ verified 84d ago

Jinja2 Pluralize is a Python library that provides pluralization filters for Jinja2 templates. It offers both a simple filter based on `inflect.py` and a Django-style pluralize filter. Currently at version 0.3.0, released in 2015, the project appears to be in a maintenance state with infrequent updates.

pip install jinja2-pluralize
INSTALL
IMPORT
SIG · JINJA2-PLURALIZE
J
jinja2-pluralize
web-frameworkpythonv0.3.0
Install
2.1s avg
Import
5434ms
Disk
19MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 5.749s · 20.3MB
glibc
py 3.103.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.
Debug
Known issues
gotchaThe library's last release was in 2015, and it was officially tested up to Python 3.5. While it might function on newer Python versions, active support and compatibility with recent Jinja2 releases (e.g., Jinja2 3.x) are not guaranteed, potentially leading to unforeseen issues.
fix
Thoroughly test on your target Python and Jinja2 versions. Consider migrating to actively maintained alternatives for new projects or if issues arise.
affects: All versions
gotchaThe `pluralize_simple` filter relies on the `inflect` library for its functionality. However, `inflect` is not a declared dependency of `jinja2-pluralize`. If you intend to use `pluralize_simple`, you must install `inflect` separately (`pip install inflect`).
fix
Explicitly install `inflect` if you plan to use `pluralize_simple`.
affects: All versions
gotchaGiven the lack of recent maintenance, consider modern and actively developed alternatives like `jinja2-inflection` for pluralization and other string transformations, which provides a broader set of filters and better compatibility with current Python and Jinja2 versions.
fix
Evaluate `jinja2-inflection` or other actively maintained Jinja2 extensions for new projects or when upgrading existing ones.
affects: All versions
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.
fix
Ensure 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.
fix
Register 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.
fix
Downgrade `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.
Agent activity
6 hits · last 30 days
node
6
Resources
jinja2-pluralize — pip install jinja2-pluralize · libregistry