New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Coming soon: API update for Streamlit query params #7665
Comments
Looks awesome 👍 The only thing I dislike about the query params API is that the embed query options are hidden and not sure what's the benefit of that. Is the plan to keep it that way? streamlit/lib/streamlit/commands/query_params.py Lines 59 to 63 in f61c53b
|
Thanks @edsaac! We have the I'm curious if you had a specific use case in mind for this? Current plan of record is to keep the embed options hidden with the new API, but interested to hear if there's a reason to do something different. Thanks! |
Thanks @sfc-gh-jcarroll for the proposal! I think it makes sense to make query params API more consistent with
# Read
st.session_state |= st.query_params
# ...
# All my app, with explicit `key`s defined when needed
# ...
# Write
st.query_params |= st.session_state An extreme case could be something like |
Thanks @arnaudmiribel !
|
Thanks for the context. Makes sense! As for the feature request, I would guess the closest is that one #302. |
@sfc-gh-jcarroll my use case for checking if the app is embed is just to show a simpler layout. For example, if embed it won't render In case someone finds that useful, this is how I check if the app is embed. Ofc it will need to be updated after the new better API rolls out. def is_embed():
from streamlit.runtime.scriptrunner import get_script_run_ctx
ctx = get_script_run_ctx()
query_params = parse.parse_qs(ctx.query_string)
return True if query_params.get("embed") else False
IS_APP_EMBED = is_embed() |
Nice, thanks @edsaac - Cool scenario and it makes sense. Based on your feedback we talked about it and |
Hey @edsaac sorry for the bait and switch - after thinking about this some more, I think it's preferable to keep the current hiding of embed params. One specific use case in mind is if an app wants to do some I think the use case is totally legit. Wondering about exposing another simple function for this, maybe some |
That would be great! It's basically what I currently do with that small |
Hi all! I just left a comment on one of the pull requests, but I would also like to suggest it here so it may be discussed: Could we mimick accessing query params the way Flask decided to do it, with a I'm currently already using the |
Thanks @bartbroere, I think we have it covered with the # URL: localhost:8501/?show_map=True&selected=asia&selected=america
st.query_params.get_all("selected")
# ["asia", "america"]
st.query_params.get_all("show_map")
# ["True"] |
This feature has been merged #7774 and will be included in the next Streamlit release, 1.30 🙌 |
Hi all, an FYI that we’re working on an upgrade to Streamlit’s query params API. I’m sharing about it today to get feedback on the new API and help assess whether to release it as
experimental_
or go directly to a stable API. Take a look and let us know what you think!Current state
Query params support is a fairly popular feature for providing some state or input about an app as part of the URL, making it easier to share with users or collaborators in a given state. Today it’s supported in Streamlit with two methods, experimental_get_query_params and experimental_set_query_params.
Both methods treat the query params as a single blob and require the app developer to track and manage the state (in case of multiple params) and handle list conversion.
Planned API update
Our plan is to move query params to a dict-like API similar to
st.session_state
, where Streamlit tracks the state of all query params and app developers can interact with them independently. For query params with only a single value, this also means the developer doesn’t need to worry about list conversion.Handling lists and multiple values
A key concern for query parameters is handling multiple values. For normal get / retrieval calls on
query_params
, Streamlit will return only the last value set for the given key, whether in the URL directly via Streamlit API. To retrieve a list of all set values, developers can callst.query_params.get_all(key)
. This approach is typical of several other python web API frameworks such as tornado and flask.Other improvements
We’ll also be making a few quality improvements to the existing support and making sure less common cases like setting an empty string / blank value are supported.
What do you think?
Let us know your feedback about the changes. Our current plan is to release this minimal version, which simplifies the API for typical use cases and leaves room to extend to new features in the future such as better handling for type conversion, or binding query params to certain session_state keys or widget values.
Your input can help impact whether we release this immediately as
st.query_params
or do anst.experimental_query_params
to see more usage of the new API before finalizing it.Thank you!
The text was updated successfully, but these errors were encountered: