Jinja2 Strcase

0.0.2 · active · verified Mon Apr 13

jinja2-strcase is a Python package that provides a set of filters for converting string cases within Jinja2 templates, including common formats like snake_case, kebab-case, and camelCase. It is currently at version 0.0.2 and is a port of the Go `strcase` package. The package has an 'Alpha' development status, indicating it is not yet stable for production use.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a Jinja2 environment with the `StrcaseExtension` and then use various case conversion filters (e.g., `to_snake`, `to_screaming_snake`, `to_camel`) on strings within a template.

from jinja2 import Environment
from jinja2_strcase import StrcaseExtension

# Create a Jinja2 environment and load the StrcaseExtension
env = Environment(extensions=[StrcaseExtension])

# Define a template using the 'to_snake' filter
template = env.from_string("{{ 'Any kind of string' | to_snake }}")
print(f"to_snake: {template.render()}")

# Example with another filter: to_screaming_snake
template_screaming_snake = env.from_string("{{ 'Another Test String' | to_screaming_snake }}")
print(f"to_screaming_snake: {template_screaming_snake.render()}")

# Example with to_camel
template_camel = env.from_string("{{ 'this is a camel case' | to_camel }}")
print(f"to_camel: {template_camel.render()}")

view raw JSON →