I am new to streamlit, and am trying to set query params to be able to share configurations. However, I cannot get the ‘new’ query_params to work at all.
import streamlit as st
st.query_params['test'] = 1
st.write("Done")
st.stop()
The new get_all also doesn’t work, this gives an error st.query_params.get_all("test")
AttributeError: 'dict' object has no attribute 'get_all'
I have checked and I am running 1.30.0 - I get the deprecation warning when using the experimental_* versions, but setting using the new API just doesn’t do anything.
To set query parameters, you should use st.experimental_set_query_params .
import streamlit as st
# Set query parameters
st.experimental_set_query_params(test=1)
st.write("Query parameter set")
To get the current query parameters, use st.experimental_get_query_params .
import streamlit as st
# Access query parameters
params = st.experimental_get_query_params()
test_value = params.get("test", ["default_value"])[0] # Query params are returned as lists
st.write("Test value:", test_value)
Let me know if you might require any further assistance!
This doesn’t seem right? The documentation claims it is an attribute directly on st, not on st.session_state. Also, when I try and access st.session_state.query_params, with a query param in the URL, I get an attribute error.
AttributeError: st.session_state has no attribute "query_params".
It appears an unrelated restart has resolved the issue and it’s all working as expected now! Unsure what was going on but since it’s working, all good.