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.1.0.tar.gz (12.6 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.1.0-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: minja-1.1.0.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for minja-1.1.0.tar.gz
Algorithm Hash digest
SHA256 1eee79e0518f27fe00094bc1c4da8f55ff8ae567e1d2589d8565063dbfb9cb22
MD5 fb5e60b1ce75b75f5545ef205c25913f
BLAKE2b-256 be5e246040b4332b0c753378490097e24095526c16bf7e731c5a21a304870f6c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: minja-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for minja-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 83caacebb8b5795d63ce8a3a343abe6e8b5a1b0052d005b4c5839e19d7a99d1d
MD5 90e1fb28c3b903071573dfb77859f478
BLAKE2b-256 ac5abd09beca9c198e01e5440c4271215c3d00c6c2fd20a12b72d9731ee0422d

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