{"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":"en","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,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}