class_docstr: This renders the template fields of object.
  
  :meta private:
class_docstr_tok: ["This","renders","the","template","fields","of","object",".",":","meta","private",":"]
docstr: Fetch a Jinja template environment from the DAG or instantiate empty environment if no DAG.
docstr_tok: ["Fetch","a","Jinja","template","environment","from","the","DAG","or","instantiate","empty","environment","if","no","DAG","."]
code: def get_template_env(
      self, dag: DAG | None = None
  ) -> jinja2.Environment:
      """Fetch a Jinja template environment from the DAG or instantiate empty environment if no DAG."""
      # This is imported locally since Jinja2 is heavy and we don't need it
      # for most of the functionalities. It is imported by get_template_env()
      # though, so we don't need to put this after the 'if dag' check.
      from airflow.templates import SandboxedEnvironment
  
      if dag:
          return dag.get_template_env(force_sandboxed=False)
      return SandboxedEnvironment(cache_size=0)
  
file_path: airflow/airflow/template/templater.py
imports: from __future__ import annotations
  from dataclasses import dataclass
  from typing import TYPE_CHECKING, Any, Collection, Iterable, Sequence
  from airflow.utils.helpers import render_template_as_native, render_template_to_string
  from airflow.utils.log.logging_mixin import LoggingMixin
  from airflow.utils.mixins import ResolveMixin
  from airflow.utils.session import NEW_SESSION, provide_session
label_desc: Use image node_id 1 for calling the Templater obj's underlying member method code with example usage: obj.get_template_env(dag) and returns: SandboxedEnvironment, dag