Skip to main content

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: http://slim-lang.com/

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="https://github.com/multiversecoder/slim4py")

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
html
  head
    title Slim4Py Example - Basic
  body
    #contents
      |
      % for a in list_:
        % if a.startswith("t"):
            its two or three
        % elif a.startswith("f"):
            four/five
        % else:
            one
        % endif
      % endfor
  footer
    | Copyright - #{author} - #{year}

Requirements

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

or:

$ pip install slim4py

for install slim4py from source:

$ git clone https://github.com/multiversecoder/slim4py
$ 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.

Metadata

Release files for slim4py 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for slim4py 1.0.1
File Size Uploaded Provenance
slim4py-1.0.1.tar.gz 5.1 kB Without provenance Details

Release files / slim4py-1.0.1.tar.gz

Download URL slim4py-1.0.1.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f40bef227ac59bd0c700d308a5e8d75c423772372b9e98d313f878e94bb8975a
BLAKE2b-256 checksum
How to use checksums
b2aba45217f48bd90182491faa1e74094a83e447bed35e35ddb3cfa13b4ea112
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.5

Security for slim4py 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page