Skip to main content

jinja2_humanize_extension

Status (master branch)

GitHub CI Maintenance

What is it ?

This is a jinja2 extension to use humanize library inside jinja2 templates.

Syntax

The generic syntax is {{ 'VALUE'|humanize_{humanize_fn}([humanize_fn_args]) }}.

Following humanize functions are currently mapped:

  • naturalsize
  • abs_timedelta (deprecated with humanize >= 4.0, we keep it for compatibility)
  • date_and_delta (deprecated with humanize >= 4.0, we keep it for compatibility)
  • naturaldate
  • naturalday
  • naturaldelta
  • naturaltime
  • precisedelta
  • ordinal
  • intcomma
  • intword
  • apnumber
  • fractional
  • scientific
  • clamp
  • metric
  • activate
  • deactivate
  • thousands_separator
  • decimal_separator

See humanize documentation for argument details.

To take a more real example, let's take the naturalsize() function. To use it inside a jinja2 template with this extension, you have to use:


The file size is: {{ 30000000|humanize_naturalsize(binary=False, gnu=True) }}

result content will be : The file size is : 30.0 MB

You can use the same logic with all supported functions. If you need other functions, feel free to open a PullRequest.

Installation

pip install jinja2-humanize-extension

Full example

from jinja2 import Template, Environment

# We load the extension in a jinja2 Environment
env = Environment(extensions=["jinja2_humanize_extension.HumanizeExtension"])

template = env.from_string("The file size is : {{ 30000000|humanize_naturalsize() }}")
result = template.render()

# [...]

result content will be : The file size is : 30.0 MB

Contributing guide

See CONTRIBUTING.md file.

Code of Conduct

See CODE_OF_CONDUCT.md file.

Sponsors

(If you are officially paid to work on MetWork Framework, please contact us to add your company logo here!)

logo

Release files for jinja2-humanize-extension 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jinja2-humanize-extension 0.4.0
File Size Uploaded
jinja2_humanize_extension-0.4.0.tar.gz 4.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jinja2-humanize-extension 0.4.0
File Interpreter ABI Platform
jinja2_humanize_extension-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.5 kB

Release files / jinja2_humanize_extension-0.4.0.tar.gz

Download URL jinja2_humanize_extension-0.4.0.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e7d69b1c20f32815bbec722330ee8af14b1287bb1c2b0afa590dbf031cadeaa0
BLAKE2b-256 checksum
How to use checksums
74770bba383819dd4e67566487c11c49479ced87e77c3285d8e7f7a3401cf882
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / jinja2_humanize_extension-0.4.0-py3-none-any.whl

Download URL jinja2_humanize_extension-0.4.0-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b6326e2da0f7d425338bebf58848e830421defbce785f12ae812e65128518156
BLAKE2b-256 checksum
How to use checksums
26b408c9d297edd5e1182506edecccbb88a92e1122a057953068cadac420ca5d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page