# st.connection

Source: https://docs.streamlit.io/develop/api-reference/connections/st.connection

> **Tip**
>
> This page only contains the `st.connection` API. For a deeper dive into creating and managing data connections within Streamlit apps, read [Connecting to data](https://docs.streamlit.io/develop/concepts/connections/connecting-to-data).

* Function signature:

   ```python
   st.connection(name, type=None, max_entries=None, ttl=<unset>, **kwargs)
   ```

* Parameters:

   | name | type | default | description |
   |---|---|---|---|
   | name | str |  | The connection name used for secrets lookup in secrets.toml. Streamlit uses secrets under [connections.] for the connection. type will be inferred if name is one of the following: "snowflake", "snowflake-callers-rights", or "sql". |
   | type | str, connection class, or None |  | The type of connection to create. This can be one of the following:  None (default): Streamlit will infer the connection type from name. If the type is not inferable from name, the type must be specified in secrets.toml instead. "snowflake": Streamlit will initialize a connection with SnowflakeConnection. "snowflake-callers-rights": Streamlit will initialize a "snowflake"-type connection, except the connection uses the current viewer's identity tokens instead of the app's connection configuration. "sql": Streamlit will initialize a connection with SQLConnection. A string path to an importable class: This must be a dot-separated module path ending in the importable class. Streamlit will import the class and initialize a connection with it. The class must extend st.connections.BaseConnection. An imported class reference: Streamlit will initialize a connection with the referenced class, which must extend st.connections.BaseConnection.   Important Connections of type "snowflake-callers-rights" only work when they run in a Snowflake Snowpark Container Services environment. If they are used in a local environment, they will raise exceptions. For local development, use an environment variable or secret to logically switch between a "snowflake" and "snowflake-callers-rights" connection depending on the runtime environment. |
   | max_entries | int or None |  | The maximum number of connections to keep in the cache. If this is None (default), the cache is unbounded. Otherwise, when a new entry is added to a full cache, the oldest cached entry is removed. |
   | ttl | float, timedelta, or None | applies | The maximum number of seconds to keep the connection in the cache. If this argument is omitted, runner.connectionDefaultTTL is used. That option defaults to None, which keeps the connection cached until it is cleared. Passing ttl explicitly -- including ttl=None -- always uses that value instead and ignores the server default. The server default applies to every connection type, including caller's-rights connections. When a connection expires, it is closed and the next call opens a new one. |
   | **kwargs | any |  | Connection-specific keyword arguments that are passed to the connection's ._connect() method. **kwargs are typically combined with (and take precedence over) key-value pairs in secrets.toml. To learn more, see the specific connection's documentation. |

* Returns: Subclass of BaseConnection

    An initialized connection object of the specified type.

For a comprehensive overview of this feature, check out this video tutorial by Joshua Carroll, Streamlit's Product Manager for Developer Experience. You'll learn about the feature's utility in creating and managing data connections within your apps by using real-world examples.

[Watch on YouTube](https://www.youtube.com/watch?v=xQwDfW7UHMo)
