BaseConnection
Base class for connection configuration objects.
Subclasses define the connection-specific fields and implement BaseConnection.get_session to create
the underlying client/session object (Snowpark, DuckDB, requests, etc.). The session is cached
on the instance; call BaseConnection.clear_session_cache to force a fresh session on the next access.
Subclasses must define a type field as a typing.Literal for Pydantic discriminated unions.
Methods
Section titled “Methods”.use_role()
Section titled “.use_role()”BaseConnection.use_role(role: str | None) -> Iterator[None]Activate role on this connection’s session for the duration of the block.
The prior role is restored on exit. No-op for backends without roles or when role
is blank/None;
Returns:
collections.abc.Iterator[None] - A context manager that activates role for the duration of thewithblock and yieldsNone.
.get_session()
Section titled “.get_session()”BaseConnection.get_session() -> AnyReturn the underlying session/client for this connection.
Override this in subclasses to create the connection-specific session (for example,
a Snowpark session, DuckDB connection, or Session).
Returns:
Any- The connection-specific session/client object.
Raises:
NotImplementedError- Always raised byBaseConnection.
.clear_session_cache()
Section titled “.clear_session_cache()”BaseConnection.clear_session_cache() -> NoneClear any cached session for this connection.
After calling this, the next call to BaseConnection.get_session creates a fresh
session/client.
Inheritance Hierarchy
Section titled “Inheritance Hierarchy”Subclassed By
Section titled “Subclassed By”config > connections ├── local │ └── LocalConnection └── snowflake ├── ExternalBrowserAuth ├── JWTAuth ├── OAuthAuth ├── OAuthAuthorizationCodeAuth ├── OAuthClientCredentialsAuth ├── ProgrammaticAccessTokenAuth ├── SnowflakeConnectionBase ├── UsernamePasswordAuth └── UsernamePasswordMFAAuth