streamlit-nightly 1.29.1.dev20240107__py2.py3-none-any.whl → 1.29.1.dev20240109__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -56,7 +56,7 @@ def stop() -> NoReturn: # type: ignore[misc]
56
56
  def rerun() -> NoReturn: # type: ignore[misc]
57
57
  """Rerun the script immediately.
58
58
 
59
- When `st.rerun()` is called, the script is halted - no more statements will
59
+ When ``st.rerun()`` is called, the script is halted - no more statements will
60
60
  be run, and the script will be queued to re-run from the top.
61
61
  """
62
62
 
@@ -80,7 +80,7 @@ def rerun() -> NoReturn: # type: ignore[misc]
80
80
  def experimental_rerun() -> NoReturn:
81
81
  """Rerun the script immediately.
82
82
 
83
- When `st.experimental_rerun()` is called, the script is halted - no
83
+ When ``st.experimental_rerun()`` is called, the script is halted - no
84
84
  more statements will be run, and the script will be queued to re-run
85
85
  from the top.
86
86
  """
@@ -94,13 +94,42 @@ def experimental_rerun() -> NoReturn:
94
94
 
95
95
  @gather_metrics("switch_page")
96
96
  def switch_page(page: str) -> NoReturn: # type: ignore[misc]
97
- """Switch the current programmatically page in a multi-page app.
98
- When `st.switch_page()` is called with a page, the current page script is halted
99
- and the requested page script will be queued to run from the top.
97
+ """Programmatically switch the current page in a multipage app.
98
+
99
+ When ``st.switch_page()`` is called, the current page execution stops and
100
+ the specified page runs as if the user clicked on it in the sidebar
101
+ navigation. The specified page must be recognized by Streamlit's multipage
102
+ architecture (your main Python file or a Python file in a ``pages/``
103
+ folder). Arbitrary Python scripts cannot be passed to ``st.switch_pages``.
104
+
100
105
  Parameters
101
106
  ----------
102
107
  page: str
103
- The file path, relative to the main script, of the page to switch to.
108
+ The file path (relative to the main script) of the page to switch to.
109
+
110
+ Example
111
+ -------
112
+ Consider the following example given this file structure:
113
+
114
+ >>> your-repository/
115
+ >>> ├── pages/
116
+ >>> │ ├── page_1.py.py
117
+ >>> │ └── page_2.py.py
118
+ >>> └── your_app.py
119
+
120
+ >>> import streamlit as st
121
+ >>>
122
+ >>> if st.button("Home"):
123
+ >>> st.switch_page("your_app.py")
124
+ >>> if st.button("Page 1"):
125
+ >>> st.switch_page("pages/page_1.py")
126
+ >>> if st.button("Page 2"):
127
+ >>> st.switch_page("pages/page_2.py")
128
+
129
+ .. output ::
130
+ https://doc-switch-page.streamlit.app/
131
+ height: 350px
132
+
104
133
  """
105
134
 
106
135
  ctx = get_script_run_ctx()
@@ -128,7 +157,7 @@ def switch_page(page: str) -> NoReturn: # type: ignore[misc]
128
157
 
129
158
  ctx.script_requests.request_rerun(
130
159
  RerunData(
131
- query_string="",
160
+ query_string=ctx.query_string,
132
161
  page_script_hash=matched_pages[0]["page_script_hash"],
133
162
  )
134
163
  )
@@ -16,15 +16,16 @@ import urllib.parse as parse
16
16
  from typing import Any, Dict, List, Union
17
17
 
18
18
  from streamlit import util
19
+ from streamlit.constants import (
20
+ EMBED_OPTIONS_QUERY_PARAM,
21
+ EMBED_QUERY_PARAM,
22
+ EMBED_QUERY_PARAMS_KEYS,
23
+ )
19
24
  from streamlit.errors import StreamlitAPIException
20
25
  from streamlit.proto.ForwardMsg_pb2 import ForwardMsg
21
26
  from streamlit.runtime.metrics_util import gather_metrics
22
27
  from streamlit.runtime.scriptrunner import get_script_run_ctx
23
28
 
24
- EMBED_QUERY_PARAM = "embed"
25
- EMBED_OPTIONS_QUERY_PARAM = "embed_options"
26
- EMBED_QUERY_PARAMS_KEYS = [EMBED_QUERY_PARAM, EMBED_OPTIONS_QUERY_PARAM]
27
-
28
29
 
29
30
  @gather_metrics("experimental_get_query_params")
30
31
  def get_query_params() -> Dict[str, List[str]]:
streamlit/constants.py ADDED
@@ -0,0 +1,17 @@
1
+ # Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024)
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ EMBED_QUERY_PARAM = "embed"
16
+ EMBED_OPTIONS_QUERY_PARAM = "embed_options"
17
+ EMBED_QUERY_PARAMS_KEYS = [EMBED_QUERY_PARAM, EMBED_OPTIONS_QUERY_PARAM]
@@ -93,7 +93,36 @@ class LayoutsMixin:
93
93
 
94
94
  .. output ::
95
95
  https://doc-container2.streamlit.app/
96
- height: 480px
96
+ height: 300px
97
+
98
+ Using ``height`` to make a grid:
99
+
100
+ >>> import streamlit as st
101
+ >>>
102
+ >>> row1 = st.columns(3)
103
+ >>> row2 = st.columns(3)
104
+ >>>
105
+ >>> for col in row1 + row2:
106
+ >>> tile = col.container(height=120, border=True)
107
+ >>> tile.title(":balloon:")
108
+
109
+ .. output ::
110
+ https://doc-container3.streamlit.app/
111
+ height: 350px
112
+
113
+ Using ``height`` to create a scrolling container for long content:
114
+
115
+ >>> import streamlit as st
116
+ >>>
117
+ >>> long_text = "Lorem ipsum. " * 1000
118
+ >>>
119
+ >>> with st.container(height=300):
120
+ >>> st.markdown(long_text)
121
+
122
+ .. output ::
123
+ https://doc-container4.streamlit.app/
124
+ height: 400px
125
+
97
126
  """
98
127
  block_proto = BlockProto()
99
128
  block_proto.allow_empty = False
@@ -98,7 +98,7 @@ class PlotlyMixin:
98
98
 
99
99
  Parameters
100
100
  ----------
101
- figure_or_data : plotly.graph_objs.Figure, plotly.graph_objs.Data,
101
+ figure_or_data : plotly.graph_objs.Figure, plotly.graph_objs.Data,\
102
102
  dict/list of plotly.graph_objs.Figure/Data
103
103
 
104
104
  See https://plot.ly/python/ for examples of graph descriptions.
@@ -303,8 +303,6 @@ class CacheResourceAPI:
303
303
  <https://docs.python.org/3/library/datetime.html#timedelta-objects>`_,
304
304
  e.g. ``timedelta(days=1)``.
305
305
 
306
- Note that ``ttl`` will be ignored if ``persist="disk"`` or ``persist=True``.
307
-
308
306
  max_entries : int or None
309
307
  The maximum number of entries to keep in the cache, or None
310
308
  for an unbounded cache. When a new entry is added to a full cache,
@@ -14,7 +14,9 @@
14
14
 
15
15
  from dataclasses import dataclass, field
16
16
  from typing import Dict, Iterable, Iterator, List, MutableMapping, Union
17
+ from urllib import parse
17
18
 
19
+ from streamlit.constants import EMBED_QUERY_PARAMS_KEYS
18
20
  from streamlit.errors import StreamlitAPIException
19
21
  from streamlit.proto.ForwardMsg_pb2 import ForwardMsg
20
22
 
@@ -29,7 +31,12 @@ class QueryParams(MutableMapping[str, str]):
29
31
 
30
32
  def __iter__(self) -> Iterator[str]:
31
33
  self._ensure_single_query_api_used()
32
- return iter(self._query_params.keys())
34
+
35
+ return iter(
36
+ key
37
+ for key in self._query_params.keys()
38
+ if key not in EMBED_QUERY_PARAMS_KEYS
39
+ )
33
40
 
34
41
  def __getitem__(self, key: str) -> str:
35
42
  """Retrieves a value for a given key in query parameters.
@@ -38,6 +45,8 @@ class QueryParams(MutableMapping[str, str]):
38
45
  """
39
46
  self._ensure_single_query_api_used()
40
47
  try:
48
+ if key in EMBED_QUERY_PARAMS_KEYS:
49
+ raise KeyError(missing_key_error_message(key))
41
50
  value = self._query_params[key]
42
51
  if isinstance(value, list):
43
52
  if len(value) == 0:
@@ -56,6 +65,10 @@ class QueryParams(MutableMapping[str, str]):
56
65
  f"You cannot set a query params key `{key}` to a dictionary."
57
66
  )
58
67
 
68
+ if key in EMBED_QUERY_PARAMS_KEYS:
69
+ raise StreamlitAPIException(
70
+ "Query param embed and embed_options (case-insensitive) cannot be set programmatically."
71
+ )
59
72
  # Type checking users should handle the string serialization themselves
60
73
  # We will accept any type for the list and serialize to str just in case
61
74
  if isinstance(value, Iterable) and not isinstance(value, str):
@@ -66,6 +79,8 @@ class QueryParams(MutableMapping[str, str]):
66
79
 
67
80
  def __delitem__(self, key: str) -> None:
68
81
  try:
82
+ if key in EMBED_QUERY_PARAMS_KEYS:
83
+ raise KeyError(missing_key_error_message(key))
69
84
  del self._query_params[key]
70
85
  self._send_query_param_msg()
71
86
  except KeyError:
@@ -73,18 +88,19 @@ class QueryParams(MutableMapping[str, str]):
73
88
 
74
89
  def get_all(self, key: str) -> List[str]:
75
90
  self._ensure_single_query_api_used()
76
- if key not in self._query_params:
91
+ if key not in self._query_params or key in EMBED_QUERY_PARAMS_KEYS:
77
92
  return []
78
93
  value = self._query_params[key]
79
94
  return value if isinstance(value, list) else [value]
80
95
 
81
96
  def __len__(self) -> int:
82
97
  self._ensure_single_query_api_used()
83
- return len(self._query_params)
98
+ return len(
99
+ {key for key in self._query_params if key not in EMBED_QUERY_PARAMS_KEYS}
100
+ )
84
101
 
85
102
  def _send_query_param_msg(self) -> None:
86
103
  # Avoid circular imports
87
- from streamlit.commands.experimental_query_params import _ensure_no_embed_params
88
104
  from streamlit.runtime.scriptrunner import get_script_run_ctx
89
105
 
90
106
  ctx = get_script_run_ctx()
@@ -93,27 +109,31 @@ class QueryParams(MutableMapping[str, str]):
93
109
  self._ensure_single_query_api_used()
94
110
 
95
111
  msg = ForwardMsg()
96
- msg.page_info_changed.query_string = _ensure_no_embed_params(
97
- self._query_params, ctx.query_string
112
+ msg.page_info_changed.query_string = parse.urlencode(
113
+ self._query_params, doseq=True
98
114
  )
99
115
  ctx.query_string = msg.page_info_changed.query_string
100
116
  ctx.enqueue(msg)
101
117
 
102
118
  def clear(self) -> None:
103
- self._query_params.clear()
119
+ new_query_params = {}
120
+ for key, value in self._query_params.items():
121
+ if key in EMBED_QUERY_PARAMS_KEYS:
122
+ new_query_params[key] = value
123
+ self._query_params = new_query_params
124
+
104
125
  self._send_query_param_msg()
105
126
 
106
127
  def to_dict(self) -> Dict[str, str]:
107
128
  self._ensure_single_query_api_used()
108
- # return the last query param if multiple keys are set
109
- return {key: self[key] for key in self._query_params}
129
+ # return the last query param if multiple values are set
130
+ return {
131
+ key: self[key]
132
+ for key in self._query_params
133
+ if key not in EMBED_QUERY_PARAMS_KEYS
134
+ }
110
135
 
111
136
  def set_with_no_forward_msg(self, key: str, val: Union[List[str], str]) -> None:
112
- # Avoid circular imports
113
- from streamlit.commands.experimental_query_params import EMBED_QUERY_PARAMS_KEYS
114
-
115
- if key.lower() in EMBED_QUERY_PARAMS_KEYS:
116
- return
117
137
  self._query_params[key] = val
118
138
 
119
139
  def clear_with_no_forward_msg(self) -> None:
@@ -20,7 +20,8 @@ from streamlit.runtime.state.session_state_proxy import get_session_state
20
20
 
21
21
 
22
22
  class QueryParamsProxy(MutableMapping[str, str]):
23
- """A stateless singleton that proxies `st.query_params` interactions
23
+ """
24
+ A stateless singleton that proxies ``st.query_params`` interactions
24
25
  to the current script thread's QueryParams instance.
25
26
  """
26
27
 
@@ -68,15 +69,51 @@ class QueryParamsProxy(MutableMapping[str, str]):
68
69
 
69
70
  @gather_metrics("query_params.get_all")
70
71
  def get_all(self, key: str) -> List[str]:
72
+ """
73
+ Get a list of all query parameter values associated to a given key.
74
+
75
+ When a key is repeated as a query parameter within the URL, this method
76
+ allows all values to be obtained. In contrast, dict-like methods only
77
+ retrieve the last value when a key is repeated in the URL.
78
+
79
+ Parameters
80
+ ----------
81
+ key: str
82
+ The label of the query parameter in the URL.
83
+
84
+ Returns
85
+ -------
86
+ List[str]
87
+ A list of values associated to the given key. May return zero, one,
88
+ or multiple values.
89
+ """
71
90
  with get_session_state().query_params() as qp:
72
91
  return qp.get_all(key)
73
92
 
74
93
  @gather_metrics("query_params.clear")
75
94
  def clear(self) -> None:
95
+ """
96
+ Clear all query parameters from the URL of the app.
97
+
98
+ Returns
99
+ -------
100
+ None
101
+ """
76
102
  with get_session_state().query_params() as qp:
77
103
  qp.clear()
78
104
 
79
105
  @gather_metrics("query_params.to_dict")
80
106
  def to_dict(self) -> Dict[str, str]:
107
+ """
108
+ Get all query parameters as a dictionary.
109
+
110
+ When a key is repeated as a query parameter within the URL, this method
111
+ will return only the last value of each unique key.
112
+
113
+ Returns
114
+ -------
115
+ Dict[str,str]
116
+ A dictionary of the current query paramters in the app's URL.
117
+ """
81
118
  with get_session_state().query_params() as qp:
82
119
  return qp.to_dict()
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "files": {
3
3
  "main.css": "./static/css/main.77d1c464.css",
4
- "main.js": "./static/js/main.cbbf0bd5.js",
4
+ "main.js": "./static/js/main.3ab8e8d9.js",
5
5
  "static/js/9336.2d95d840.chunk.js": "./static/js/9336.2d95d840.chunk.js",
6
6
  "static/js/9330.c0dd1723.chunk.js": "./static/js/9330.c0dd1723.chunk.js",
7
7
  "static/js/7217.d970c074.chunk.js": "./static/js/7217.d970c074.chunk.js",
@@ -149,6 +149,6 @@
149
149
  },
150
150
  "entrypoints": [
151
151
  "static/css/main.77d1c464.css",
152
- "static/js/main.cbbf0bd5.js"
152
+ "static/js/main.3ab8e8d9.js"
153
153
  ]
154
154
  }
@@ -1 +1 @@
1
- <!doctype html><html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><link rel="shortcut icon" href="./favicon.png"/><link rel="preload" href="./static/media/SourceSansPro-Regular.0d69e5ff5e92ac64a0c9.woff2" as="font" type="font/woff2" crossorigin><link rel="preload" href="./static/media/SourceSansPro-SemiBold.abed79cd0df1827e18cf.woff2" as="font" type="font/woff2" crossorigin><link rel="preload" href="./static/media/SourceSansPro-Bold.118dea98980e20a81ced.woff2" as="font" type="font/woff2" crossorigin><title>Streamlit</title><script>window.prerenderReady=!1</script><script defer="defer" src="./static/js/main.cbbf0bd5.js"></script><link href="./static/css/main.77d1c464.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
1
+ <!doctype html><html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><link rel="shortcut icon" href="./favicon.png"/><link rel="preload" href="./static/media/SourceSansPro-Regular.0d69e5ff5e92ac64a0c9.woff2" as="font" type="font/woff2" crossorigin><link rel="preload" href="./static/media/SourceSansPro-SemiBold.abed79cd0df1827e18cf.woff2" as="font" type="font/woff2" crossorigin><link rel="preload" href="./static/media/SourceSansPro-Bold.118dea98980e20a81ced.woff2" as="font" type="font/woff2" crossorigin><title>Streamlit</title><script>window.prerenderReady=!1</script><script defer="defer" src="./static/js/main.3ab8e8d9.js"></script><link href="./static/css/main.77d1c464.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>