streamlit-nightly 1.43.2.dev20250307__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.
- streamlit/__init__.py +306 -0
- streamlit/__main__.py +20 -0
- streamlit/auth_util.py +218 -0
- streamlit/cli_util.py +105 -0
- streamlit/column_config.py +56 -0
- streamlit/commands/__init__.py +13 -0
- streamlit/commands/echo.py +126 -0
- streamlit/commands/execution_control.py +238 -0
- streamlit/commands/experimental_query_params.py +169 -0
- streamlit/commands/logo.py +189 -0
- streamlit/commands/navigation.py +385 -0
- streamlit/commands/page_config.py +311 -0
- streamlit/components/__init__.py +13 -0
- streamlit/components/lib/__init__.py +13 -0
- streamlit/components/lib/local_component_registry.py +84 -0
- streamlit/components/types/__init__.py +13 -0
- streamlit/components/types/base_component_registry.py +99 -0
- streamlit/components/types/base_custom_component.py +150 -0
- streamlit/components/v1/__init__.py +31 -0
- streamlit/components/v1/component_arrow.py +141 -0
- streamlit/components/v1/component_registry.py +130 -0
- streamlit/components/v1/components.py +38 -0
- streamlit/components/v1/custom_component.py +243 -0
- streamlit/config.py +1513 -0
- streamlit/config_option.py +311 -0
- streamlit/config_util.py +177 -0
- streamlit/connections/__init__.py +28 -0
- streamlit/connections/base_connection.py +174 -0
- streamlit/connections/snowflake_connection.py +562 -0
- streamlit/connections/snowpark_connection.py +213 -0
- streamlit/connections/sql_connection.py +425 -0
- streamlit/connections/util.py +97 -0
- streamlit/cursor.py +210 -0
- streamlit/dataframe_util.py +1416 -0
- streamlit/delta_generator.py +602 -0
- streamlit/delta_generator_singletons.py +204 -0
- streamlit/deprecation_util.py +209 -0
- streamlit/development.py +21 -0
- streamlit/elements/__init__.py +13 -0
- streamlit/elements/alert.py +234 -0
- streamlit/elements/arrow.py +962 -0
- streamlit/elements/balloons.py +47 -0
- streamlit/elements/bokeh_chart.py +133 -0
- streamlit/elements/code.py +114 -0
- streamlit/elements/deck_gl_json_chart.py +546 -0
- streamlit/elements/dialog_decorator.py +267 -0
- streamlit/elements/doc_string.py +558 -0
- streamlit/elements/empty.py +130 -0
- streamlit/elements/exception.py +331 -0
- streamlit/elements/form.py +354 -0
- streamlit/elements/graphviz_chart.py +150 -0
- streamlit/elements/heading.py +302 -0
- streamlit/elements/html.py +105 -0
- streamlit/elements/iframe.py +191 -0
- streamlit/elements/image.py +196 -0
- streamlit/elements/json.py +139 -0
- streamlit/elements/layouts.py +879 -0
- streamlit/elements/lib/__init__.py +13 -0
- streamlit/elements/lib/built_in_chart_utils.py +1157 -0
- streamlit/elements/lib/color_util.py +263 -0
- streamlit/elements/lib/column_config_utils.py +542 -0
- streamlit/elements/lib/column_types.py +2188 -0
- streamlit/elements/lib/dialog.py +147 -0
- streamlit/elements/lib/dicttools.py +154 -0
- streamlit/elements/lib/event_utils.py +37 -0
- streamlit/elements/lib/file_uploader_utils.py +66 -0
- streamlit/elements/lib/form_utils.py +77 -0
- streamlit/elements/lib/image_utils.py +441 -0
- streamlit/elements/lib/js_number.py +105 -0
- streamlit/elements/lib/mutable_status_container.py +183 -0
- streamlit/elements/lib/options_selector_utils.py +250 -0
- streamlit/elements/lib/pandas_styler_utils.py +274 -0
- streamlit/elements/lib/policies.py +194 -0
- streamlit/elements/lib/streamlit_plotly_theme.py +207 -0
- streamlit/elements/lib/subtitle_utils.py +176 -0
- streamlit/elements/lib/utils.py +250 -0
- streamlit/elements/map.py +508 -0
- streamlit/elements/markdown.py +277 -0
- streamlit/elements/media.py +793 -0
- streamlit/elements/metric.py +301 -0
- streamlit/elements/plotly_chart.py +546 -0
- streamlit/elements/progress.py +156 -0
- streamlit/elements/pyplot.py +194 -0
- streamlit/elements/snow.py +47 -0
- streamlit/elements/spinner.py +113 -0
- streamlit/elements/text.py +76 -0
- streamlit/elements/toast.py +98 -0
- streamlit/elements/vega_charts.py +1984 -0
- streamlit/elements/widgets/__init__.py +13 -0
- streamlit/elements/widgets/audio_input.py +310 -0
- streamlit/elements/widgets/button.py +1123 -0
- streamlit/elements/widgets/button_group.py +1008 -0
- streamlit/elements/widgets/camera_input.py +263 -0
- streamlit/elements/widgets/chat.py +647 -0
- streamlit/elements/widgets/checkbox.py +352 -0
- streamlit/elements/widgets/color_picker.py +265 -0
- streamlit/elements/widgets/data_editor.py +983 -0
- streamlit/elements/widgets/file_uploader.py +486 -0
- streamlit/elements/widgets/multiselect.py +338 -0
- streamlit/elements/widgets/number_input.py +545 -0
- streamlit/elements/widgets/radio.py +407 -0
- streamlit/elements/widgets/select_slider.py +437 -0
- streamlit/elements/widgets/selectbox.py +366 -0
- streamlit/elements/widgets/slider.py +880 -0
- streamlit/elements/widgets/text_widgets.py +628 -0
- streamlit/elements/widgets/time_widgets.py +970 -0
- streamlit/elements/write.py +574 -0
- streamlit/emojis.py +34 -0
- streamlit/env_util.py +61 -0
- streamlit/error_util.py +105 -0
- streamlit/errors.py +452 -0
- streamlit/external/__init__.py +13 -0
- streamlit/external/langchain/__init__.py +23 -0
- streamlit/external/langchain/streamlit_callback_handler.py +406 -0
- streamlit/file_util.py +247 -0
- streamlit/git_util.py +173 -0
- streamlit/hello/__init__.py +13 -0
- streamlit/hello/animation_demo.py +82 -0
- streamlit/hello/dataframe_demo.py +71 -0
- streamlit/hello/hello.py +37 -0
- streamlit/hello/mapping_demo.py +114 -0
- streamlit/hello/plotting_demo.py +55 -0
- streamlit/hello/streamlit_app.py +55 -0
- streamlit/hello/utils.py +28 -0
- streamlit/logger.py +130 -0
- streamlit/material_icon_names.py +25 -0
- streamlit/navigation/__init__.py +13 -0
- streamlit/navigation/page.py +302 -0
- streamlit/net_util.py +125 -0
- streamlit/platform.py +33 -0
- streamlit/proto/Alert_pb2.py +29 -0
- streamlit/proto/Alert_pb2.pyi +90 -0
- streamlit/proto/AppPage_pb2.py +27 -0
- streamlit/proto/AppPage_pb2.pyi +64 -0
- streamlit/proto/ArrowNamedDataSet_pb2.py +28 -0
- streamlit/proto/ArrowNamedDataSet_pb2.pyi +57 -0
- streamlit/proto/ArrowVegaLiteChart_pb2.py +29 -0
- streamlit/proto/ArrowVegaLiteChart_pb2.pyi +84 -0
- streamlit/proto/Arrow_pb2.py +33 -0
- streamlit/proto/Arrow_pb2.pyi +188 -0
- streamlit/proto/AudioInput_pb2.py +28 -0
- streamlit/proto/AudioInput_pb2.pyi +58 -0
- streamlit/proto/Audio_pb2.py +27 -0
- streamlit/proto/Audio_pb2.pyi +58 -0
- streamlit/proto/AuthRedirect_pb2.py +27 -0
- streamlit/proto/AuthRedirect_pb2.pyi +41 -0
- streamlit/proto/AutoRerun_pb2.py +27 -0
- streamlit/proto/AutoRerun_pb2.pyi +45 -0
- streamlit/proto/BackMsg_pb2.py +29 -0
- streamlit/proto/BackMsg_pb2.pyi +105 -0
- streamlit/proto/Balloons_pb2.py +27 -0
- streamlit/proto/Balloons_pb2.pyi +43 -0
- streamlit/proto/Block_pb2.py +53 -0
- streamlit/proto/Block_pb2.pyi +322 -0
- streamlit/proto/BokehChart_pb2.py +27 -0
- streamlit/proto/BokehChart_pb2.pyi +49 -0
- streamlit/proto/ButtonGroup_pb2.py +36 -0
- streamlit/proto/ButtonGroup_pb2.pyi +169 -0
- streamlit/proto/Button_pb2.py +27 -0
- streamlit/proto/Button_pb2.pyi +71 -0
- streamlit/proto/CameraInput_pb2.py +28 -0
- streamlit/proto/CameraInput_pb2.pyi +58 -0
- streamlit/proto/ChatInput_pb2.py +31 -0
- streamlit/proto/ChatInput_pb2.pyi +111 -0
- streamlit/proto/Checkbox_pb2.py +30 -0
- streamlit/proto/Checkbox_pb2.pyi +90 -0
- streamlit/proto/ClientState_pb2.py +30 -0
- streamlit/proto/ClientState_pb2.pyi +90 -0
- streamlit/proto/Code_pb2.py +27 -0
- streamlit/proto/Code_pb2.pyi +55 -0
- streamlit/proto/ColorPicker_pb2.py +28 -0
- streamlit/proto/ColorPicker_pb2.pyi +67 -0
- streamlit/proto/Common_pb2.py +51 -0
- streamlit/proto/Common_pb2.pyi +293 -0
- streamlit/proto/Components_pb2.py +35 -0
- streamlit/proto/Components_pb2.pyi +172 -0
- streamlit/proto/DataFrame_pb2.py +56 -0
- streamlit/proto/DataFrame_pb2.pyi +397 -0
- streamlit/proto/DateInput_pb2.py +28 -0
- streamlit/proto/DateInput_pb2.pyi +83 -0
- streamlit/proto/DeckGlJsonChart_pb2.py +29 -0
- streamlit/proto/DeckGlJsonChart_pb2.pyi +102 -0
- streamlit/proto/Delta_pb2.py +31 -0
- streamlit/proto/Delta_pb2.pyi +74 -0
- streamlit/proto/DocString_pb2.py +29 -0
- streamlit/proto/DocString_pb2.pyi +93 -0
- streamlit/proto/DownloadButton_pb2.py +27 -0
- streamlit/proto/DownloadButton_pb2.pyi +70 -0
- streamlit/proto/Element_pb2.py +78 -0
- streamlit/proto/Element_pb2.pyi +312 -0
- streamlit/proto/Empty_pb2.py +27 -0
- streamlit/proto/Empty_pb2.pyi +36 -0
- streamlit/proto/Exception_pb2.py +27 -0
- streamlit/proto/Exception_pb2.pyi +72 -0
- streamlit/proto/Favicon_pb2.py +27 -0
- streamlit/proto/Favicon_pb2.pyi +40 -0
- streamlit/proto/FileUploader_pb2.py +28 -0
- streamlit/proto/FileUploader_pb2.pyi +78 -0
- streamlit/proto/ForwardMsg_pb2.py +53 -0
- streamlit/proto/ForwardMsg_pb2.pyi +293 -0
- streamlit/proto/GitInfo_pb2.py +29 -0
- streamlit/proto/GitInfo_pb2.pyi +83 -0
- streamlit/proto/GraphVizChart_pb2.py +27 -0
- streamlit/proto/GraphVizChart_pb2.pyi +53 -0
- streamlit/proto/Heading_pb2.py +27 -0
- streamlit/proto/Heading_pb2.pyi +56 -0
- streamlit/proto/Html_pb2.py +27 -0
- streamlit/proto/Html_pb2.pyi +42 -0
- streamlit/proto/IFrame_pb2.py +27 -0
- streamlit/proto/IFrame_pb2.pyi +59 -0
- streamlit/proto/Image_pb2.py +29 -0
- streamlit/proto/Image_pb2.pyi +84 -0
- streamlit/proto/Json_pb2.py +27 -0
- streamlit/proto/Json_pb2.pyi +53 -0
- streamlit/proto/LabelVisibilityMessage_pb2.py +29 -0
- streamlit/proto/LabelVisibilityMessage_pb2.pyi +68 -0
- streamlit/proto/LinkButton_pb2.py +27 -0
- streamlit/proto/LinkButton_pb2.pyi +58 -0
- streamlit/proto/Logo_pb2.py +27 -0
- streamlit/proto/Logo_pb2.pyi +51 -0
- streamlit/proto/Markdown_pb2.py +29 -0
- streamlit/proto/Markdown_pb2.pyi +86 -0
- streamlit/proto/Metric_pb2.py +32 -0
- streamlit/proto/Metric_pb2.pyi +101 -0
- streamlit/proto/MetricsEvent_pb2.py +30 -0
- streamlit/proto/MetricsEvent_pb2.pyi +200 -0
- streamlit/proto/MultiSelect_pb2.py +28 -0
- streamlit/proto/MultiSelect_pb2.pyi +81 -0
- streamlit/proto/NamedDataSet_pb2.py +28 -0
- streamlit/proto/NamedDataSet_pb2.pyi +59 -0
- streamlit/proto/Navigation_pb2.py +30 -0
- streamlit/proto/Navigation_pb2.pyi +84 -0
- streamlit/proto/NewSession_pb2.py +51 -0
- streamlit/proto/NewSession_pb2.pyi +481 -0
- streamlit/proto/NumberInput_pb2.py +30 -0
- streamlit/proto/NumberInput_pb2.pyi +121 -0
- streamlit/proto/PageConfig_pb2.py +33 -0
- streamlit/proto/PageConfig_pb2.pyi +126 -0
- streamlit/proto/PageInfo_pb2.py +27 -0
- streamlit/proto/PageInfo_pb2.pyi +43 -0
- streamlit/proto/PageLink_pb2.py +27 -0
- streamlit/proto/PageLink_pb2.pyi +63 -0
- streamlit/proto/PageNotFound_pb2.py +27 -0
- streamlit/proto/PageNotFound_pb2.pyi +42 -0
- streamlit/proto/PageProfile_pb2.py +31 -0
- streamlit/proto/PageProfile_pb2.pyi +127 -0
- streamlit/proto/PagesChanged_pb2.py +28 -0
- streamlit/proto/PagesChanged_pb2.pyi +48 -0
- streamlit/proto/ParentMessage_pb2.py +27 -0
- streamlit/proto/ParentMessage_pb2.pyi +46 -0
- streamlit/proto/PlotlyChart_pb2.py +31 -0
- streamlit/proto/PlotlyChart_pb2.pyi +131 -0
- streamlit/proto/Progress_pb2.py +27 -0
- streamlit/proto/Progress_pb2.pyi +43 -0
- streamlit/proto/Radio_pb2.py +28 -0
- streamlit/proto/Radio_pb2.pyi +84 -0
- streamlit/proto/RootContainer_pb2.py +27 -0
- streamlit/proto/RootContainer_pb2.pyi +56 -0
- streamlit/proto/Selectbox_pb2.py +28 -0
- streamlit/proto/Selectbox_pb2.pyi +80 -0
- streamlit/proto/SessionEvent_pb2.py +28 -0
- streamlit/proto/SessionEvent_pb2.pyi +62 -0
- streamlit/proto/SessionStatus_pb2.py +27 -0
- streamlit/proto/SessionStatus_pb2.pyi +57 -0
- streamlit/proto/Skeleton_pb2.py +29 -0
- streamlit/proto/Skeleton_pb2.pyi +71 -0
- streamlit/proto/Slider_pb2.py +32 -0
- streamlit/proto/Slider_pb2.pyi +142 -0
- streamlit/proto/Snow_pb2.py +27 -0
- streamlit/proto/Snow_pb2.pyi +43 -0
- streamlit/proto/Spinner_pb2.py +27 -0
- streamlit/proto/Spinner_pb2.pyi +49 -0
- streamlit/proto/TextArea_pb2.py +28 -0
- streamlit/proto/TextArea_pb2.pyi +80 -0
- streamlit/proto/TextInput_pb2.py +30 -0
- streamlit/proto/TextInput_pb2.pyi +107 -0
- streamlit/proto/Text_pb2.py +27 -0
- streamlit/proto/Text_pb2.pyi +46 -0
- streamlit/proto/TimeInput_pb2.py +28 -0
- streamlit/proto/TimeInput_pb2.pyi +74 -0
- streamlit/proto/Toast_pb2.py +27 -0
- streamlit/proto/Toast_pb2.pyi +45 -0
- streamlit/proto/VegaLiteChart_pb2.py +29 -0
- streamlit/proto/VegaLiteChart_pb2.pyi +71 -0
- streamlit/proto/Video_pb2.py +31 -0
- streamlit/proto/Video_pb2.pyi +117 -0
- streamlit/proto/WidgetStates_pb2.py +31 -0
- streamlit/proto/WidgetStates_pb2.pyi +126 -0
- streamlit/proto/__init__.py +15 -0
- streamlit/proto/openmetrics_data_model_pb2.py +60 -0
- streamlit/proto/openmetrics_data_model_pb2.pyi +522 -0
- streamlit/py.typed +0 -0
- streamlit/runtime/__init__.py +50 -0
- streamlit/runtime/app_session.py +982 -0
- streamlit/runtime/caching/__init__.py +98 -0
- streamlit/runtime/caching/cache_data_api.py +665 -0
- streamlit/runtime/caching/cache_errors.py +142 -0
- streamlit/runtime/caching/cache_resource_api.py +527 -0
- streamlit/runtime/caching/cache_type.py +33 -0
- streamlit/runtime/caching/cache_utils.py +523 -0
- streamlit/runtime/caching/cached_message_replay.py +290 -0
- streamlit/runtime/caching/hashing.py +637 -0
- streamlit/runtime/caching/legacy_cache_api.py +169 -0
- streamlit/runtime/caching/storage/__init__.py +29 -0
- streamlit/runtime/caching/storage/cache_storage_protocol.py +239 -0
- streamlit/runtime/caching/storage/dummy_cache_storage.py +60 -0
- streamlit/runtime/caching/storage/in_memory_cache_storage_wrapper.py +145 -0
- streamlit/runtime/caching/storage/local_disk_cache_storage.py +223 -0
- streamlit/runtime/connection_factory.py +436 -0
- streamlit/runtime/context.py +280 -0
- streamlit/runtime/credentials.py +364 -0
- streamlit/runtime/forward_msg_cache.py +296 -0
- streamlit/runtime/forward_msg_queue.py +240 -0
- streamlit/runtime/fragment.py +477 -0
- streamlit/runtime/media_file_manager.py +234 -0
- streamlit/runtime/media_file_storage.py +143 -0
- streamlit/runtime/memory_media_file_storage.py +181 -0
- streamlit/runtime/memory_session_storage.py +77 -0
- streamlit/runtime/memory_uploaded_file_manager.py +138 -0
- streamlit/runtime/metrics_util.py +486 -0
- streamlit/runtime/pages_manager.py +165 -0
- streamlit/runtime/runtime.py +792 -0
- streamlit/runtime/runtime_util.py +106 -0
- streamlit/runtime/script_data.py +46 -0
- streamlit/runtime/scriptrunner/__init__.py +38 -0
- streamlit/runtime/scriptrunner/exec_code.py +159 -0
- streamlit/runtime/scriptrunner/magic.py +273 -0
- streamlit/runtime/scriptrunner/magic_funcs.py +32 -0
- streamlit/runtime/scriptrunner/script_cache.py +89 -0
- streamlit/runtime/scriptrunner/script_runner.py +756 -0
- streamlit/runtime/scriptrunner_utils/__init__.py +19 -0
- streamlit/runtime/scriptrunner_utils/exceptions.py +48 -0
- streamlit/runtime/scriptrunner_utils/script_requests.py +307 -0
- streamlit/runtime/scriptrunner_utils/script_run_context.py +287 -0
- streamlit/runtime/secrets.py +534 -0
- streamlit/runtime/session_manager.py +394 -0
- streamlit/runtime/state/__init__.py +41 -0
- streamlit/runtime/state/common.py +191 -0
- streamlit/runtime/state/query_params.py +205 -0
- streamlit/runtime/state/query_params_proxy.py +218 -0
- streamlit/runtime/state/safe_session_state.py +138 -0
- streamlit/runtime/state/session_state.py +772 -0
- streamlit/runtime/state/session_state_proxy.py +153 -0
- streamlit/runtime/state/widgets.py +135 -0
- streamlit/runtime/stats.py +109 -0
- streamlit/runtime/uploaded_file_manager.py +148 -0
- streamlit/runtime/websocket_session_manager.py +167 -0
- streamlit/source_util.py +98 -0
- streamlit/static/favicon.png +0 -0
- streamlit/static/index.html +61 -0
- streamlit/static/static/css/index.Bmkmz40k.css +1 -0
- streamlit/static/static/css/index.DpJG_94W.css +1 -0
- streamlit/static/static/css/index.DzuxGC_t.css +1 -0
- streamlit/static/static/js/FileDownload.esm.Bp9m5jrx.js +1 -0
- streamlit/static/static/js/FileHelper.D_3pbilj.js +5 -0
- streamlit/static/static/js/FormClearHelper.Ct2rwLXo.js +1 -0
- streamlit/static/static/js/Hooks.BKdzj5MJ.js +1 -0
- streamlit/static/static/js/InputInstructions.DB3QGNJP.js +1 -0
- streamlit/static/static/js/ProgressBar.D40A5xc2.js +2 -0
- streamlit/static/static/js/RenderInPortalIfExists.DLUCooTN.js +1 -0
- streamlit/static/static/js/Toolbar.BiGGIQun.js +1 -0
- streamlit/static/static/js/UploadFileInfo.C-jY39rj.js +1 -0
- streamlit/static/static/js/base-input.CQBQT24M.js +4 -0
- streamlit/static/static/js/checkbox.Buj8gd_M.js +9 -0
- streamlit/static/static/js/createDownloadLinkElement.DZMwyjvU.js +1 -0
- streamlit/static/static/js/createSuper.CesK3I23.js +1 -0
- streamlit/static/static/js/data-grid-overlay-editor.B69OOFM4.js +1 -0
- streamlit/static/static/js/downloader.BZQhlBNT.js +1 -0
- streamlit/static/static/js/es6.D9Zhqujy.js +2 -0
- streamlit/static/static/js/iframeResizer.contentWindow.CAzcBpCC.js +1 -0
- streamlit/static/static/js/index.08vcOOvb.js +1 -0
- streamlit/static/static/js/index.0uqKfJUS.js +1 -0
- streamlit/static/static/js/index.B02M5u69.js +203 -0
- streamlit/static/static/js/index.B7mcZKMx.js +1 -0
- streamlit/static/static/js/index.BAQDHFA_.js +1 -0
- streamlit/static/static/js/index.BI60cMVr.js +2 -0
- streamlit/static/static/js/index.BLug2inK.js +1 -0
- streamlit/static/static/js/index.BM6TMY8g.js +2 -0
- streamlit/static/static/js/index.BZ9p1t7G.js +1 -0
- streamlit/static/static/js/index.BZqa87a1.js +2 -0
- streamlit/static/static/js/index.BcsRUzZZ.js +1 -0
- streamlit/static/static/js/index.BgVMiY_P.js +197 -0
- streamlit/static/static/js/index.BtuGy7By.js +6 -0
- streamlit/static/static/js/index.BuDuBmrs.js +1 -0
- streamlit/static/static/js/index.BvXU2oKV.js +1 -0
- streamlit/static/static/js/index.BxcwPacT.js +73 -0
- streamlit/static/static/js/index.CWX8KB81.js +1 -0
- streamlit/static/static/js/index.CXzZTo_q.js +1 -0
- streamlit/static/static/js/index.CcRWp_KL.js +1 -0
- streamlit/static/static/js/index.Cd-_xe55.js +3 -0
- streamlit/static/static/js/index.CdG2PXln.js +4537 -0
- streamlit/static/static/js/index.CjXvXmcP.js +1 -0
- streamlit/static/static/js/index.D1HZENZx.js +776 -0
- streamlit/static/static/js/index.D21Efo64.js +1617 -0
- streamlit/static/static/js/index.D9WgGVBx.js +7 -0
- streamlit/static/static/js/index.DEcsHtvb.js +12 -0
- streamlit/static/static/js/index.DFeMfr_K.js +1 -0
- streamlit/static/static/js/index.DHFBoItz.js +1 -0
- streamlit/static/static/js/index.D_PrBKnJ.js +3 -0
- streamlit/static/static/js/index.DmuRkekN.js +3855 -0
- streamlit/static/static/js/index.Do6eY8sf.js +1 -0
- streamlit/static/static/js/index.Dz3lP2P-.js +1 -0
- streamlit/static/static/js/index.Dz_UqF-s.js +1 -0
- streamlit/static/static/js/index.GkSUsPhJ.js +1 -0
- streamlit/static/static/js/index.H1U1IC_d.js +3 -0
- streamlit/static/static/js/index.g6p_4DPr.js +1 -0
- streamlit/static/static/js/index.g9x_GKss.js +1 -0
- streamlit/static/static/js/index.zo9jm08y.js +1 -0
- streamlit/static/static/js/input.DnaFglHq.js +2 -0
- streamlit/static/static/js/inputUtils.CQWz5UKz.js +1 -0
- streamlit/static/static/js/memory.Crb9x4-F.js +1 -0
- streamlit/static/static/js/mergeWith.ouAz0sK3.js +1 -0
- streamlit/static/static/js/number-overlay-editor._UaN-O48.js +9 -0
- streamlit/static/static/js/possibleConstructorReturn.CtGjGFHz.js +1 -0
- streamlit/static/static/js/sandbox.CBybYOhV.js +1 -0
- streamlit/static/static/js/sprintf.D7DtBTRn.js +1 -0
- streamlit/static/static/js/textarea.Cb_uJt5U.js +2 -0
- streamlit/static/static/js/threshold.DjX0wlsa.js +1 -0
- streamlit/static/static/js/timepicker.DKT7pfoF.js +4 -0
- streamlit/static/static/js/timer.CAwTRJ_g.js +1 -0
- streamlit/static/static/js/toConsumableArray.05Ikp13-.js +3 -0
- streamlit/static/static/js/uniqueId.D2FMWUEI.js +1 -0
- streamlit/static/static/js/useBasicWidgetState.urnZLANY.js +1 -0
- streamlit/static/static/js/useOnInputChange.BOKIIdJ1.js +1 -0
- streamlit/static/static/js/value.CgPGBV_l.js +1 -0
- streamlit/static/static/js/withFullScreenWrapper.C_N8J0Xx.js +1 -0
- streamlit/static/static/media/KaTeX_AMS-Regular.BQhdFMY1.woff2 +0 -0
- streamlit/static/static/media/KaTeX_AMS-Regular.DMm9YOAa.woff +0 -0
- streamlit/static/static/media/KaTeX_AMS-Regular.DRggAlZN.ttf +0 -0
- streamlit/static/static/media/KaTeX_Caligraphic-Bold.ATXxdsX0.ttf +0 -0
- streamlit/static/static/media/KaTeX_Caligraphic-Bold.BEiXGLvX.woff +0 -0
- streamlit/static/static/media/KaTeX_Caligraphic-Bold.Dq_IR9rO.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Caligraphic-Regular.CTRA-rTL.woff +0 -0
- streamlit/static/static/media/KaTeX_Caligraphic-Regular.Di6jR-x-.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Caligraphic-Regular.wX97UBjC.ttf +0 -0
- streamlit/static/static/media/KaTeX_Fraktur-Bold.BdnERNNW.ttf +0 -0
- streamlit/static/static/media/KaTeX_Fraktur-Bold.BsDP51OF.woff +0 -0
- streamlit/static/static/media/KaTeX_Fraktur-Bold.CL6g_b3V.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Fraktur-Regular.CB_wures.ttf +0 -0
- streamlit/static/static/media/KaTeX_Fraktur-Regular.CTYiF6lA.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Fraktur-Regular.Dxdc4cR9.woff +0 -0
- streamlit/static/static/media/KaTeX_Main-Bold.Cx986IdX.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Main-Bold.Jm3AIy58.woff +0 -0
- streamlit/static/static/media/KaTeX_Main-Bold.waoOVXN0.ttf +0 -0
- streamlit/static/static/media/KaTeX_Main-BoldItalic.DxDJ3AOS.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Main-BoldItalic.DzxPMmG6.ttf +0 -0
- streamlit/static/static/media/KaTeX_Main-BoldItalic.SpSLRI95.woff +0 -0
- streamlit/static/static/media/KaTeX_Main-Italic.3WenGoN9.ttf +0 -0
- streamlit/static/static/media/KaTeX_Main-Italic.BMLOBm91.woff +0 -0
- streamlit/static/static/media/KaTeX_Main-Italic.NWA7e6Wa.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Main-Regular.B22Nviop.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Main-Regular.Dr94JaBh.woff +0 -0
- streamlit/static/static/media/KaTeX_Main-Regular.ypZvNtVU.ttf +0 -0
- streamlit/static/static/media/KaTeX_Math-BoldItalic.B3XSjfu4.ttf +0 -0
- streamlit/static/static/media/KaTeX_Math-BoldItalic.CZnvNsCZ.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Math-BoldItalic.iY-2wyZ7.woff +0 -0
- streamlit/static/static/media/KaTeX_Math-Italic.DA0__PXp.woff +0 -0
- streamlit/static/static/media/KaTeX_Math-Italic.flOr_0UB.ttf +0 -0
- streamlit/static/static/media/KaTeX_Math-Italic.t53AETM-.woff2 +0 -0
- streamlit/static/static/media/KaTeX_SansSerif-Bold.CFMepnvq.ttf +0 -0
- streamlit/static/static/media/KaTeX_SansSerif-Bold.D1sUS0GD.woff2 +0 -0
- streamlit/static/static/media/KaTeX_SansSerif-Bold.DbIhKOiC.woff +0 -0
- streamlit/static/static/media/KaTeX_SansSerif-Italic.C3H0VqGB.woff2 +0 -0
- streamlit/static/static/media/KaTeX_SansSerif-Italic.DN2j7dab.woff +0 -0
- streamlit/static/static/media/KaTeX_SansSerif-Italic.YYjJ1zSn.ttf +0 -0
- streamlit/static/static/media/KaTeX_SansSerif-Regular.BNo7hRIc.ttf +0 -0
- streamlit/static/static/media/KaTeX_SansSerif-Regular.CS6fqUqJ.woff +0 -0
- streamlit/static/static/media/KaTeX_SansSerif-Regular.DDBCnlJ7.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Script-Regular.C5JkGWo-.ttf +0 -0
- streamlit/static/static/media/KaTeX_Script-Regular.D3wIWfF6.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Script-Regular.D5yQViql.woff +0 -0
- streamlit/static/static/media/KaTeX_Size1-Regular.C195tn64.woff +0 -0
- streamlit/static/static/media/KaTeX_Size1-Regular.Dbsnue_I.ttf +0 -0
- streamlit/static/static/media/KaTeX_Size1-Regular.mCD8mA8B.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Size2-Regular.B7gKUWhC.ttf +0 -0
- streamlit/static/static/media/KaTeX_Size2-Regular.Dy4dx90m.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Size2-Regular.oD1tc_U0.woff +0 -0
- streamlit/static/static/media/KaTeX_Size3-Regular.CTq5MqoE.woff +0 -0
- streamlit/static/static/media/KaTeX_Size3-Regular.DgpXs0kz.ttf +0 -0
- streamlit/static/static/media/KaTeX_Size4-Regular.BF-4gkZK.woff +0 -0
- streamlit/static/static/media/KaTeX_Size4-Regular.DWFBv043.ttf +0 -0
- streamlit/static/static/media/KaTeX_Size4-Regular.Dl5lxZxV.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Typewriter-Regular.C0xS9mPB.woff +0 -0
- streamlit/static/static/media/KaTeX_Typewriter-Regular.CO6r4hn1.woff2 +0 -0
- streamlit/static/static/media/KaTeX_Typewriter-Regular.D3Ib7_Hf.ttf +0 -0
- streamlit/static/static/media/MaterialSymbols-Rounded.DcZbplWk.woff2 +0 -0
- streamlit/static/static/media/SourceCodePro-Bold.CFEfr7-q.woff2 +0 -0
- streamlit/static/static/media/SourceCodePro-BoldItalic.C-LkFXxa.woff2 +0 -0
- streamlit/static/static/media/SourceCodePro-Italic.CxFOx7N-.woff2 +0 -0
- streamlit/static/static/media/SourceCodePro-Regular.CBOlD63d.woff2 +0 -0
- streamlit/static/static/media/SourceCodePro-SemiBold.CFHwW3Wd.woff2 +0 -0
- streamlit/static/static/media/SourceCodePro-SemiBoldItalic.Cg2yRu82.woff2 +0 -0
- streamlit/static/static/media/SourceSansPro-Bold.-6c9oR8J.woff2 +0 -0
- streamlit/static/static/media/SourceSansPro-BoldItalic.DmM_grLY.woff2 +0 -0
- streamlit/static/static/media/SourceSansPro-Italic.I1ipWe7Q.woff2 +0 -0
- streamlit/static/static/media/SourceSansPro-Regular.DZLUzqI4.woff2 +0 -0
- streamlit/static/static/media/SourceSansPro-SemiBold.sKQIyTMz.woff2 +0 -0
- streamlit/static/static/media/SourceSansPro-SemiBoldItalic.C0wP0icr.woff2 +0 -0
- streamlit/static/static/media/SourceSerifPro-Bold.8TUnKj4x.woff2 +0 -0
- streamlit/static/static/media/SourceSerifPro-BoldItalic.CBVO7Ve7.woff2 +0 -0
- streamlit/static/static/media/SourceSerifPro-Italic.DkFgL2HZ.woff2 +0 -0
- streamlit/static/static/media/SourceSerifPro-Regular.CNJNET2S.woff2 +0 -0
- streamlit/static/static/media/SourceSerifPro-SemiBold.CHyh9GC5.woff2 +0 -0
- streamlit/static/static/media/SourceSerifPro-SemiBoldItalic.CBtz8sWN.woff2 +0 -0
- streamlit/static/static/media/balloon-0.Czj7AKwE.png +0 -0
- streamlit/static/static/media/balloon-1.CNvFFrND.png +0 -0
- streamlit/static/static/media/balloon-2.DTvC6B1t.png +0 -0
- streamlit/static/static/media/balloon-3.CgSk4tbL.png +0 -0
- streamlit/static/static/media/balloon-4.mbtFrzxf.png +0 -0
- streamlit/static/static/media/balloon-5.CSwkUfRA.png +0 -0
- streamlit/static/static/media/fireworks.B4d-_KUe.gif +0 -0
- streamlit/static/static/media/flake-0.DgWaVvm5.png +0 -0
- streamlit/static/static/media/flake-1.B2r5AHMK.png +0 -0
- streamlit/static/static/media/flake-2.BnWSExPC.png +0 -0
- streamlit/static/static/media/snowflake.JU2jBHL8.svg +11 -0
- streamlit/string_util.py +203 -0
- streamlit/temporary_directory.py +56 -0
- streamlit/testing/__init__.py +13 -0
- streamlit/testing/v1/__init__.py +17 -0
- streamlit/testing/v1/app_test.py +1050 -0
- streamlit/testing/v1/element_tree.py +2083 -0
- streamlit/testing/v1/local_script_runner.py +180 -0
- streamlit/testing/v1/util.py +53 -0
- streamlit/time_util.py +75 -0
- streamlit/type_util.py +460 -0
- streamlit/url_util.py +122 -0
- streamlit/user_info.py +519 -0
- streamlit/util.py +72 -0
- streamlit/vendor/__init__.py +0 -0
- streamlit/vendor/pympler/__init__.py +0 -0
- streamlit/vendor/pympler/asizeof.py +2869 -0
- streamlit/version.py +18 -0
- streamlit/watcher/__init__.py +28 -0
- streamlit/watcher/event_based_path_watcher.py +406 -0
- streamlit/watcher/folder_black_list.py +82 -0
- streamlit/watcher/local_sources_watcher.py +233 -0
- streamlit/watcher/path_watcher.py +185 -0
- streamlit/watcher/polling_path_watcher.py +124 -0
- streamlit/watcher/util.py +207 -0
- streamlit/web/__init__.py +13 -0
- streamlit/web/bootstrap.py +353 -0
- streamlit/web/cache_storage_manager_config.py +38 -0
- streamlit/web/cli.py +369 -0
- streamlit/web/server/__init__.py +26 -0
- streamlit/web/server/app_static_file_handler.py +93 -0
- streamlit/web/server/authlib_tornado_integration.py +60 -0
- streamlit/web/server/browser_websocket_handler.py +246 -0
- streamlit/web/server/component_request_handler.py +116 -0
- streamlit/web/server/media_file_handler.py +141 -0
- streamlit/web/server/oauth_authlib_routes.py +176 -0
- streamlit/web/server/oidc_mixin.py +108 -0
- streamlit/web/server/routes.py +295 -0
- streamlit/web/server/server.py +479 -0
- streamlit/web/server/server_util.py +161 -0
- streamlit/web/server/stats_request_handler.py +95 -0
- streamlit/web/server/upload_file_request_handler.py +137 -0
- streamlit/web/server/websocket_headers.py +56 -0
- streamlit_nightly-1.43.2.dev20250307.data/scripts/streamlit.cmd +16 -0
- streamlit_nightly-1.43.2.dev20250307.dist-info/METADATA +207 -0
- streamlit_nightly-1.43.2.dev20250307.dist-info/RECORD +563 -0
- streamlit_nightly-1.43.2.dev20250307.dist-info/WHEEL +5 -0
- streamlit_nightly-1.43.2.dev20250307.dist-info/entry_points.txt +2 -0
- streamlit_nightly-1.43.2.dev20250307.dist-info/top_level.txt +1 -0
@@ -0,0 +1,772 @@
|
|
1
|
+
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2025)
|
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
|
+
from __future__ import annotations
|
16
|
+
|
17
|
+
import json
|
18
|
+
import pickle
|
19
|
+
from collections.abc import Iterator, KeysView, MutableMapping
|
20
|
+
from copy import deepcopy
|
21
|
+
from dataclasses import dataclass, field, replace
|
22
|
+
from typing import (
|
23
|
+
TYPE_CHECKING,
|
24
|
+
Any,
|
25
|
+
Final,
|
26
|
+
Union,
|
27
|
+
cast,
|
28
|
+
)
|
29
|
+
|
30
|
+
from typing_extensions import TypeAlias
|
31
|
+
|
32
|
+
import streamlit as st
|
33
|
+
from streamlit import config, util
|
34
|
+
from streamlit.errors import StreamlitAPIException, UnserializableSessionStateError
|
35
|
+
from streamlit.proto.WidgetStates_pb2 import WidgetState as WidgetStateProto
|
36
|
+
from streamlit.proto.WidgetStates_pb2 import WidgetStates as WidgetStatesProto
|
37
|
+
from streamlit.runtime.scriptrunner_utils.script_run_context import get_script_run_ctx
|
38
|
+
from streamlit.runtime.state.common import (
|
39
|
+
RegisterWidgetResult,
|
40
|
+
T,
|
41
|
+
ValueFieldName,
|
42
|
+
WidgetMetadata,
|
43
|
+
is_array_value_field_name,
|
44
|
+
is_element_id,
|
45
|
+
is_keyed_element_id,
|
46
|
+
)
|
47
|
+
from streamlit.runtime.state.query_params import QueryParams
|
48
|
+
from streamlit.runtime.stats import CacheStat, CacheStatsProvider, group_stats
|
49
|
+
|
50
|
+
if TYPE_CHECKING:
|
51
|
+
from streamlit.runtime.session_manager import SessionManager
|
52
|
+
|
53
|
+
|
54
|
+
STREAMLIT_INTERNAL_KEY_PREFIX: Final = "$$STREAMLIT_INTERNAL_KEY"
|
55
|
+
SCRIPT_RUN_WITHOUT_ERRORS_KEY: Final = (
|
56
|
+
f"{STREAMLIT_INTERNAL_KEY_PREFIX}_SCRIPT_RUN_WITHOUT_ERRORS"
|
57
|
+
)
|
58
|
+
|
59
|
+
|
60
|
+
@dataclass(frozen=True)
|
61
|
+
class Serialized:
|
62
|
+
"""A widget value that's serialized to a protobuf. Immutable."""
|
63
|
+
|
64
|
+
value: WidgetStateProto
|
65
|
+
|
66
|
+
|
67
|
+
@dataclass(frozen=True)
|
68
|
+
class Value:
|
69
|
+
"""A widget value that's not serialized. Immutable."""
|
70
|
+
|
71
|
+
value: Any
|
72
|
+
|
73
|
+
|
74
|
+
WState: TypeAlias = Union[Value, Serialized]
|
75
|
+
|
76
|
+
|
77
|
+
@dataclass
|
78
|
+
class WStates(MutableMapping[str, Any]):
|
79
|
+
"""A mapping of widget IDs to values. Widget values can be stored in
|
80
|
+
serialized or deserialized form, but when values are retrieved from the
|
81
|
+
mapping, they'll always be deserialized.
|
82
|
+
"""
|
83
|
+
|
84
|
+
states: dict[str, WState] = field(default_factory=dict)
|
85
|
+
widget_metadata: dict[str, WidgetMetadata[Any]] = field(default_factory=dict)
|
86
|
+
|
87
|
+
def __repr__(self):
|
88
|
+
return util.repr_(self)
|
89
|
+
|
90
|
+
def __getitem__(self, k: str) -> Any:
|
91
|
+
"""Return the value of the widget with the given key.
|
92
|
+
If the widget's value is currently stored in serialized form, it
|
93
|
+
will be deserialized first.
|
94
|
+
"""
|
95
|
+
wstate = self.states.get(k)
|
96
|
+
if wstate is None:
|
97
|
+
raise KeyError(k)
|
98
|
+
|
99
|
+
if isinstance(wstate, Value):
|
100
|
+
# The widget's value is already deserialized - return it directly.
|
101
|
+
return wstate.value
|
102
|
+
|
103
|
+
# The widget's value is serialized. We deserialize it, and return
|
104
|
+
# the deserialized value.
|
105
|
+
|
106
|
+
metadata = self.widget_metadata.get(k)
|
107
|
+
if metadata is None:
|
108
|
+
# No deserializer, which should only happen if state is
|
109
|
+
# gotten from a reconnecting browser and the script is
|
110
|
+
# trying to access it. Pretend it doesn't exist.
|
111
|
+
raise KeyError(k)
|
112
|
+
value_field_name = cast(
|
113
|
+
ValueFieldName,
|
114
|
+
wstate.value.WhichOneof("value"),
|
115
|
+
)
|
116
|
+
value = (
|
117
|
+
wstate.value.__getattribute__(value_field_name)
|
118
|
+
if value_field_name # Field name is None if the widget value was cleared
|
119
|
+
else None
|
120
|
+
)
|
121
|
+
|
122
|
+
if is_array_value_field_name(value_field_name):
|
123
|
+
# Array types are messages with data in a `data` field
|
124
|
+
value = value.data
|
125
|
+
elif value_field_name == "json_value":
|
126
|
+
value = json.loads(value)
|
127
|
+
|
128
|
+
deserialized = metadata.deserializer(value, metadata.id)
|
129
|
+
|
130
|
+
# Update metadata to reflect information from WidgetState proto
|
131
|
+
self.set_widget_metadata(
|
132
|
+
replace(
|
133
|
+
metadata,
|
134
|
+
value_type=value_field_name,
|
135
|
+
)
|
136
|
+
)
|
137
|
+
|
138
|
+
self.states[k] = Value(deserialized)
|
139
|
+
return deserialized
|
140
|
+
|
141
|
+
def __setitem__(self, k: str, v: WState) -> None:
|
142
|
+
self.states[k] = v
|
143
|
+
|
144
|
+
def __delitem__(self, k: str) -> None:
|
145
|
+
del self.states[k]
|
146
|
+
|
147
|
+
def __len__(self) -> int:
|
148
|
+
return len(self.states)
|
149
|
+
|
150
|
+
def __iter__(self):
|
151
|
+
# For this and many other methods, we can't simply delegate to the
|
152
|
+
# states field, because we need to invoke `__getitem__` for any
|
153
|
+
# values, to handle deserialization and unwrapping of values.
|
154
|
+
yield from self.states
|
155
|
+
|
156
|
+
def keys(self) -> KeysView[str]:
|
157
|
+
return KeysView(self.states)
|
158
|
+
|
159
|
+
def items(self) -> set[tuple[str, Any]]: # type: ignore[override]
|
160
|
+
return {(k, self[k]) for k in self}
|
161
|
+
|
162
|
+
def values(self) -> set[Any]: # type: ignore[override]
|
163
|
+
return {self[wid] for wid in self}
|
164
|
+
|
165
|
+
def update(self, other: WStates) -> None: # type: ignore[override]
|
166
|
+
"""Copy all widget values and metadata from 'other' into this mapping,
|
167
|
+
overwriting any data in this mapping that's also present in 'other'.
|
168
|
+
"""
|
169
|
+
self.states.update(other.states)
|
170
|
+
self.widget_metadata.update(other.widget_metadata)
|
171
|
+
|
172
|
+
def set_widget_from_proto(self, widget_state: WidgetStateProto) -> None:
|
173
|
+
"""Set a widget's serialized value, overwriting any existing value it has."""
|
174
|
+
self[widget_state.id] = Serialized(widget_state)
|
175
|
+
|
176
|
+
def set_from_value(self, k: str, v: Any) -> None:
|
177
|
+
"""Set a widget's deserialized value, overwriting any existing value it has."""
|
178
|
+
self[k] = Value(v)
|
179
|
+
|
180
|
+
def set_widget_metadata(self, widget_meta: WidgetMetadata[Any]) -> None:
|
181
|
+
"""Set a widget's metadata, overwriting any existing metadata it has."""
|
182
|
+
self.widget_metadata[widget_meta.id] = widget_meta
|
183
|
+
|
184
|
+
def remove_stale_widgets(
|
185
|
+
self,
|
186
|
+
active_widget_ids: set[str],
|
187
|
+
fragment_ids_this_run: list[str] | None,
|
188
|
+
) -> None:
|
189
|
+
"""Remove widget state for stale widgets."""
|
190
|
+
self.states = {
|
191
|
+
k: v
|
192
|
+
for k, v in self.states.items()
|
193
|
+
if not _is_stale_widget(
|
194
|
+
self.widget_metadata.get(k),
|
195
|
+
active_widget_ids,
|
196
|
+
fragment_ids_this_run,
|
197
|
+
)
|
198
|
+
}
|
199
|
+
|
200
|
+
def get_serialized(self, k: str) -> WidgetStateProto | None:
|
201
|
+
"""Get the serialized value of the widget with the given id.
|
202
|
+
|
203
|
+
If the widget doesn't exist, return None. If the widget exists but
|
204
|
+
is not in serialized form, it will be serialized first.
|
205
|
+
"""
|
206
|
+
|
207
|
+
item = self.states.get(k)
|
208
|
+
if item is None:
|
209
|
+
# No such widget: return None.
|
210
|
+
return None
|
211
|
+
|
212
|
+
if isinstance(item, Serialized):
|
213
|
+
# Widget value is serialized: return it directly.
|
214
|
+
return item.value
|
215
|
+
|
216
|
+
# Widget value is not serialized: serialize it first!
|
217
|
+
metadata = self.widget_metadata.get(k)
|
218
|
+
if metadata is None:
|
219
|
+
# We're missing the widget's metadata. (Can this happen?)
|
220
|
+
return None
|
221
|
+
|
222
|
+
widget = WidgetStateProto()
|
223
|
+
widget.id = k
|
224
|
+
|
225
|
+
field = metadata.value_type
|
226
|
+
serialized = metadata.serializer(item.value)
|
227
|
+
|
228
|
+
if is_array_value_field_name(field):
|
229
|
+
arr = getattr(widget, field)
|
230
|
+
arr.data.extend(serialized)
|
231
|
+
elif field == "json_value":
|
232
|
+
setattr(widget, field, json.dumps(serialized))
|
233
|
+
elif field == "file_uploader_state_value":
|
234
|
+
widget.file_uploader_state_value.CopyFrom(serialized)
|
235
|
+
elif field == "string_trigger_value":
|
236
|
+
widget.string_trigger_value.CopyFrom(serialized)
|
237
|
+
elif field == "chat_input_value":
|
238
|
+
widget.chat_input_value.CopyFrom(serialized)
|
239
|
+
elif field is not None and serialized is not None:
|
240
|
+
# If the field is None, the widget value was cleared
|
241
|
+
# by the user and therefore is None. But we cannot
|
242
|
+
# set it to None here, since the proto properties are
|
243
|
+
# not nullable. So we just don't set it.
|
244
|
+
setattr(widget, field, serialized)
|
245
|
+
|
246
|
+
return widget
|
247
|
+
|
248
|
+
def as_widget_states(self) -> list[WidgetStateProto]:
|
249
|
+
"""Return a list of serialized widget values for each widget with a value."""
|
250
|
+
states = [
|
251
|
+
self.get_serialized(widget_id)
|
252
|
+
for widget_id in self.states.keys()
|
253
|
+
if self.get_serialized(widget_id)
|
254
|
+
]
|
255
|
+
states = cast(list[WidgetStateProto], states)
|
256
|
+
return states
|
257
|
+
|
258
|
+
def call_callback(self, widget_id: str) -> None:
|
259
|
+
"""Call the given widget's callback and return the callback's
|
260
|
+
return value. If the widget has no callback, return None.
|
261
|
+
|
262
|
+
If the widget doesn't exist, raise an Exception.
|
263
|
+
"""
|
264
|
+
metadata = self.widget_metadata.get(widget_id)
|
265
|
+
assert metadata is not None
|
266
|
+
callback = metadata.callback
|
267
|
+
if callback is None:
|
268
|
+
return
|
269
|
+
|
270
|
+
args = metadata.callback_args or ()
|
271
|
+
kwargs = metadata.callback_kwargs or {}
|
272
|
+
callback(*args, **kwargs)
|
273
|
+
|
274
|
+
|
275
|
+
def _missing_key_error_message(key: str) -> str:
|
276
|
+
return (
|
277
|
+
f'st.session_state has no key "{key}". Did you forget to initialize it? '
|
278
|
+
f"More info: https://docs.streamlit.io/develop/concepts/architecture/session-state#initialization"
|
279
|
+
)
|
280
|
+
|
281
|
+
|
282
|
+
@dataclass
|
283
|
+
class KeyIdMapper:
|
284
|
+
"""A mapping of user-provided keys to element IDs.
|
285
|
+
It also maps element IDs to user-provided keys so that this reverse mapping
|
286
|
+
does not have to be computed ad-hoc.
|
287
|
+
All built-in dict-operations such as setting and deleting expect the key as the
|
288
|
+
argument, not the element ID.
|
289
|
+
"""
|
290
|
+
|
291
|
+
_key_id_mapping: dict[str, str] = field(default_factory=dict)
|
292
|
+
_id_key_mapping: dict[str, str] = field(default_factory=dict)
|
293
|
+
|
294
|
+
def __contains__(self, key: str) -> bool:
|
295
|
+
return key in self._key_id_mapping
|
296
|
+
|
297
|
+
def __setitem__(self, key: str, widget_id: Any) -> None:
|
298
|
+
self._key_id_mapping[key] = widget_id
|
299
|
+
self._id_key_mapping[widget_id] = key
|
300
|
+
|
301
|
+
def __delitem__(self, key: str) -> None:
|
302
|
+
self.delete(key)
|
303
|
+
|
304
|
+
@property
|
305
|
+
def id_key_mapping(self) -> dict[str, str]:
|
306
|
+
return self._id_key_mapping
|
307
|
+
|
308
|
+
def set_key_id_mapping(self, key_id_mapping: dict[str, str]) -> None:
|
309
|
+
self._key_id_mapping = key_id_mapping
|
310
|
+
self._id_key_mapping = {v: k for k, v in key_id_mapping.items()}
|
311
|
+
|
312
|
+
def get_id_from_key(self, key: str, default: Any = None) -> str:
|
313
|
+
return self._key_id_mapping.get(key, default)
|
314
|
+
|
315
|
+
def get_key_from_id(self, widget_id: str) -> str:
|
316
|
+
return self._id_key_mapping[widget_id]
|
317
|
+
|
318
|
+
def update(self, other: KeyIdMapper) -> None:
|
319
|
+
self._key_id_mapping.update(other._key_id_mapping)
|
320
|
+
self._id_key_mapping.update(other._id_key_mapping)
|
321
|
+
|
322
|
+
def clear(self):
|
323
|
+
self._key_id_mapping.clear()
|
324
|
+
self._id_key_mapping.clear()
|
325
|
+
|
326
|
+
def delete(self, key: str):
|
327
|
+
widget_id = self._key_id_mapping[key]
|
328
|
+
del self._key_id_mapping[key]
|
329
|
+
del self._id_key_mapping[widget_id]
|
330
|
+
|
331
|
+
|
332
|
+
@dataclass
|
333
|
+
class SessionState:
|
334
|
+
"""SessionState allows users to store values that persist between app
|
335
|
+
reruns.
|
336
|
+
|
337
|
+
Example
|
338
|
+
-------
|
339
|
+
>>> if "num_script_runs" not in st.session_state:
|
340
|
+
... st.session_state.num_script_runs = 0
|
341
|
+
>>> st.session_state.num_script_runs += 1
|
342
|
+
>>> st.write(st.session_state.num_script_runs) # writes 1
|
343
|
+
|
344
|
+
The next time your script runs, the value of
|
345
|
+
st.session_state.num_script_runs will be preserved.
|
346
|
+
>>> st.session_state.num_script_runs += 1
|
347
|
+
>>> st.write(st.session_state.num_script_runs) # writes 2
|
348
|
+
"""
|
349
|
+
|
350
|
+
# All the values from previous script runs, squished together to save memory
|
351
|
+
_old_state: dict[str, Any] = field(default_factory=dict)
|
352
|
+
|
353
|
+
# Values set in session state during the current script run, possibly for
|
354
|
+
# setting a widget's value. Keyed by a user provided string.
|
355
|
+
_new_session_state: dict[str, Any] = field(default_factory=dict)
|
356
|
+
|
357
|
+
# Widget values from the frontend, usually one changing prompted the script rerun
|
358
|
+
_new_widget_state: WStates = field(default_factory=WStates)
|
359
|
+
|
360
|
+
# Keys used for widgets will be eagerly converted to the matching element id
|
361
|
+
_key_id_mapper: KeyIdMapper = field(default_factory=KeyIdMapper)
|
362
|
+
|
363
|
+
# query params are stored in session state because query params will be tied with
|
364
|
+
# widget state at one point.
|
365
|
+
query_params: QueryParams = field(default_factory=QueryParams)
|
366
|
+
|
367
|
+
def __repr__(self):
|
368
|
+
return util.repr_(self)
|
369
|
+
|
370
|
+
# is it possible for a value to get through this without being deserialized?
|
371
|
+
def _compact_state(self) -> None:
|
372
|
+
"""Copy all current session_state and widget_state values into our
|
373
|
+
_old_state dict, and then clear our current session_state and
|
374
|
+
widget_state.
|
375
|
+
"""
|
376
|
+
for key_or_wid in self:
|
377
|
+
try:
|
378
|
+
self._old_state[key_or_wid] = self[key_or_wid]
|
379
|
+
except KeyError:
|
380
|
+
# handle key errors from widget state not having metadata gracefully
|
381
|
+
# https://github.com/streamlit/streamlit/issues/7206
|
382
|
+
pass
|
383
|
+
self._new_session_state.clear()
|
384
|
+
self._new_widget_state.clear()
|
385
|
+
|
386
|
+
def clear(self) -> None:
|
387
|
+
"""Reset self completely, clearing all current and old values."""
|
388
|
+
self._old_state.clear()
|
389
|
+
self._new_session_state.clear()
|
390
|
+
self._new_widget_state.clear()
|
391
|
+
self._key_id_mapper.clear()
|
392
|
+
|
393
|
+
@property
|
394
|
+
def filtered_state(self) -> dict[str, Any]:
|
395
|
+
"""The combined session and widget state, excluding keyless widgets."""
|
396
|
+
|
397
|
+
wid_key_map = self._key_id_mapper.id_key_mapping
|
398
|
+
|
399
|
+
state: dict[str, Any] = {}
|
400
|
+
|
401
|
+
# We can't write `for k, v in self.items()` here because doing so will
|
402
|
+
# run into a `KeyError` if widget metadata has been cleared (which
|
403
|
+
# happens when the streamlit server restarted or the cache was cleared),
|
404
|
+
# then we receive a widget's state from a browser.
|
405
|
+
for k in self._keys():
|
406
|
+
if not is_element_id(k) and not _is_internal_key(k):
|
407
|
+
state[k] = self[k]
|
408
|
+
elif is_keyed_element_id(k):
|
409
|
+
try:
|
410
|
+
key = wid_key_map[k]
|
411
|
+
state[key] = self[k]
|
412
|
+
except KeyError:
|
413
|
+
# Widget id no longer maps to a key, it is a not yet
|
414
|
+
# cleared value in old state for a reset widget
|
415
|
+
pass
|
416
|
+
|
417
|
+
return state
|
418
|
+
|
419
|
+
def _keys(self) -> set[str]:
|
420
|
+
"""All keys active in Session State, with widget keys converted
|
421
|
+
to widget ids when one is known. (This includes autogenerated keys
|
422
|
+
for widgets that don't have user_keys defined, and which aren't
|
423
|
+
exposed to user code.)
|
424
|
+
"""
|
425
|
+
old_keys = {self._get_widget_id(k) for k in self._old_state.keys()}
|
426
|
+
new_widget_keys = set(self._new_widget_state.keys())
|
427
|
+
new_session_state_keys = {
|
428
|
+
self._get_widget_id(k) for k in self._new_session_state.keys()
|
429
|
+
}
|
430
|
+
return old_keys | new_widget_keys | new_session_state_keys
|
431
|
+
|
432
|
+
def is_new_state_value(self, user_key: str) -> bool:
|
433
|
+
"""True if a value with the given key is in the current session state."""
|
434
|
+
return user_key in self._new_session_state
|
435
|
+
|
436
|
+
def __iter__(self) -> Iterator[Any]:
|
437
|
+
"""Return an iterator over the keys of the SessionState.
|
438
|
+
This is a shortcut for `iter(self.keys())`
|
439
|
+
"""
|
440
|
+
return iter(self._keys())
|
441
|
+
|
442
|
+
def __len__(self) -> int:
|
443
|
+
"""Return the number of items in SessionState."""
|
444
|
+
return len(self._keys())
|
445
|
+
|
446
|
+
def __getitem__(self, key: str) -> Any:
|
447
|
+
wid_key_map = self._key_id_mapper.id_key_mapping
|
448
|
+
widget_id = self._get_widget_id(key)
|
449
|
+
|
450
|
+
if widget_id in wid_key_map and widget_id == key:
|
451
|
+
# the "key" is a raw widget id, so get its associated user key for lookup
|
452
|
+
key = wid_key_map[widget_id]
|
453
|
+
try:
|
454
|
+
return self._getitem(widget_id, key)
|
455
|
+
except KeyError:
|
456
|
+
raise KeyError(_missing_key_error_message(key))
|
457
|
+
|
458
|
+
def _getitem(self, widget_id: str | None, user_key: str | None) -> Any:
|
459
|
+
"""Get the value of an entry in Session State, using either the
|
460
|
+
user-provided key or a widget id as appropriate for the internal dict
|
461
|
+
being accessed.
|
462
|
+
|
463
|
+
At least one of the arguments must have a value.
|
464
|
+
"""
|
465
|
+
assert user_key is not None or widget_id is not None
|
466
|
+
|
467
|
+
if user_key is not None:
|
468
|
+
try:
|
469
|
+
return self._new_session_state[user_key]
|
470
|
+
except KeyError:
|
471
|
+
pass
|
472
|
+
|
473
|
+
if widget_id is not None:
|
474
|
+
try:
|
475
|
+
return self._new_widget_state[widget_id]
|
476
|
+
except KeyError:
|
477
|
+
pass
|
478
|
+
|
479
|
+
# Typically, there won't be both a widget id and an associated state key in
|
480
|
+
# old state at the same time, so the order we check is arbitrary.
|
481
|
+
# The exception is if session state is set and then a later run has
|
482
|
+
# a widget created, so the widget id entry should be newer.
|
483
|
+
# The opposite case shouldn't happen, because setting the value of a widget
|
484
|
+
# through session state will result in the next widget state reflecting that
|
485
|
+
# value.
|
486
|
+
if widget_id is not None:
|
487
|
+
try:
|
488
|
+
return self._old_state[widget_id]
|
489
|
+
except KeyError:
|
490
|
+
pass
|
491
|
+
|
492
|
+
if user_key is not None:
|
493
|
+
try:
|
494
|
+
return self._old_state[user_key]
|
495
|
+
except KeyError:
|
496
|
+
pass
|
497
|
+
|
498
|
+
# We'll never get here
|
499
|
+
raise KeyError
|
500
|
+
|
501
|
+
def __setitem__(self, user_key: str, value: Any) -> None:
|
502
|
+
"""Set the value of the session_state entry with the given user_key.
|
503
|
+
|
504
|
+
If the key corresponds to a widget or form that's been instantiated
|
505
|
+
during the current script run, raise a StreamlitAPIException instead.
|
506
|
+
"""
|
507
|
+
ctx = get_script_run_ctx()
|
508
|
+
|
509
|
+
if ctx is not None:
|
510
|
+
widget_id = self._key_id_mapper.get_id_from_key(user_key, None)
|
511
|
+
widget_ids = ctx.widget_ids_this_run
|
512
|
+
form_ids = ctx.form_ids_this_run
|
513
|
+
|
514
|
+
if widget_id in widget_ids or user_key in form_ids:
|
515
|
+
raise StreamlitAPIException(
|
516
|
+
f"`st.session_state.{user_key}` cannot be modified after the widget"
|
517
|
+
f" with key `{user_key}` is instantiated."
|
518
|
+
)
|
519
|
+
|
520
|
+
self._new_session_state[user_key] = value
|
521
|
+
|
522
|
+
def __delitem__(self, key: str) -> None:
|
523
|
+
widget_id = self._get_widget_id(key)
|
524
|
+
|
525
|
+
if not (key in self or widget_id in self):
|
526
|
+
raise KeyError(_missing_key_error_message(key))
|
527
|
+
|
528
|
+
if key in self._new_session_state:
|
529
|
+
del self._new_session_state[key]
|
530
|
+
|
531
|
+
if key in self._old_state:
|
532
|
+
del self._old_state[key]
|
533
|
+
|
534
|
+
if key in self._key_id_mapper:
|
535
|
+
self._key_id_mapper.delete(key)
|
536
|
+
|
537
|
+
if widget_id in self._new_widget_state:
|
538
|
+
del self._new_widget_state[widget_id]
|
539
|
+
|
540
|
+
if widget_id in self._old_state:
|
541
|
+
del self._old_state[widget_id]
|
542
|
+
|
543
|
+
def set_widgets_from_proto(self, widget_states: WidgetStatesProto) -> None:
|
544
|
+
"""Set the value of all widgets represented in the given WidgetStatesProto."""
|
545
|
+
for state in widget_states.widgets:
|
546
|
+
self._new_widget_state.set_widget_from_proto(state)
|
547
|
+
|
548
|
+
def on_script_will_rerun(self, latest_widget_states: WidgetStatesProto) -> None:
|
549
|
+
"""Called by ScriptRunner before its script re-runs.
|
550
|
+
|
551
|
+
Update widget data and call callbacks on widgets whose value changed
|
552
|
+
between the previous and current script runs.
|
553
|
+
"""
|
554
|
+
# Clear any triggers that weren't reset because the script was disconnected
|
555
|
+
self._reset_triggers()
|
556
|
+
self._compact_state()
|
557
|
+
self.set_widgets_from_proto(latest_widget_states)
|
558
|
+
self._call_callbacks()
|
559
|
+
|
560
|
+
def _call_callbacks(self) -> None:
|
561
|
+
"""Call any callback associated with each widget whose value
|
562
|
+
changed between the previous and current script runs.
|
563
|
+
"""
|
564
|
+
from streamlit.runtime.scriptrunner import RerunException
|
565
|
+
|
566
|
+
changed_widget_ids = [
|
567
|
+
wid for wid in self._new_widget_state if self._widget_changed(wid)
|
568
|
+
]
|
569
|
+
for wid in changed_widget_ids:
|
570
|
+
try:
|
571
|
+
self._new_widget_state.call_callback(wid)
|
572
|
+
except RerunException:
|
573
|
+
st.warning("Calling st.rerun() within a callback is a no-op.")
|
574
|
+
|
575
|
+
def _widget_changed(self, widget_id: str) -> bool:
|
576
|
+
"""True if the given widget's value changed between the previous
|
577
|
+
script run and the current script run.
|
578
|
+
"""
|
579
|
+
new_value = self._new_widget_state.get(widget_id)
|
580
|
+
old_value = self._old_state.get(widget_id)
|
581
|
+
changed: bool = new_value != old_value
|
582
|
+
return changed
|
583
|
+
|
584
|
+
def on_script_finished(self, widget_ids_this_run: set[str]) -> None:
|
585
|
+
"""Called by ScriptRunner after its script finishes running.
|
586
|
+
Updates widgets to prepare for the next script run.
|
587
|
+
|
588
|
+
Parameters
|
589
|
+
----------
|
590
|
+
widget_ids_this_run: set[str]
|
591
|
+
The IDs of the widgets that were accessed during the script
|
592
|
+
run. Any widget state whose ID does *not* appear in this set
|
593
|
+
is considered "stale" and will be removed.
|
594
|
+
"""
|
595
|
+
self._reset_triggers()
|
596
|
+
self._remove_stale_widgets(widget_ids_this_run)
|
597
|
+
|
598
|
+
def _reset_triggers(self) -> None:
|
599
|
+
"""Set all trigger values in our state dictionary to False."""
|
600
|
+
for state_id in self._new_widget_state:
|
601
|
+
metadata = self._new_widget_state.widget_metadata.get(state_id)
|
602
|
+
if metadata is not None:
|
603
|
+
if metadata.value_type == "trigger_value":
|
604
|
+
self._new_widget_state[state_id] = Value(False)
|
605
|
+
elif metadata.value_type == "string_trigger_value":
|
606
|
+
self._new_widget_state[state_id] = Value(None)
|
607
|
+
elif metadata.value_type == "chat_input_value":
|
608
|
+
self._new_widget_state[state_id] = Value(None)
|
609
|
+
|
610
|
+
for state_id in self._old_state:
|
611
|
+
metadata = self._new_widget_state.widget_metadata.get(state_id)
|
612
|
+
if metadata is not None:
|
613
|
+
if metadata.value_type == "trigger_value":
|
614
|
+
self._old_state[state_id] = False
|
615
|
+
elif metadata.value_type == "string_trigger_value":
|
616
|
+
self._old_state[state_id] = None
|
617
|
+
elif metadata.value_type == "chat_input_value":
|
618
|
+
self._old_state[state_id] = None
|
619
|
+
|
620
|
+
def _remove_stale_widgets(self, active_widget_ids: set[str]) -> None:
|
621
|
+
"""Remove widget state for widgets whose ids aren't in `active_widget_ids`."""
|
622
|
+
ctx = get_script_run_ctx()
|
623
|
+
if ctx is None:
|
624
|
+
return
|
625
|
+
|
626
|
+
self._new_widget_state.remove_stale_widgets(
|
627
|
+
active_widget_ids,
|
628
|
+
ctx.fragment_ids_this_run,
|
629
|
+
)
|
630
|
+
|
631
|
+
# Remove entries from _old_state corresponding to
|
632
|
+
# widgets not in widget_ids.
|
633
|
+
self._old_state = {
|
634
|
+
k: v
|
635
|
+
for k, v in self._old_state.items()
|
636
|
+
if (
|
637
|
+
not is_element_id(k)
|
638
|
+
or not _is_stale_widget(
|
639
|
+
self._new_widget_state.widget_metadata.get(k),
|
640
|
+
active_widget_ids,
|
641
|
+
ctx.fragment_ids_this_run,
|
642
|
+
)
|
643
|
+
)
|
644
|
+
}
|
645
|
+
|
646
|
+
def _set_widget_metadata(self, widget_metadata: WidgetMetadata[Any]) -> None:
|
647
|
+
"""Set a widget's metadata."""
|
648
|
+
widget_id = widget_metadata.id
|
649
|
+
self._new_widget_state.widget_metadata[widget_id] = widget_metadata
|
650
|
+
|
651
|
+
def get_widget_states(self) -> list[WidgetStateProto]:
|
652
|
+
"""Return a list of serialized widget values for each widget with a value."""
|
653
|
+
return self._new_widget_state.as_widget_states()
|
654
|
+
|
655
|
+
def _get_widget_id(self, k: str) -> str:
|
656
|
+
"""Turns a value that might be a widget id or a user provided key into
|
657
|
+
an appropriate widget id.
|
658
|
+
"""
|
659
|
+
return self._key_id_mapper.get_id_from_key(k, k)
|
660
|
+
|
661
|
+
def _set_key_widget_mapping(self, widget_id: str, user_key: str) -> None:
|
662
|
+
self._key_id_mapper[user_key] = widget_id
|
663
|
+
|
664
|
+
def register_widget(
|
665
|
+
self, metadata: WidgetMetadata[T], user_key: str | None
|
666
|
+
) -> RegisterWidgetResult[T]:
|
667
|
+
"""Register a widget with the SessionState.
|
668
|
+
|
669
|
+
Returns
|
670
|
+
-------
|
671
|
+
RegisterWidgetResult[T]
|
672
|
+
Contains the widget's current value, and a bool that will be True
|
673
|
+
if the frontend needs to be updated with the current value.
|
674
|
+
"""
|
675
|
+
widget_id = metadata.id
|
676
|
+
|
677
|
+
self._set_widget_metadata(metadata)
|
678
|
+
if user_key is not None:
|
679
|
+
# If the widget has a user_key, update its user_key:widget_id mapping
|
680
|
+
self._set_key_widget_mapping(widget_id, user_key)
|
681
|
+
|
682
|
+
if widget_id not in self and (user_key is None or user_key not in self):
|
683
|
+
# This is the first time the widget is registered, so we save its
|
684
|
+
# value in widget state.
|
685
|
+
deserializer = metadata.deserializer
|
686
|
+
initial_widget_value = deepcopy(deserializer(None, metadata.id))
|
687
|
+
self._new_widget_state.set_from_value(widget_id, initial_widget_value)
|
688
|
+
|
689
|
+
# Get the current value of the widget for use as its return value.
|
690
|
+
# We return a copy, so that reference types can't be accidentally
|
691
|
+
# mutated by user code.
|
692
|
+
widget_value = cast(T, self[widget_id])
|
693
|
+
widget_value = deepcopy(widget_value)
|
694
|
+
|
695
|
+
# widget_value_changed indicates to the caller that the widget's
|
696
|
+
# current value is different from what is in the frontend.
|
697
|
+
widget_value_changed = user_key is not None and self.is_new_state_value(
|
698
|
+
user_key
|
699
|
+
)
|
700
|
+
|
701
|
+
return RegisterWidgetResult(widget_value, widget_value_changed)
|
702
|
+
|
703
|
+
def __contains__(self, key: str) -> bool:
|
704
|
+
try:
|
705
|
+
self[key]
|
706
|
+
except KeyError:
|
707
|
+
return False
|
708
|
+
else:
|
709
|
+
return True
|
710
|
+
|
711
|
+
def get_stats(self) -> list[CacheStat]:
|
712
|
+
# Lazy-load vendored package to prevent import of numpy
|
713
|
+
from streamlit.vendor.pympler.asizeof import asizeof
|
714
|
+
|
715
|
+
stat = CacheStat("st_session_state", "", asizeof(self))
|
716
|
+
return [stat]
|
717
|
+
|
718
|
+
def _check_serializable(self) -> None:
|
719
|
+
"""Verify that everything added to session state can be serialized.
|
720
|
+
We use pickleability as the metric for serializability, and test for
|
721
|
+
pickleability by just trying it.
|
722
|
+
"""
|
723
|
+
for k in self:
|
724
|
+
try:
|
725
|
+
pickle.dumps(self[k])
|
726
|
+
except Exception as e:
|
727
|
+
err_msg = f"""Cannot serialize the value (of type `{type(self[k])}`) of '{k}' in st.session_state.
|
728
|
+
Streamlit has been configured to use [pickle](https://docs.python.org/3/library/pickle.html) to
|
729
|
+
serialize session_state values. Please convert the value to a pickle-serializable type. To learn
|
730
|
+
more about this behavior, see [our docs](https://docs.streamlit.io/knowledge-base/using-streamlit/serializable-session-state). """
|
731
|
+
raise UnserializableSessionStateError(err_msg) from e
|
732
|
+
|
733
|
+
def maybe_check_serializable(self) -> None:
|
734
|
+
"""Verify that session state can be serialized, if the relevant config
|
735
|
+
option is set.
|
736
|
+
|
737
|
+
See `_check_serializable` for details."""
|
738
|
+
if config.get_option("runner.enforceSerializableSessionState"):
|
739
|
+
self._check_serializable()
|
740
|
+
|
741
|
+
|
742
|
+
def _is_internal_key(key: str) -> bool:
|
743
|
+
return key.startswith(STREAMLIT_INTERNAL_KEY_PREFIX)
|
744
|
+
|
745
|
+
|
746
|
+
def _is_stale_widget(
|
747
|
+
metadata: WidgetMetadata[Any] | None,
|
748
|
+
active_widget_ids: set[str],
|
749
|
+
fragment_ids_this_run: list[str] | None,
|
750
|
+
) -> bool:
|
751
|
+
if not metadata:
|
752
|
+
return True
|
753
|
+
elif metadata.id in active_widget_ids:
|
754
|
+
return False
|
755
|
+
# If we're running 1 or more fragments, but this widget is unrelated to any of the
|
756
|
+
# fragments that we're running, then it should not be marked as stale as its value
|
757
|
+
# may still be needed for a future fragment run or full script run.
|
758
|
+
elif fragment_ids_this_run and metadata.fragment_id not in fragment_ids_this_run:
|
759
|
+
return False
|
760
|
+
return True
|
761
|
+
|
762
|
+
|
763
|
+
@dataclass
|
764
|
+
class SessionStateStatProvider(CacheStatsProvider):
|
765
|
+
_session_mgr: SessionManager
|
766
|
+
|
767
|
+
def get_stats(self) -> list[CacheStat]:
|
768
|
+
stats: list[CacheStat] = []
|
769
|
+
for session_info in self._session_mgr.list_active_sessions():
|
770
|
+
session_state = session_info.session.session_state
|
771
|
+
stats.extend(session_state.get_stats())
|
772
|
+
return group_stats(stats)
|