{"id":2079,"library":"jinja2-humanize-extension","title":"Jinja2 Humanize Extension","description":"jinja2-humanize-extension is a Jinja2 extension that integrates the popular `humanize` library, providing a suite of human-readable formatting filters directly within Jinja2 templates. It allows developers to easily format numbers, dates, and sizes (e.g., `naturalsize`, `naturaldate`, `intcomma`, `intword`) using Jinja's filter syntax. The current version is 0.4.0, with releases occurring periodically to maintain compatibility with its `humanize` dependency.","status":"active","version":"0.4.0","language":"python","source_language":"en","source_url":"https://github.com/metwork-framework/jinja2_humanize_extension","tags":["jinja2","extension","humanize","template-filters","formatting"],"install":[{"cmd":"pip install jinja2-humanize-extension","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Core templating engine this library extends.","package":"jinja2"},{"reason":"Provides the core humanization functions. Version compatibility is critical for this dependency, see warnings.","package":"humanize","optional":false}],"imports":[{"note":"Used when adding the extension to a Jinja2 Environment.","symbol":"HumanizeExtension","correct":"from jinja2_humanize_extension import HumanizeExtension"},{"note":"Required to create a Jinja2 environment and load the extension.","symbol":"Environment","correct":"from jinja2 import Environment"}],"quickstart":{"code":"from jinja2 import Environment\nfrom jinja2_humanize_extension import HumanizeExtension\n\n# We load the extension in a jinja2 Environment\nenv = Environment(extensions=[HumanizeExtension])\n\ntemplate = env.from_string(\n    \"The file size is : {{ 30000000|humanize_naturalsize() }}\\n\"\n    \"Today is: {{ '2023-01-15'|humanize_naturaldate() }}\\n\"\n    \"Number with commas: {{ 1234567|humanize_intcomma() }}\"\n)\n\nresult = template.render()\nprint(result)\n# Expected output:\n# The file size is : 30.0 MB\n# Today is: Jan 15th 2023\n# Number with commas: 1,234,567","lang":"python","description":"This example demonstrates how to create a Jinja2 environment, load the `HumanizeExtension`, and then render a template using several `humanize` filters."},"warnings":[{"fix":"When upgrading `jinja2-humanize-extension` to `0.3.0` or higher, ensure your `humanize` dependency is `4.0.0` or greater. If using `jinja2-humanize-extension < 0.3.0`, ensure `humanize < 4.0.0` to avoid dependency conflicts and runtime errors.","message":"Version 0.3.0 of `jinja2-humanize-extension` introduced compatibility with `humanize` library version 4.0 and later. Prior to v0.3.0 (specifically v0.2.1 and earlier), the extension was only compatible with `humanize < 4.0.0`.","severity":"breaking","affected_versions":"<0.3.0"},{"fix":"Consider refactoring templates to use alternative `humanize` functions if `abs_timedelta` or `date_and_delta` are heavily used, to future-proof your application against potential removals in future `humanize` versions.","message":"`humanize` version 4.0 deprecated `abs_timedelta` and `date_and_delta` functions. While `jinja2-humanize-extension` retains these as filters for compatibility, their future availability or behavior might be subject to changes in the `humanize` library itself.","severity":"deprecated","affected_versions":"0.3.0 and later (when used with humanize >= 4.0)"},{"fix":"Configure Flask's `jinja_options` to include the extension, typically after initializing your Flask app: `app.jinja_options['extensions'] = ['jinja2_humanize_extension.HumanizeExtension']`.","message":"When integrating `jinja2-humanize-extension` with Flask, merely importing the extension might not make the filters available through `render_template`. The extension needs to be explicitly added to Flask's Jinja2 environment options.","severity":"gotcha","affected_versions":"All versions when used with Flask"}],"env_vars":null,"search_vec":"'0.4.0':55 'allow':32 'compat':62 'current':52 'date':38 'depend':66 'develop':33 'direct':27 'e.g':41 'easili':35 'extens':3,7,11,68 'filter':26,49,72 'format':25,36,73 'human':2,6,16,23,65,69 'human-read':22 'intcomma':44 'integr':13 'intword':45 'jinja':47 'jinja2':1,5,10,29,67 'jinja2-humanize-extension':4 'librari':17 'maintain':61 'naturald':43 'naturals':42 'number':37 'occur':58 'period':59 'popular':15 'provid':18 'readabl':24 'releas':57 'size':40 'suit':20 'syntax':50 'templat':30,71 'template-filt':70 'use':46 'version':53 'within':28","created_at":"2026-04-09T18:42:37.765275+00:00","updated_at":"2026-04-16T15:52:25.218421+00:00","problems":[{"fix":"Ensure the extension is properly loaded in your Jinja2 Environment: `env = Environment(extensions=[\"jinja2_humanize_extension.HumanizeExtension\"])`. Then, use the correct filter name in your template, e.g., `{{ my_date_value|humanize_naturaldate() }}` for dates, or `{{ 30000000|humanize_naturalsize() }}` for sizes.","cause":"The jinja2-humanize-extension was not loaded into the Jinja2 environment, or the filter is being called with the incorrect name (e.g., 'naturaldate' instead of 'humanize_naturaldate'). Filters provided by this extension are prefixed with 'humanize_'.","error":"TemplateAssertionError: No filter named 'naturaldate'."},{"fix":"Verify that `jinja2-humanize-extension` is installed (`pip show jinja2-humanize-extension`) and that the extension string in the `Environment` constructor is exactly `'jinja2_humanize_extension.HumanizeExtension'`. For Flask applications, you might need to configure `app.jinja_options['extensions'] = ['jinja2_humanize_extension.HumanizeExtension']`.","cause":"Jinja2 cannot find the specified extension module. This usually indicates a typo in the extension's import path or the package is not correctly installed or accessible in the Python environment.","error":"jinja2.exceptions.ExtensionError: Could not load extension 'jinja2_humanize_extension.HumanizeExtension'"},{"fix":"Install the package using pip: `pip install jinja2-humanize-extension`.","cause":"The `jinja2-humanize-extension` Python package, or one of its dependencies, has not been installed in the current Python environment.","error":"ImportError: No module named 'jinja2_humanize_extension'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.4.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/metwork-framework/jinja2_humanize_extension","docs":null,"changelog":null,"pypi":"https://pypi.org/project/jinja2-humanize-extension/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["web-framework","serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-28","next_check":"2026-07-28","install_tag":null}}