class_docstr: A connection to a SQL database using a SQLAlchemy Engine. Initialize using ``st.connection("<name>", type="sql")``.
  
  SQLConnection provides the ``query()`` convenience method, which can be used to
  run simple read-only queries with both caching and simple error handling/retries.
  More complex DB interactions can be performed by using the ``.session`` property
  to receive a regular SQLAlchemy Session.
  
  SQLConnections should always be created using ``st.connection()``, **not**
  initialized directly. Connection parameters for a SQLConnection can be specified
  using either ``st.secrets`` or ``**kwargs``. Some frequently used parameters include:
  
  - **url** or arguments for `sqlalchemy.engine.URL.create()
    <https://docs.sqlalchemy.org/en/20/core/engines.html#sqlalchemy.engine.URL.create>`_.
    Most commonly it includes a dialect, host, database, username and password.
  
  - **create_engine_kwargs** can be passed via ``st.secrets``, such as for
    `snowflake-sqlalchemy <https://github.com/snowflakedb/snowflake-sqlalchemy#key-pair-authentication-support>`_
    or `Google BigQuery <https://github.com/googleapis/python-bigquery-sqlalchemy#authentication>`_.
    These can also be passed directly as ``**kwargs`` to connection().
  
  - **autocommit=True** to run with isolation level ``AUTOCOMMIT``. Default is False.
  
  Example
  -------
  >>> import streamlit as st
  >>>
  >>> conn = st.connection("sql")
  >>> df = conn.query("select * from pet_owners")
  >>> st.dataframe(df)
class_docstr_tok: ["A","connection","to","a","SQL","database","using","a","SQLAlchemy","Engine",".","Initialize","using","``","st.connection","(","``","<","name",">","''",",","type=","''","sql","''",")","``",".","SQLConnection","provides","the","``","query","(",")","``","convenience","method",",","which","can","be","used","to","run","simple","read-only","queries","with","both","caching","and","simple","error","handling\/retries",".","More","complex","DB","interactions","can","be","performed","by","using","the","``",".session","``","property","to","receive","a","regular","SQLAlchemy","Session",".","SQLConnections","should","always","be","created","using","``","st.connection","(",")","``",",","*","*","not","*","*","initialized","directly",".","Connection","parameters","for","a","SQLConnection","can","be","specified","using","either","``","st.secrets","``","or","``","*","*","kwargs","``",".","Some","frequently","used","parameters","include",":","-","*","*","url","*","*","or","arguments","for","`","sqlalchemy.engine.URL.create","(",")","<","https",":","\/\/docs.sqlalchemy.org\/en\/20\/core\/engines.html","#","sqlalchemy.engine.URL.create",">","`","_",".","Most","commonly","it","includes","a","dialect",",","host",",","database",",","username","and","password",".","-","*","*","create_engine_kwargs","*","*","can","be","passed","via","``","st.secrets","``",",","such","as","for","`","snowflake-sqlalchemy","<","https",":","\/\/github.com\/snowflakedb\/snowflake-sqlalchemy","#","key-pair-authentication-support",">","`","_","or","`","Google","BigQuery","<","https",":","\/\/github.com\/googleapis\/python-bigquery-sqlalchemy","#","authentication",">","`","_",".","These","can","also","be","passed","directly","as","``","*","*","kwargs","``","to","connection","(",")",".","-","*","*","autocommit=True","*","*","to","run","with","isolation","level","``","AUTOCOMMIT","``",".","Default","is","False",".","Example","--","--","--","-",">",">",">","import","streamlit","as","st",">",">",">",">",">",">","conn","=","st.connection","(","``","sql","''",")",">",">",">","df","=","conn.query","(","``","select","*","from","pet_owners","''",")",">",">",">","st.dataframe","(","df",")"]
docstr: Return a SQLAlchemy Session.
  
  Users of this connection should use the contextmanager pattern for writes,
  transactions, and anything more complex than simple read queries.
  
  See the usage example below, which assumes we have a table ``numbers`` with a
  single integer column ``val``. The `SQLAlchemy
  <https://docs.sqlalchemy.org/en/20/orm/session_basics.html>`_ docs also contain
  much more information on the usage of sessions.
  
  Example
  -------
  >>> import streamlit as st
  >>> conn = st.connection("sql")
  >>> n = st.slider("Pick a number")
  >>> if st.button("Add the number!"):
  ...     with conn.session as session:
  ...         session.execute("INSERT INTO numbers (val) VALUES (:n);", {"n": n})
  ...         session.commit()
docstr_tok: ["Return","a","SQLAlchemy","Session",".","Users","of","this","connection","should","use","the","contextmanager","pattern","for","writes",",","transactions",",","and","anything","more","complex","than","simple","read","queries",".","See","the","usage","example","below",",","which","assumes","we","have","a","table","``","numbers","``","with","a","single","integer","column","``","val","``",".","The","`","SQLAlchemy","<","https",":","\/\/docs.sqlalchemy.org\/en\/20\/orm\/session_basics.html",">","`","_","docs","also","contain","much","more","information","on","the","usage","of","sessions",".","Example","--","--","--","-",">",">",">","import","streamlit","as","st",">",">",">","conn","=","st.connection","(","``","sql","''",")",">",">",">","n","=","st.slider","(","``","Pick","a","number","''",")",">",">",">","if","st.button","(","``","Add","the","number","!","``",")",":","...","with","conn.session","as","session",":","...","session.execute","(","``","INSERT","INTO","numbers","(","val",")","VALUES","(",":","n",")",";","''",",","{","``","n","''",":","n","}",")","...","session.commit","(",")"]
code: def session(self) -> "Session":
      """Return a SQLAlchemy Session.
  
      Users of this connection should use the contextmanager pattern for writes,
      transactions, and anything more complex than simple read queries.
  
      See the usage example below, which assumes we have a table ``numbers`` with a
      single integer column ``val``. The `SQLAlchemy
      <https://docs.sqlalchemy.org/en/20/orm/session_basics.html>`_ docs also contain
      much more information on the usage of sessions.
  
      Example
      -------
      >>> import streamlit as st
      >>> conn = st.connection("sql")
      >>> n = st.slider("Pick a number")
      >>> if st.button("Add the number!"):
      ...     with conn.session as session:
      ...         session.execute("INSERT INTO numbers (val) VALUES (:n);", {"n": n})
      ...         session.commit()
      """
      from sqlalchemy.orm import Session
  
      return Session(self._instance)
  
file_path: streamlit/lib/streamlit/connections/sql_connection.py
imports: from __future__ import annotations
  from collections import ChainMap
  from copy import deepcopy
  from datetime import timedelta
  from typing import TYPE_CHECKING, List, Optional, Union, cast
  import pandas
  from streamlit.connections import BaseConnection
  from streamlit.connections.util import extract_from_dict
  from streamlit.errors import StreamlitAPIException
  from streamlit.runtime.caching import cache_data
label_desc: Use image node_id 6 for calling the SQLConnection obj's underlying member method code with example usage: obj.session() and returns: Session