Skip to main content

Slim4Py is a tool that allows you to integrate Ruby Slim as a templating engine into any Python framework.

Project description

Slim4Py - Slim Templates for Python

What is Slim?

Slim is a fast, lightweight templating engine whose goal is reduce html syntax to the essential parts without becoming cryptic.

Check on the official site:

What is slim4py?

Slim4Py is a simple script that allows you to use all the functions of Slim (Ruby) in any python framework with the addition that you can also use the mako syntax (a popular and fast template engine for python).

Here is a small example of usage:

from slim4py.slim import Slim

slim = Slim("slim")

def say_hello():
    return "Hello World"

slim.render("example.slim", say_hello=say_hello, year="2019", author="")

About Magic Comments

If you need to use python inside the templates, you can define at the beginning of the file a magic comment containing all the variables that will be rendered by mako using the logic written in python.

To define a magic comment use:

/ mako_vars = [name_var_1, name_var_2, ...]

This comment will be detected by the engine and rendered using mako and python.

Combining Python With Ruby

/ mako_vars = [list_]
doctype 5
    title Slim4Py Example - Basic
      % for a in list_:
        % if a.startswith("t"):
            its two or three
        % elif a.startswith("f"):
        % else:
        % endif
      % endfor
    | Copyright - #{author} - #{year}


You need Python 3.7 or later to run slim4py, ruby and the slim gem

In Ubuntu, Mint and Debian you can install Requirements like this:

$ apt-get install python3 python3-pip
$ apt-get install ruby
$ gem install slim

For RHEL, Fedora and CentOS:

$ dnf install python3 python3-pip
$ dnf install ruby
$ gem install slim

For other systems

- Install Python3
- Install Ruby
- gem install slim

Quick start

slim4py can be installed using pip:

$ python3 -m pip install -U slim4py


$ pip install slim4py

for install slim4py from source:

$ git clone
$ cd ./slim4py
$ pip install .

Development status

slim4py is beta software, but it has already been used in production and it has an extensive test suite.

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

slim4py-1.0.1.tar.gz (5.1 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page