Skip to main content

simple_template

A templating library for simple placeholder filling. Useful when the full might of Jinja and friends is unnecessary.

Installation

simple_template can be installed from PyPI or conda-forge.

Install from PyPI

pip install simple_template

Install from conda-forge

conda install -c conda-forge simple_template

Usage

Usage information can be found by running help(simple_template).

Help on module simple_template:

NAME
    simple_template - Fills in placeholder values in a string or file.

DESCRIPTION
    Intended for HTML files. Simple substitution only, with an easy API

CLASSES
    class TemplateError(builtins.KeyError)
        Rendering a template failed due a placeholder without a value.

FUNCTIONS
    render(template: str, /, **variables) -> str
        Render the template with the provided variables.

        The template should contain placeholders that will be replaced. These
        placeholders consist of the placeholder name within double curly braces. The
        name of the placeholder should be a valid python identifier. Whitespace
        between the braces and the name is ignored. E.g.: `{{ placeholder_name }}`

        An exception will be raised if there are placeholders without corresponding
        values. It is acceptable to provide unused values; they will be ignored.

        Parameters
        ----------
        template: str
            Template to fill with variables.

        **variables: Any
            Keyword arguments for the placeholder values. The argument name should
            be the same as the placeholder's name. You can unpack a dictionary of
            value with `render(template, **my_dict)`.

        Returns
        -------
        rendered_template: str
            Filled template.

        Raises
        ------
        TemplateError
            Value not given for a placeholder in the template.
        TypeError
            If the template is not a string, or a variable cannot be casted to a
            string.

        Examples
        --------
        >>> template = "<p>Hello {{myplaceholder}}!</p>"
        >>> simple_template.render(template, myplaceholder="World")
        "<p>Hello World!</p>"

    render_file(template_path: str, /, **variables) -> str
        Render a template directly from a file.

        Otherwise the same as `simple_template.render()`.

        Examples
        --------
        >>> simple_template.render_file("/path/to/template.html", myplaceholder="World")
        "<p>Hello World!</p>"

Licence

simple_template is licenced under the BSD0 licence, so you can do whatever you like with it. See the full licence text in the LICENCE file.

Release files for simple-template 1.0

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

Source distribution (sdist)

Source distribution for simple-template 1.0
File Size Uploaded
simple_template-1.0.tar.gz 7.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for simple-template 1.0
File Interpreter ABI Platform
simple_template-1.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.3 kB

Release files / simple_template-1.0.tar.gz

Download URL simple_template-1.0.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1f782c744d122f5d2b7d75b387019ec397e4f878665f5a2ed7f668801686e705
BLAKE2b-256 checksum
How to use checksums
5c120604d5052957d75dceab5a819e7a213889cf5494ce2c9a22363d067427aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / simple_template-1.0-py3-none-any.whl

Download URL simple_template-1.0-py3-none-any.whl
Size 4.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
20698b23e6ebb2ad55ae2412d87d22eba3f4af1c86b37da225a74f24d5fe5b1d
BLAKE2b-256 checksum
How to use checksums
7644f71b3f369e2efd9e28c19f607b90f81afd29cb2dcfe753c11e1955e66f49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release history Release notifications | RSS feed

This release

1.0 This release

2 release files

0.3

2 release files

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