{"id":4486,"library":"ct3","title":"Cheetah3 Template Engine","description":"Cheetah3 is a free and open-source template engine and code-generation tool for Python. It is a fork of the original CheetahTemplate library, designed to compile templates into optimized, readable Python code. It blends Python's power and flexibility with a simple template language. The library is actively maintained and supports Python 2.7 and Python 3.4+.","status":"active","version":"3.4.0.post5","language":"en","source_language":"en","source_url":"https://github.com/CheetahTemplate3/cheetah3","tags":["template engine","code generation","web development"],"install":[{"cmd":"pip install ct3","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for execution. Supports Python 2.7 and >=3.4.","package":"Python","optional":false},{"reason":"Optional for Markdown processing within templates.","package":"Markdown","optional":true}],"imports":[{"symbol":"Template","correct":"from Cheetah.Template import Template"}],"quickstart":{"code":"from Cheetah.Template import Template\nimport datetime\n\n# Define a simple template string\ntemplate_code = \"\"\"\n#set $current_year = datetime.date.today().year\nHello, $name!\nThis template was rendered in $current_year using $engine.\n\"\"\"\n\n# Create a template instance and pass data\nt = Template(template_code, searchList=[\n    {'name': 'Registry User', 'engine': 'Cheetah3'}\n])\n\n# Render the template\noutput = str(t)\nprint(output)","lang":"python","description":"Demonstrates defining a template string, injecting data via a search list, and rendering the output. It also shows using Python imports and `#set` directives within the template."},"warnings":[{"fix":"Ensure your Python environment meets the minimum requirement (2.7 or >=3.4) and recompile all templates after upgrading to Cheetah3 version 3.0.0 or later.","message":"Version 3.0.0 introduced significant breaking changes, including dropping support for Python versions older than 2.7 and requiring recompilation of all previously compiled Cheetah templates.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Use `cheetah compile` instead, which provides the same functionality.","message":"The standalone `cheetah-compile` command-line program is deprecated.","severity":"deprecated","affected_versions":"All versions >=3.x"},{"fix":"Always treat templates from untrusted sources as potentially malicious. Implement sandboxing or strict input validation if dynamic template loading is necessary.","message":"A security issue (arbitrary code execution) was reported. Caution is advised when processing templates from untrusted sources without proper sanitization or sandboxing.","severity":"gotcha","affected_versions":"Potentially all versions prior to specific fixes. Review GitHub issues for updates."},{"fix":"Update exception handling to catch `ModuleNotFoundError` for module-not-found scenarios, especially when dealing with dynamic template imports.","message":"Under Python 3, `Cheetah.ImportHooks` now correctly raises `ModuleNotFoundError` instead of `ImportError` when a module cannot be found. Code that specifically catches `ImportError` for missing template modules might need updating.","severity":"gotcha","affected_versions":">=3.4.0"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}