Cheetah3, the Python-Powered Template Engine¶
Introduction¶
Cheetah3 is a free and open source template engine and code-generation tool written in Python. Cheetah can be used unto itself, or incorporated with other technologies and stacks regardless of whether they’re written in Python or not.
At its core, Cheetah is a domain-specific language for markup generation and templating which allows for full integration with existing Python code but also offers extensions to traditional Python syntax to allow for easier text-generation.
It’s a fork of the original CheetahTemplate library.
Talk Cheetah¶
You can get involved and talk with Cheetah developers on the Cheetah3 issue tracker.
Contents¶
- Authors and contributors
- News
- 3.4.0 (2024-12-02)
- 3.3.3.post1 (2024-02-28)
- 3.3.3 (2023-10-22)
- 3.3.2 (2023-08-08)
- 3.3.1 (2022-12-25)
- 3.3.0.post1 (2022-11-26)
- 3.3.0 (2022-10-10)
- 3.2.7b1 (2021-07-25)
- 3.2.6.post1 (2021-02-22)
- 3.2.6 (2020-10-01)
- 3.2.5 (2020-05-16)
- 3.2.4 (2019-10-22)
- 3.2.3 (2019-05-10)
- 3.2.2 (2019-04-29)
- 3.2.1 (2019-03-19)
- 3.2.0 (2019-02-06)
- 3.1.0 (2018-03-03)
- 3.0.1 (2018-02-27)
- 3.0.0 (2017-05-07)
- Contributing to Cheetah
- Downloading Cheetah
- Cheetah User’s Guide
- Introduction
- Vocabulary
- Getting Started
- Language Overview
- Comments
- Generating, Caching and Filtering Output
- Import, Inheritance, Declaration and Assignment
- Flow Control
- Error Handling
- Instructions to the Parser/Compiler
- Tips, Tricks and Troubleshooting
- Using Cheetah with Webware
- non-Webware HTML output
- Non-HTML Output
- Batteries included: templates and other libraries
- Visual Editors
- Useful Web Links
- Examples
- Cheetah vs. Other Template Engines
- Cheetah Recipes
- Cheetah Roadmap
- Cheetah Developer’s Guide
- Cheetah Enhancement Proposals
Cheetah in a nutshell¶
Below is a simple example of some Cheetah code, as you can see it’s practically Python. You can import, inherit and define methods just like in a regular Python module, since that’s what your Cheetah templates are compiled to :)
#from Cheetah.Template import Template
#extends Template
#set $people = [{'name' : 'Tom', 'mood' : 'Happy'}, {'name' : 'Dick',
'mood' : 'Sad'}, {'name' : 'Harry', 'mood' : 'Hairy'}]
<strong>How are you feeling?</strong>
<ul>
#for $person in $people
<li>
$person['name'] is $person['mood']
</li>
#end for
</ul>
Why Cheetah?¶
- Cheetah is supported by every major Python web framework.
- It is fully documented and is supported by an active user community.
- It can output/generate any text-based format.
- Cheetah compiles templates into optimized, yet readable, Python code.
- It blends the power and flexibility of Python with a simple template language that non-programmers can understand.
- It gives template authors full access to any Python data structure, module, function, object, or method in their templates. Meanwhile, it provides a way for administrators to selectively restrict access to Python when needed.
- Cheetah makes code reuse easy by providing an object-oriented interface to templates that is accessible from Python code or other Cheetah templates. One template can subclass another and selectively reimplement sections of it. Cheetah templates can be subclasses of any Python class and vice-versa.
- It provides a simple, yet powerful, caching mechanism that can dramatically improve the performance of a dynamic website.
- It encourages clean separation of content, graphic design, and program code. This leads to highly modular, flexible, and reusable site architectures, shorter development time, and HTML and program code that is easier to understand and maintain. It is particularly well suited for team efforts.
- Cheetah can be used to generate static html via its command-line tool.