Skip to main content

tempest

Syntax-independent text templating library

Easily embed literal python code into any file.

Features:

  • Configurable open/close delimiters
  • Works with any language
  • It's just more python

Big Scary Security Warning

This library will execute arbitrary code contained in the template. Do not allow untrusted templates to be executed.

Install

pip install tempest-fmt

Example

Template

# This is a markdown file

Hello my name is {name=}

My friends are:
{for f in friends:}
    - {f=}

{divisor = 2}
{for i in range(5):}
    {if i % divisor == 0:}
        Did you know {i=} is divisible by {divisor=}

I can even evaluate stuff: {len(name)=}

Python Implementation

import tempest

t = tempest.parse_template_file("myTemplate.md", "{", "}")

values = {
    "name": "Jimmy",
    "friends": ["Carl", "Steve", "Greg"],
}

with open("output.md", mode='w') as f:
    t.generate(f, value)

Output file

# This is a markdown file

Hello my name is Jimmy

My friends are:
- Carl
- Steve
- Greg

Did you know 0 is divisible by 2
Did you know 2 is divisible by 2
Did you know 4 is divisible by 2

I can even evaluate stuff: 5

Syntax specifics

For simplicity, we will assume the delimiters to be { }
All python statements will be contained within the delimiters, any text outside will be considered raw text.

Statements of the form {<expr>=} will be evaluated as str(<expr>) and directly inserted into the text.
All other statements will be considered logical statements. Such statements must follow indentation rules for python and should have no raw text on the line. Any statements following will have indentation stripped, this includes raw text (extra whitespace after the expected indentation is left as-is).

Indentation is important
Leading spaces replaced with dots for this example

{for x in range(3):}
....- {x}

My next thing

Will produce

- 0
- 1
- 2

My next thing

Compared to

{for x in range(3):}
....- {x}
....

My next thing

Will produce

- 0

- 1

- 2

My next thing

Release files for tempest-fmt 1.0.2

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

Source distribution (sdist)

Source distribution for tempest-fmt 1.0.2
File Size Uploaded
tempest_fmt-1.0.2.tar.gz 5.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tempest-fmt 1.0.2
File Interpreter ABI Platform
tempest_fmt-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size:11.3 kB

Release files / tempest_fmt-1.0.2.tar.gz

Download URL tempest_fmt-1.0.2.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
6b8fca8ad8719e4622c492b242dd08002dc38b2785cff1d52375de6ef0c14411
BLAKE2b-256 checksum
How to use checksums
6187f3fc0044079be5f9e1923dad5aeae5a6574f71d2847725d085e01d212fd8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / tempest_fmt-1.0.2-py3-none-any.whl

Download URL tempest_fmt-1.0.2-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
86dca56f54dbf2287118a529708b7f15994a63fc61295f3362e2205817178e80
BLAKE2b-256 checksum
How to use checksums
998a659cf2279074c069ed2db11b53ec7076fe9d8c7d7fedf943d0f6324316e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

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