{"id":7072,"library":"chameleon","title":"Chameleon","description":"Chameleon is a fast HTML/XML template compiler for Python. It implements the Zope Page Templates language, compiling templates into optimized Python byte-code for high performance. Currently at version 4.6.0, it is actively maintained with a regular release cadence, supporting Python 3.9+ and PyPy 3.","status":"active","version":"4.6.0","language":"python","source_language":"en","source_url":"https://github.com/malthe/chameleon","tags":["templating","html","xml","zope","pagetemplates","compiler","web","performance"],"install":[{"cmd":"pip install chameleon","lang":"bash","label":"Latest stable version"}],"dependencies":[],"imports":[{"note":"For creating templates directly from a string.","symbol":"PageTemplate","correct":"from chameleon import PageTemplate"},{"note":"For loading templates from a file path.","symbol":"PageTemplateFile","correct":"from chameleon import PageTemplateFile"},{"note":"For loading multiple templates from a directory, relative to a base path.","symbol":"PageTemplateLoader","correct":"from chameleon import PageTemplateLoader"}],"quickstart":{"code":"from chameleon import PageTemplate\n\ntemplate_string = \"\"\"\n<div tal:define=\"name 'World'\">\n  <h1>Hello, ${name}!</h1>\n  <p>Today is ${context.today.strftime('%Y-%m-%d')}.</p>\n</div>\n\"\"\"\n\ntemplate = PageTemplate(template_string)\n\n# Render the template with a 'context' dictionary\nimport datetime\noutput = template(context={'today': datetime.date.today()})\nprint(output)","lang":"python","description":"This quickstart demonstrates creating a `PageTemplate` from a string, defining a variable using `tal:define`, interpolating variables with `${...}`, and passing a context object for dynamic data. It then renders the template and prints the resulting HTML."},"warnings":[{"fix":"Ensure your project runs on Python 3.9 or newer. Upgrade your Python environment if necessary.","message":"Chameleon 4.x dropped support for Python versions earlier than 3.9.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Replace `\\$` with `$$` in your templates if you need a literal dollar sign.","message":"Backslash-escaping of dollar-based string interpolation is no longer supported. To render a literal dollar sign, use `$$`.","severity":"breaking","affected_versions":">=4.0.0 (exact version unclear, but around 3.x to 4.x transition)"},{"fix":"Be aware that expressions within `tal:` attributes (e.g., `tal:content=\"expression\"`) will be evaluated as Python code. If you previously relied on Zope's path expressions without explicit `python:` prefixes, you might need to adjust your syntax.","message":"Chameleon uses Python as the default expression language, unlike traditional Zope Page Templates which might default to path expressions.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Avoid using variable names with two or more leading underscores (e.g., `__my_var__`). Do not attempt to redefine Python built-in types or keywords within your template's scope.","message":"Template variable names starting with two or more leading underscores are disallowed as they are reserved for internal compiler use. Also, certain Python built-ins (e.g., `int`, `float`, `str`, `None`, `True`, `False`) cannot be redefined within templates.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Migrate your template configuration to use the `boolean_attributes` option instead of `literal_false`. Consult the official documentation for `boolean_attributes` usage.","message":"The `literal_false` flag has been removed. Use `boolean_attributes` for similar behavior regarding boolean attributes.","severity":"deprecated","affected_versions":">=4.0.0 (removed around 4.0.0)"}],"env_vars":null,"search_vec":"'3':47 '3.9':44 '4.6.0':32 'activ':35 'byte':24 'byte-cod':23 'cadenc':41 'chameleon':1,2 'code':25 'compil':8,18,53 'current':29 'fast':5 'high':27 'html':49 'html/xml':6 'implement':12 'languag':17 'maintain':36 'optim':21 'page':15 'pagetempl':52 'perform':28,55 'pypi':46 'python':10,22,43 'regular':39 'releas':40 'support':42 'templat':7,16,19,48 'version':31 'web':54 'xml':50 'zope':14,51","created_at":"2026-04-16T13:42:16.406648+00:00","updated_at":"2026-04-16T13:42:16.406648+00:00","problems":[{"fix":"Run `pip install chameleon` to install the library. Ensure you are in the correct virtual environment if you are using one.","cause":"The 'chameleon' package is not installed in the current Python environment.","error":"ModuleNotFoundError: No module named 'chameleon'"},{"fix":"Verify your Python version meets the `chameleon` requirements (>=3.9 for current versions) using `python --version`. Upgrade `pip` (`pip install --upgrade pip`), clear the pip cache, or try specifying a compatible version of `chameleon` if you cannot upgrade Python.","cause":"This usually indicates an incompatibility between the requested package version and your Python version, or a corrupted pip cache.","error":"ERROR: Could not find a version that satisfies the requirement chameleon (from versions: none)"},{"fix":"Examine the full traceback provided by `chameleon.exc.ExpressionError`. It often includes the template's filename, line, and column where the error originated, along with the problematic expression and variable scope. Debug the Python expression within your template.","cause":"An error occurred during the evaluation of a Python expression within the template. The traceback will usually point to the specific expression and context.","error":"chameleon.exc.ExpressionError: ('...', ...)"},{"fix":"Carefully review the `tal:`, `metal:`, or inline Python syntax in your template around the reported line. Ensure proper nesting and valid logical constructs as interpreted by the Page Templates language.","cause":"Although Chameleon compiles to Python, complex `tal:` attribute logic, `metal:` macros, or inline Python blocks might lead to malformed generated Python code if the template syntax is incorrect or ambiguous.","error":"IndentationError: expected an indented block"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"4.6.0","cli_name":"","cli_version":null,"type":"library","homepage":"https://chameleon.readthedocs.io","github":"https://github.com/malthe/chameleon","docs":"https://chameleon.readthedocs.io","changelog":null,"pypi":"https://pypi.org/project/chameleon/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["web-framework","serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}