创建与数据存储或 API 的新连接,或返回现有连接。
连接的配置选项、根据、保密信息等来自不同来源:
任何特定于连接的配置文件。
应用程序的 secrets.toml 文件。
传递给此函数的 kwargs。
Function signature[source] st.connection(name, type=None, max_entries=None, ttl=None, **kwargs)
Returns (Connection object)
An initialized Connection object of the specified type.
Parameters name (str)
The connection name used for secrets lookup in [connections.<name>]. Type will be inferred from passing "sql", "snowflake", or "snowpark".
type (str, connection class, or None)
The type of connection to create. It can be a keyword ("sql", "snowflake", or "snowpark"), a path to an importable class, or an imported class reference. All classes must extend st.connections.BaseConnection and implement the _connect() method. If the type kwarg is None, a type field must be set in the connection's section in secrets.toml.
max_entries (int or None)
The maximum number of connections to keep in the cache, or None for an unbounded cache. (When a new entry is added to a full cache, the oldest cached entry will be removed.) The default is None.
ttl (float, timedelta, or None)
The maximum number of seconds to keep results in the cache