Skip to main content

Templaty

Documentation Status

Templaty is a code generator written in Python that focuses on generating correct and readable programming code. It features fine-grained control over whitespacing and indentation and a rich meta-language that allows full control over the end result.

🌈 There now is a syntax plugin for Vim!

The template syntax was inspired by Jinja2 and should be very easy to pick up.

def annoying_prompt():
    {% for i in range(0, 5) %}
      prompt("Hey, how you're doing?")
    {% endfor %}

Generates the following code:

def annoying_prompt():
    prompt("Hey, how you're doing?")
    prompt("Hey, how you're doing?")
    prompt("Hey, how you're doing?")
    prompt("Hey, how you're doing?")
    prompt("Hey, how you're doing?")

What about generating an identity matrix in C that imposes no runtime cost?

static const int IDENTITY_MATRIX[][] = [
  {% join i in range(0, 10) with ',' %}
    [{% join j in range(0, 10) with ',' %}{% if j == i %}1{% else %}0{% endjoin %}]
  {% endjoin %}
];

It should look something like this:

static const int IDENTITY_MATRIX[][] = [
  [1,0,0,0,0,0,0,0,0,0],
  [0,1,0,0,0,0,0,0,0,0],
  [0,0,1,0,0,0,0,0,0,0],
  [0,0,0,1,0,0,0,0,0,0],
  [0,0,0,0,1,0,0,0,0,0],
  [0,0,0,0,0,1,0,0,0,0],
  [0,0,0,0,0,0,1,0,0,0],
  [0,0,0,0,0,0,0,1,0,0],
  [0,0,0,0,0,0,0,0,1,0],
  [0,0,0,0,0,0,0,0,0,1]
];

This is just the tip of the iceberg of what Templaty can do!

Usage

Templaty is available on PyPi. You can issue the following command to install it:

pip3 install -U --user templaty

This should make the main command templaty available in your terminal.

FAQ

Will this library support Python 2?

No. Python 2 has reached its end-of-life and the organisation recommends everyone to upgrade to Python 3. Porting to Python 2 requires extra work for no good reason.

Is it safe to use this library in my web server?

No, absolutely not! Templaty is a tool meant to be run by developers, not end-users. As such, it has little (if any) security checks. You should never run untrusted input using Templaty, only code you wrote yourself or from a developer you trust.

What extension should I use for my template files?

It is recommended to use the .tply extension so that syntax plugins like vim-templaty automatically set up the right syntax highlighting for you.

If your template contains code in another programming language, simply prefix the default file extension to .tply, e.g. mytemplate.cc.tply.

License

Templaty is licensed under the Apache 2.0 license, in the hope it will help developers write better programs.

Metadata

Release files for templaty 1.3.4

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

Source distribution (sdist)

Source distribution for templaty 1.3.4
File Size Uploaded
templaty-1.3.4.tar.gz 19.4 kB Details

Release files / templaty-1.3.4.tar.gz

Download URL templaty-1.3.4.tar.gz
Size 19.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0da75ae3f9c7b6630750a7588d29359978b328fb4bd06a9765b193834a810137
BLAKE2b-256 checksum
How to use checksums
a77648e792dc4d9dd6c86ab4b2e4973917e207dbb71915f379ad1d1fa80da0aa
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.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.5

Release history Release notifications | RSS feed

This release

1.3.4 This release

1 release file

1.3.3

1 release file

1.3.2

1 release file

1.3.1

1 release file

1.3.0

1 release file

1.2.0

1 release file

1.1.0

1 release file

1.0.0

1 release file

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