{"id":4223,"library":"python-liquid","title":"Python Liquid","description":"Python Liquid is a Python engine for Liquid, the safe, customer-facing template language, currently at version 2.1.0. It closely follows Shopify/Liquid's design and test suite, providing a robust and secure templating solution for web applications. While there isn't a fixed release cadence, the project is actively maintained with regular updates.","status":"active","version":"2.1.0","language":"en","source_language":"en","source_url":"https://github.com/jg-rp/liquid","tags":["templating","liquid","html","web","frontend"],"install":[{"cmd":"pip install python-liquid","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Required Python version.","package":"python","optional":false}],"imports":[{"symbol":"render","correct":"from liquid import render"},{"symbol":"parse","correct":"from liquid import parse"},{"symbol":"Template","correct":"from liquid import Template"},{"symbol":"Environment","correct":"from liquid import Environment"},{"symbol":"FileSystemLoader","correct":"from liquid import FileSystemLoader"}],"quickstart":{"code":"from liquid import Environment, FileSystemLoader\nimport os\n\n# For a simple template string, use render() or parse():\n# from liquid import render\n# print(render(\"Hello, {{ you }}!\", you=\"World\"))\n\n# For more complex applications, an Environment is recommended.\n# This example assumes a 'templates' directory with 'index.liquid'.\n\n# Create a dummy templates directory and file for demonstration\nos.makedirs(\"templates\", exist_ok=True)\nwith open(\"templates/index.liquid\", \"w\") as f:\n    f.write(\"Hello, {{ name }}! From {{ app_name }}. Today is {{ date | date: '%Y-%m-%d' }}.\")\n\nenv = Environment(\n    loader=FileSystemLoader(\"templates/\"),\n    globals={\n        \"app_name\": os.environ.get('LIQUID_APP_NAME', 'Default App') # Example with env var\n    }\n)\n\ntemplate = env.get_template(\"index.liquid\")\noutput = template.render(name=\"Liquid User\", date=\"2026-04-11\")\nprint(output)\n\n# Clean up dummy files/directory\nos.remove(\"templates/index.liquid\")\nos.rmdir(\"templates\")","lang":"python","description":"The simplest way to render a template string is using the package-level `render()` function. For applications requiring configuration, template loading from files, or better performance, it's recommended to configure an `Environment` instance. This example demonstrates using `Environment` with a `FileSystemLoader` to render a template from a file, passing variables and accessing globals."},"warnings":[{"fix":"Refer to the archived documentation for 1.x and the current documentation for 2.x to identify specific API changes and migration paths. Thoroughly test your application after upgrading.","message":"Upgrading from Python Liquid 1.x to 2.x may involve breaking API changes. The project maintains separate documentation archives for older major versions, indicating significant shifts.","severity":"breaking","affected_versions":"1.x to 2.x"},{"fix":"Initialize a single `Environment` instance for your application and use its `get_template()` or `from_string()` methods to load and render templates.","message":"For all but the simplest one-off string renderings, using `liquid.Environment` with a template loader is more efficient and provides better configurability than repeatedly creating `liquid.Template` instances directly.","severity":"gotcha","affected_versions":"All"},{"fix":"Utilize whitespace control characters (`-` within `{%` or `}}` tags, e.g., `{%-` or `-%}`) to strip leading or trailing whitespace around tags and output, as described in the Liquid syntax documentation.","message":"Liquid's default behavior for whitespace in templates can lead to unwanted blank lines or spaces in the rendered output.","severity":"gotcha","affected_versions":"All"},{"fix":"Keep business logic in your Python application code. Use Liquid templates solely for presentation and data display. Pre-process data in Python before passing it to the Liquid template for rendering.","message":"Liquid is designed as a secure, non-evaluating template language. It does not allow arbitrary Python code execution within templates. Attempting to implement complex application logic directly in Liquid templates might be cumbersome or impossible.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}