I am using st.experimental_connection for duckdb and for that I am using ExperimentalBaseConnection Base Class.
class DuckDBConnection(ExperimentalBaseConnection[duckdb.DuckDBPyConnection]):
def _connect(self, **kwargs) -> duckdb.DuckDBPyConnection:
if 'database' in kwargs:
db = kwargs.pop('database')
else:
st.write(self._secrets)
db = self._secrets['database']
return duckdb.connect(database=db, **kwargs)
But while printing the secrets , I am getting a empty dict , though it was throwing the error to me
KeyError: βst.secrets has no key βdatabaseβ. Did you forget to add it to secrets.toml or the app settings on Streamlit Cloud? More info: Secrets management - Streamlit Docsβ
I had already added database as key in secrets.toml file
Hi @Harsh_Gupta sorry about the late follow up. If this is for your app locally, Iβd check if your secret.toml is in the right directory
- streamlit_app.py
- .streamlit
- secrets.toml
You can write out the secret st.write(st.secrets) to check
if this your app in cloud, you would need to manually add secrets to the secret managements under settings. Let me know if this helps.
st.write(st.secrets) is working , but after inheriting ExperimentalBaseConnection , I am implementing the connect method , in which I will be using secrets for making the connection , there it is not working β¦
def _connect(self, **kwargs) -> duckdb.DuckDBPyConnection:
st.write("check",st.secrets)
if 'database' in kwargs:
db = kwargs.pop('database')
else:
db = self._secrets['database']
return duckdb.connect(database=db, **kwargs)
it looks like it is picking up the database in your kwarg. if you want to read the credentials from the secrets, could give a try on and see it that returns anything? conn = st.experimental_connection("duckdb", type=DuckDBConnection)