New st.query_params doesn't work?

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()

does not set the query param

import streamlit as st

st.experimental_set_query_params(test=1)
st.write("Done")
st.stop()

still does

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.

What am I missing?

Hello @ksyme99,

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!

Kind Regards,
Sahir

P.S. Lets connect on LinkedIn!

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.

@ksyme99, Great to hear all is working fine!

If you have any more questions, feel free to let me know :slight_smile: