code: def _create_connection(
      name: str,
      connection_class: Type[ConnectionClass],
      max_entries: int | None = None,
      ttl: float | timedelta | None = None,
      **kwargs,
  ) -> ConnectionClass:
      """Create an instance of connection_class with the given name and kwargs.
  
      The weird implementation of this function with the @cache_resource annotated
      function defined internally is done to:
        * Always @gather_metrics on the call even if the return value is a cached one.
        * Allow the user to specify ttl and max_entries when calling st.connection.
      """
  
      def __create_connection(
          name: str, connection_class: Type[ConnectionClass], **kwargs
      ) -> ConnectionClass:
          return connection_class(connection_name=name, **kwargs)
  
      if not issubclass(connection_class, BaseConnection):
          raise StreamlitAPIException(
              f"{connection_class} is not a subclass of BaseConnection!"
          )
  
      # We modify our helper function's `__qualname__` here to work around default
      # `@st.cache_resource` behavior. Otherwise, `st.connection` being called with
      # different `ttl` or `max_entries` values will reset the cache with each call.
      ttl_str = str(
          ttl
      ).replace(  # Avoid adding extra `.` characters to `__qualname__`
          ".", "_"
      )
      __create_connection.__qualname__ = (
          f"{__create_connection.__qualname__}_{ttl_str}_{max_entries}"
      )
      __create_connection = cache_resource(
          max_entries=max_entries,
          show_spinner="Running `st.connection(...)`.",
          ttl=ttl,
      )(__create_connection)
  
      return __create_connection(name, connection_class, **kwargs)
  
imports: from __future__ import annotations
  import importlib
  import os
  import re
  from datetime import timedelta
  from typing import Any, Dict, Type, TypeVar, overload
  from typing_extensions import Final, Literal
  from streamlit.connections import BaseConnection, SnowflakeConnection, SnowparkConnection, SQLConnection
  from streamlit.deprecation_util import deprecate_obj_name
  from streamlit.errors import StreamlitAPIException
  from streamlit.runtime.caching import cache_resource
  from streamlit.runtime.metrics_util import gather_metrics
  from streamlit.runtime.secrets import secrets_singleton
label_desc: Use image node_id 1 for calling a global function with example usage: _create_connection(name, connection_class, max_entries, ttl) and returns: __create_connection, connection_class