Skip to main content

A Mini Jinja Template Engine

Project description

minja

A Mini Jinja Template Engine

I am creating this package because I need something like Jinja, but in a much smaller footprint.

Install

pip install minja

Usage

A Simple Usage

from minja import Template

template = Template("{{ flowers }} are {{ color }}")
print(template.render(flowers="Roses", color="red"))
# Roses are red

What Is a Template?

A template is a string embedded variables. For example, the template in previous example has two variables, flowers and color.

Note that the spaces surrounding the variables are insignificant: they are there to improve readability. That means the following will render to the same text:

t1 = Template(">{{name}}<")
t2 = Template(">{{ name }}<")
t3 = Template(">{{     name     }}<")

print(t1.render(name="Anna"))  # '>Anna<'
print(t2.render(name="Anna"))  # '>Anna<'
print(t3.render(name="Anna"))  # '>Anna<'

How Can I Get the Names of the Variables?

A template maintains a property called .names which keep track of the names of the variables.

template = Template("{{ flowers }} are {{ color }}")
print(template.names)  # {'flowers', 'color'}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

minja-1.2.0.tar.gz (35.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

minja-1.2.0-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file minja-1.2.0.tar.gz.

File metadata

  • Download URL: minja-1.2.0.tar.gz
  • Upload date:
  • Size: 35.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for minja-1.2.0.tar.gz
Algorithm Hash digest
SHA256 4eab83c29450507089827bfb75332cd2592b3dd5ee62e488e156d375b9aca912
MD5 9f04917b18b2cf79760de5373ef0c5d4
BLAKE2b-256 05d17b9f1052cafb9892877da64448d321f6e79fb0da7efd311a4937bd491e00

See more details on using hashes here.

File details

Details for the file minja-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: minja-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for minja-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 22da87e62b73a3253f3bc276b34edb21da36f3f319bbd9ccbf18c7f77e279b8c
MD5 d36e79158d2c1755ddb4e5723f252e7b
BLAKE2b-256 dc24bf1e374431e6edfd93661b0241ba6dbc693f759dd7014508cca7aafb0644

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page