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)
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.