# Source: https://docs.streamlit.io/develop/api-reference/caching-and-state/st.query_params

# st.query_params

`st.query_params` provides a dictionary-like interface to access query parameters in your app's URL and is available as of Streamlit 1.30.0. It behaves similarly to `st.session_state` with the notable exception that keys may be repeated in an app's URL. Handling of repeated keys requires special consideration as explained below.

`st.query_params` can be used with both key and attribute notation. For example, `st.query_params.my_key` and `st.query_params[“my_key”]`. All keys and values will be set and returned as strings. When you write to `st.query_params`, key-value pair prefixed with `?` is added to the end of your app's URL. Each additional pair is prefixed with `&` instead of `?`. Query parameters are cleared when navigating between pages in a multipage app.

For example, consider the following URL:

```
https://your_app.streamlit.app/?first_key=1&second_key=two&third_key=true
```

The parameters in the URL above will be accessible in `st.query_params` as:

```python
{
    "first_key" : "1",
    "second_key" : "two",
    "third_key" : "true"
}
```

This means you can use those parameters in your app like this:

```python
# You can read query params using key notation
if st.query_params["first_key"] == "1":
    do_something()

# ...or using attribute notation
if st.query_params.second_key == "two":
    do_something_else()

# And you can change a param by just writing to it
st.query_params.first_key = 2  # This gets converted to str automatically
```

## `st.query_params.clear`

Clear all query parameters from the URL of the app.

```python
import streamlit as st

st.query_params.clear()
```

## `st.query_params.from_dict`

Set all of the query parameters from a dictionary or dictionary-like object.

This method primarily exists for advanced users who want to control multiple query parameters in a single update. To set individual query parameters, use key or attribute notation instead.

This method inherits limitations from `st.query_params` and can't be used to set embedding options as described in [Embed your app](https://docs.streamlit.io/deploy/streamlit-community-cloud/share-your-app/embed-your-app#embed-options).

To handle repeated keys, the value in a key-value pair should be a list.

```python
from st import st

st.query_params.from_dict({"foo": "bar", "baz": [1, "two"]})
```

## `st.query_params.get_all`

Get a list of all query parameter values associated to a given key.

When a key is repeated as a query parameter within the URL, this method allows all values to be obtained. In contrast, dict-like methods only retrieve the last value when a key is repeated in the URL.

```python
import st

st.query_params.get_all("key")
```

## `st.query_params.to_dict`

Get all query parameters as a dictionary.

This method primarily exists for internal use and is not needed for most cases. `st.query_params` returns an object that inherits from `dict` by default.

When a key is repeated as a query parameter within the URL, this method will return only the last value of each unique key.

```python
import st

st.query_params.to_dict()
```