Loader

class liquid.Loader

Bases: ABC

Template loader base class.

abstractmethod get_source(env: Environment, name: str, context: RenderContext | None = None, **kwargs: object) → TemplateSource

Return template source text and meta data identified by name.

async get_source_async(env: Environment, name: str, context: RenderContext | None = None, **kwargs: object) → TemplateSource

Return template source text and meta data identified by name.

class liquid.DictLoader(templates: dict[str, str])

Bases: Loader

A template loader that reads source text from a dictionary.

Parameters:

templates – A mapping of template names to template source code.

get_source(env: Environment, name: str, context: RenderContext | None = None, **kwargs: object) → TemplateSource

Return template source text and meta data identified by name.

class liquid.CachingDictLoader(templates: dict[str, str], *, auto_reload: bool = True, namespace_key: str = '', capacity: int = 300)

Bases: CachingLoaderMixin, DictLoader

A DictLoader that caches parsed templates in memory.

class liquid.FileSystemLoader(search_path: str | Path | Iterable[str | Path], *, encoding: str = 'utf-8', ext: str | None = None, reject_symlinks: bool = False)

Bases: Loader

A loader that loads templates from one or more directories on a file system.

Parameters:
  • search_path – One or more paths to search.

  • encoding – Encoding to use when opening files.

  • ext – A default file extension. Should include a leading period.

  • reject_symlinks – When True, reject paths to symlinks that resolve to files outside the search path. Defaults to False.

Raises:

ValueError – If ext is not a valid suffix.

get_source(env: Environment, name: str, context: RenderContext | None = None, **kwargs: object) → TemplateSource

Get source information for a template.

async get_source_async(env: Environment, name: str, context: RenderContext | None = None, **kwargs: object) → TemplateSource

Get source information for a template.

class liquid.CachingFileSystemLoader(search_path: str | Path | Iterable[str | Path], encoding: str = 'utf-8', ext: str | None = None, *, reject_symlinks: bool = False, auto_reload: bool = True, namespace_key: str = '', capacity: int = 300)

Bases: CachingLoaderMixin, FileSystemLoader

A file system loader that caches parsed templates in memory.

Parameters:
  • search_path – One or more paths to search.

  • encoding – Open template files with the given encoding.

  • ext – A default file extension. Should include a leading period.

  • reject_symlinks – When True, reject paths to symlinks that resolve to files outside the search path. Defaults to False.

  • auto_reload – If True, automatically reload a cached template if it has been updated.

  • namespace_key –

    The name of a global render context variable or loader keyword argument that resolves to the current loader “namespace” or “scope”.

    If you’re developing a multi-user application, a good namespace might be uid, where uid is a unique identifier for a user and templates are arranged in folders named for each uid inside the search path.

  • capacity – The maximum number of templates to hold in the cache before removing the least recently used template.

class liquid.PackageLoader(package: str | ModuleType, *, package_path: str | Iterable[str] = 'templates', encoding: str = 'utf-8', ext: str = '.liquid')

Bases: Loader

A template loader that reads templates from Python packages.

Parameters:
  • package – Import name of a package containing Liquid templates.

  • package_path – One or more directories in the package containing Liquid templates.

  • encoding – Encoding of template files.

  • ext – A default file extension to use if one is not provided. Should include a leading period.

get_source(env: Environment, name: str, context: RenderContext | None = None, **kwargs: object) → TemplateSource

Return template source text and meta data identified by name.

async get_source_async(env: Environment, name: str, context: RenderContext | None = None, **kwargs: object) → TemplateSource

Return template source text and meta data identified by name.

class liquid.ChoiceLoader(loaders: list[Loader])

Bases: Loader

A template loader that delegates to other template loaders.

Parameters:

loaders – A list of loaders implementing liquid.Loader.

get_source(env: Environment, name: str, context: RenderContext | None = None, **kwargs: object) → TemplateSource

Get source information for a template.

async get_source_async(env: Environment, name: str, context: RenderContext | None = None, **kwargs: object) → TemplateSource

Get source information for a template.

class liquid.CachingChoiceLoader(loaders: list[Loader], *, auto_reload: bool = True, namespace_key: str = '', capacity: int = 300)

Bases: CachingLoaderMixin, ChoiceLoader

A ChoiceLoader that caches parsed templates in memory.

Parameters:
  • loaders – A list of loaders implementing liquid.Loader.

  • auto_reload – If True, automatically reload a cached template if it has been updated.

  • namespace_key – The name of a global render context variable or loader keyword argument that resolves to the current loader “namespace” or “scope”.

  • capacity – The maximum number of templates to hold in the cache before removing the least recently used template.