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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for minja-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c2e64669249818ea7c25ad04953cc3779fe38cb82e1e4406df81ee86548f77be
MD5 ebcdf903b615655665bb7125cf0b0b43
BLAKE2b-256 2140abfd11ac458f6faaabaa47b36aac77d33f3b569e50cc4a5414ec72a4b0c0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: minja-1.0.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.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4365b59887c25ec8de9dcff53202c448a574baf9dce487ccfd388f83aa4bca6e
MD5 81fbbefc17969a579436b19136b5f52c
BLAKE2b-256 801a98565a9f689bc8946741bbb063521ed6a17146b9576fae286a23eb98e586

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