streamlit-data-editor-plus 0.1.0__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 +292 -0
- streamlit/__main__.py +20 -0
- streamlit/auth_util.py +583 -0
- streamlit/cli_util.py +107 -0
- streamlit/column_config.py +60 -0
- streamlit/commands/__init__.py +13 -0
- streamlit/commands/echo.py +128 -0
- streamlit/commands/execution_control.py +318 -0
- streamlit/commands/logo.py +250 -0
- streamlit/commands/navigation.py +430 -0
- streamlit/commands/page_config.py +335 -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 +158 -0
- streamlit/components/v1/__init__.py +29 -0
- streamlit/components/v1/component_arrow.py +141 -0
- streamlit/components/v1/component_registry.py +147 -0
- streamlit/components/v1/components.py +38 -0
- streamlit/components/v1/custom_component.py +239 -0
- streamlit/components/v2/__init__.py +531 -0
- streamlit/components/v2/bidi_component/__init__.py +20 -0
- streamlit/components/v2/bidi_component/constants.py +29 -0
- streamlit/components/v2/bidi_component/main.py +537 -0
- streamlit/components/v2/bidi_component/serialization.py +272 -0
- streamlit/components/v2/bidi_component/state.py +92 -0
- streamlit/components/v2/component_definition_resolver.py +143 -0
- streamlit/components/v2/component_file_watcher.py +403 -0
- streamlit/components/v2/component_manager.py +439 -0
- streamlit/components/v2/component_manifest_handler.py +122 -0
- streamlit/components/v2/component_path_utils.py +233 -0
- streamlit/components/v2/component_registry.py +426 -0
- streamlit/components/v2/get_bidi_component_manager.py +51 -0
- streamlit/components/v2/manifest_scanner.py +620 -0
- streamlit/components/v2/presentation.py +198 -0
- streamlit/components/v2/types.py +317 -0
- streamlit/config.py +2977 -0
- streamlit/config_option.py +319 -0
- streamlit/config_util.py +887 -0
- streamlit/connections/__init__.py +32 -0
- streamlit/connections/base_connection.py +215 -0
- streamlit/connections/snowflake_connection.py +765 -0
- streamlit/connections/snowpark_connection.py +213 -0
- streamlit/connections/sql_connection.py +427 -0
- streamlit/connections/util.py +97 -0
- streamlit/cursor.py +314 -0
- streamlit/dataframe_util.py +1434 -0
- streamlit/delta_generator.py +696 -0
- streamlit/delta_generator_singletons.py +243 -0
- streamlit/deprecation_util.py +253 -0
- streamlit/development.py +21 -0
- streamlit/elements/__init__.py +13 -0
- streamlit/elements/alert.py +341 -0
- streamlit/elements/arrow.py +1065 -0
- streamlit/elements/balloons.py +47 -0
- streamlit/elements/bokeh_chart.py +75 -0
- streamlit/elements/code.py +154 -0
- streamlit/elements/deck_gl_json_chart.py +627 -0
- streamlit/elements/dialog_decorator.py +320 -0
- streamlit/elements/empty.py +130 -0
- streamlit/elements/exception.py +370 -0
- streamlit/elements/form.py +481 -0
- streamlit/elements/graphviz_chart.py +226 -0
- streamlit/elements/heading.py +407 -0
- streamlit/elements/help.py +565 -0
- streamlit/elements/html.py +189 -0
- streamlit/elements/iframe.py +245 -0
- streamlit/elements/image.py +221 -0
- streamlit/elements/json.py +171 -0
- streamlit/elements/layouts.py +1534 -0
- streamlit/elements/lib/__init__.py +13 -0
- streamlit/elements/lib/built_in_chart_utils.py +1316 -0
- streamlit/elements/lib/color_util.py +272 -0
- streamlit/elements/lib/column_config_utils.py +555 -0
- streamlit/elements/lib/column_types.py +2699 -0
- streamlit/elements/lib/dialog.py +212 -0
- streamlit/elements/lib/dicttools.py +152 -0
- streamlit/elements/lib/file_uploader_utils.py +91 -0
- streamlit/elements/lib/form_utils.py +77 -0
- streamlit/elements/lib/image_utils.py +447 -0
- streamlit/elements/lib/js_number.py +105 -0
- streamlit/elements/lib/layout_utils.py +325 -0
- streamlit/elements/lib/mutable_expander_container.py +73 -0
- streamlit/elements/lib/mutable_popover_container.py +73 -0
- streamlit/elements/lib/mutable_status_container.py +194 -0
- streamlit/elements/lib/mutable_tab_container.py +73 -0
- streamlit/elements/lib/options_selector_utils.py +480 -0
- streamlit/elements/lib/pandas_styler_utils.py +302 -0
- streamlit/elements/lib/policies.py +198 -0
- streamlit/elements/lib/shortcut_utils.py +152 -0
- streamlit/elements/lib/streamlit_plotly_theme.py +206 -0
- streamlit/elements/lib/subtitle_utils.py +175 -0
- streamlit/elements/lib/utils.py +274 -0
- streamlit/elements/map.py +526 -0
- streamlit/elements/markdown.py +529 -0
- streamlit/elements/media.py +843 -0
- streamlit/elements/metric.py +529 -0
- streamlit/elements/pdf.py +190 -0
- streamlit/elements/plotly_chart.py +779 -0
- streamlit/elements/progress.py +172 -0
- streamlit/elements/pyplot.py +240 -0
- streamlit/elements/snow.py +47 -0
- streamlit/elements/space.py +121 -0
- streamlit/elements/spinner.py +152 -0
- streamlit/elements/table.py +240 -0
- streamlit/elements/text.py +113 -0
- streamlit/elements/toast.py +175 -0
- streamlit/elements/vega_charts.py +2510 -0
- streamlit/elements/widgets/__init__.py +13 -0
- streamlit/elements/widgets/audio_input.py +334 -0
- streamlit/elements/widgets/button.py +1559 -0
- streamlit/elements/widgets/button_group.py +1061 -0
- streamlit/elements/widgets/camera_input.py +281 -0
- streamlit/elements/widgets/chat.py +1028 -0
- streamlit/elements/widgets/checkbox.py +420 -0
- streamlit/elements/widgets/color_picker.py +329 -0
- streamlit/elements/widgets/data_editor.py +1168 -0
- streamlit/elements/widgets/data_editor_plus.py +902 -0
- streamlit/elements/widgets/feedback.py +322 -0
- streamlit/elements/widgets/file_uploader.py +592 -0
- streamlit/elements/widgets/multiselect.py +654 -0
- streamlit/elements/widgets/number_input.py +719 -0
- streamlit/elements/widgets/radio.py +551 -0
- streamlit/elements/widgets/select_slider.py +568 -0
- streamlit/elements/widgets/selectbox.py +680 -0
- streamlit/elements/widgets/slider.py +1093 -0
- streamlit/elements/widgets/text_widgets.py +779 -0
- streamlit/elements/widgets/time_widgets.py +1712 -0
- streamlit/elements/write.py +585 -0
- streamlit/emojis.py +34 -0
- streamlit/env_util.py +56 -0
- streamlit/error_util.py +112 -0
- streamlit/errors.py +680 -0
- streamlit/external/__init__.py +13 -0
- streamlit/external/langchain/__init__.py +23 -0
- streamlit/external/langchain/streamlit_callback_handler.py +410 -0
- streamlit/file_util.py +266 -0
- streamlit/git_util.py +200 -0
- streamlit/hello/__init__.py +13 -0
- streamlit/hello/__pycache__/__init__.cpython-312.pyc +0 -0
- streamlit/hello/__pycache__/streamlit_app.cpython-312.pyc +0 -0
- streamlit/hello/animation_demo.py +82 -0
- streamlit/hello/dataframe_demo.py +71 -0
- streamlit/hello/hello.py +46 -0
- streamlit/hello/mapping_demo.py +113 -0
- streamlit/hello/plotting_demo.py +62 -0
- streamlit/hello/streamlit_app.py +57 -0
- streamlit/hello/utils.py +30 -0
- streamlit/logger.py +129 -0
- streamlit/material_icon_names.py +25 -0
- streamlit/navigation/__init__.py +13 -0
- streamlit/navigation/page.py +365 -0
- streamlit/net_util.py +125 -0
- streamlit/path_security.py +98 -0
- streamlit/platform.py +31 -0
- streamlit/proto/Alert_pb2.py +28 -0
- streamlit/proto/Alert_pb2.pyi +100 -0
- streamlit/proto/AppPage_pb2.py +25 -0
- streamlit/proto/AppPage_pb2.pyi +75 -0
- streamlit/proto/ArrowData_pb2.py +27 -0
- streamlit/proto/ArrowData_pb2.pyi +103 -0
- streamlit/proto/ArrowNamedDataSet_pb2.py +26 -0
- streamlit/proto/ArrowNamedDataSet_pb2.pyi +65 -0
- streamlit/proto/AudioInput_pb2.py +26 -0
- streamlit/proto/AudioInput_pb2.pyi +72 -0
- streamlit/proto/Audio_pb2.py +26 -0
- streamlit/proto/Audio_pb2.pyi +75 -0
- streamlit/proto/AuthRedirect_pb2.py +25 -0
- streamlit/proto/AuthRedirect_pb2.pyi +48 -0
- streamlit/proto/AutoRerun_pb2.py +25 -0
- streamlit/proto/AutoRerun_pb2.pyi +52 -0
- streamlit/proto/BackMsg_pb2.py +29 -0
- streamlit/proto/BackMsg_pb2.pyi +132 -0
- streamlit/proto/Balloons_pb2.py +25 -0
- streamlit/proto/Balloons_pb2.pyi +48 -0
- streamlit/proto/BidiComponent_pb2.py +32 -0
- streamlit/proto/BidiComponent_pb2.pyi +176 -0
- streamlit/proto/Block_pb2.py +62 -0
- streamlit/proto/Block_pb2.pyi +518 -0
- streamlit/proto/ButtonGroup_pb2.py +32 -0
- streamlit/proto/ButtonGroup_pb2.pyi +157 -0
- streamlit/proto/ButtonLikeIconPosition_pb2.py +25 -0
- streamlit/proto/ButtonLikeIconPosition_pb2.pyi +47 -0
- streamlit/proto/Button_pb2.py +26 -0
- streamlit/proto/Button_pb2.pyi +82 -0
- streamlit/proto/CameraInput_pb2.py +26 -0
- streamlit/proto/CameraInput_pb2.pyi +66 -0
- streamlit/proto/ChatInput_pb2.py +27 -0
- streamlit/proto/ChatInput_pb2.pyi +113 -0
- streamlit/proto/Checkbox_pb2.py +28 -0
- streamlit/proto/Checkbox_pb2.pyi +99 -0
- streamlit/proto/ClientState_pb2.py +28 -0
- streamlit/proto/ClientState_pb2.pyi +137 -0
- streamlit/proto/Code_pb2.py +25 -0
- streamlit/proto/Code_pb2.pyi +59 -0
- streamlit/proto/ColorPicker_pb2.py +26 -0
- streamlit/proto/ColorPicker_pb2.pyi +82 -0
- streamlit/proto/Common_pb2.py +49 -0
- streamlit/proto/Common_pb2.pyi +325 -0
- streamlit/proto/Components_pb2.py +33 -0
- streamlit/proto/Components_pb2.pyi +196 -0
- streamlit/proto/Dataframe_pb2.py +30 -0
- streamlit/proto/Dataframe_pb2.pyi +172 -0
- streamlit/proto/DateInput_pb2.py +26 -0
- streamlit/proto/DateInput_pb2.pyi +91 -0
- streamlit/proto/DateTimeInput_pb2.py +26 -0
- streamlit/proto/DateTimeInput_pb2.pyi +94 -0
- streamlit/proto/DeckGlJsonChart_pb2.py +27 -0
- streamlit/proto/DeckGlJsonChart_pb2.pyi +91 -0
- streamlit/proto/Delta_pb2.py +29 -0
- streamlit/proto/Delta_pb2.pyi +82 -0
- streamlit/proto/DownloadButton_pb2.py +26 -0
- streamlit/proto/DownloadButton_pb2.pyi +92 -0
- streamlit/proto/Element_pb2.py +81 -0
- streamlit/proto/Element_pb2.pyi +348 -0
- streamlit/proto/Empty_pb2.py +25 -0
- streamlit/proto/Empty_pb2.pyi +42 -0
- streamlit/proto/Exception_pb2.py +26 -0
- streamlit/proto/Exception_pb2.pyi +88 -0
- streamlit/proto/Favicon_pb2.py +25 -0
- streamlit/proto/Favicon_pb2.pyi +47 -0
- streamlit/proto/Feedback_pb2.py +27 -0
- streamlit/proto/Feedback_pb2.pyi +93 -0
- streamlit/proto/FileUploader_pb2.py +26 -0
- streamlit/proto/FileUploader_pb2.pyi +90 -0
- streamlit/proto/ForwardMsg_pb2.py +48 -0
- streamlit/proto/ForwardMsg_pb2.pyi +296 -0
- streamlit/proto/GapSize_pb2.py +27 -0
- streamlit/proto/GapSize_pb2.pyi +82 -0
- streamlit/proto/GitInfo_pb2.py +27 -0
- streamlit/proto/GitInfo_pb2.pyi +84 -0
- streamlit/proto/GraphVizChart_pb2.py +25 -0
- streamlit/proto/GraphVizChart_pb2.pyi +56 -0
- streamlit/proto/Heading_pb2.py +25 -0
- streamlit/proto/Heading_pb2.pyi +63 -0
- streamlit/proto/HeightConfig_pb2.py +25 -0
- streamlit/proto/HeightConfig_pb2.pyi +61 -0
- streamlit/proto/Help_pb2.py +27 -0
- streamlit/proto/Help_pb2.pyi +104 -0
- streamlit/proto/Html_pb2.py +25 -0
- streamlit/proto/Html_pb2.pyi +52 -0
- streamlit/proto/IFrame_pb2.py +25 -0
- streamlit/proto/IFrame_pb2.pyi +68 -0
- streamlit/proto/Image_pb2.py +27 -0
- streamlit/proto/Image_pb2.pyi +73 -0
- streamlit/proto/Json_pb2.py +25 -0
- streamlit/proto/Json_pb2.pyi +63 -0
- streamlit/proto/LabelVisibility_pb2.py +27 -0
- streamlit/proto/LabelVisibility_pb2.pyi +69 -0
- streamlit/proto/LinkButton_pb2.py +26 -0
- streamlit/proto/LinkButton_pb2.pyi +76 -0
- streamlit/proto/Logo_pb2.py +27 -0
- streamlit/proto/Logo_pb2.pyi +82 -0
- streamlit/proto/Markdown_pb2.py +27 -0
- streamlit/proto/Markdown_pb2.pyi +83 -0
- streamlit/proto/Metric_pb2.py +32 -0
- streamlit/proto/Metric_pb2.pyi +145 -0
- streamlit/proto/MetricsEvent_pb2.py +28 -0
- streamlit/proto/MetricsEvent_pb2.pyi +224 -0
- streamlit/proto/MultiSelect_pb2.py +26 -0
- streamlit/proto/MultiSelect_pb2.pyi +108 -0
- streamlit/proto/Navigation_pb2.py +28 -0
- streamlit/proto/Navigation_pb2.pyi +89 -0
- streamlit/proto/NewSession_pb2.py +47 -0
- streamlit/proto/NewSession_pb2.pyi +753 -0
- streamlit/proto/NumberInput_pb2.py +28 -0
- streamlit/proto/NumberInput_pb2.pyi +138 -0
- streamlit/proto/PageConfig_pb2.py +33 -0
- streamlit/proto/PageConfig_pb2.pyi +179 -0
- streamlit/proto/PageInfo_pb2.py +25 -0
- streamlit/proto/PageInfo_pb2.pyi +50 -0
- streamlit/proto/PageLink_pb2.py +26 -0
- streamlit/proto/PageLink_pb2.pyi +80 -0
- streamlit/proto/PageNotFound_pb2.py +25 -0
- streamlit/proto/PageNotFound_pb2.pyi +49 -0
- streamlit/proto/PageProfile_pb2.py +29 -0
- streamlit/proto/PageProfile_pb2.pyi +146 -0
- streamlit/proto/ParentMessage_pb2.py +25 -0
- streamlit/proto/ParentMessage_pb2.pyi +53 -0
- streamlit/proto/PlotlyChart_pb2.py +27 -0
- streamlit/proto/PlotlyChart_pb2.pyi +96 -0
- streamlit/proto/Progress_pb2.py +25 -0
- streamlit/proto/Progress_pb2.pyi +50 -0
- streamlit/proto/Radio_pb2.py +26 -0
- streamlit/proto/Radio_pb2.pyi +104 -0
- streamlit/proto/RootContainer_pb2.py +25 -0
- streamlit/proto/RootContainer_pb2.pyi +56 -0
- streamlit/proto/Selectbox_pb2.py +26 -0
- streamlit/proto/Selectbox_pb2.pyi +107 -0
- streamlit/proto/SessionEvent_pb2.py +26 -0
- streamlit/proto/SessionEvent_pb2.pyi +72 -0
- streamlit/proto/SessionStatus_pb2.py +25 -0
- streamlit/proto/SessionStatus_pb2.pyi +64 -0
- streamlit/proto/Skeleton_pb2.py +27 -0
- streamlit/proto/Skeleton_pb2.pyi +75 -0
- streamlit/proto/Slider_pb2.py +30 -0
- streamlit/proto/Slider_pb2.pyi +161 -0
- streamlit/proto/Snow_pb2.py +25 -0
- streamlit/proto/Snow_pb2.pyi +48 -0
- streamlit/proto/Space_pb2.py +25 -0
- streamlit/proto/Space_pb2.pyi +48 -0
- streamlit/proto/Spinner_pb2.py +25 -0
- streamlit/proto/Spinner_pb2.pyi +56 -0
- streamlit/proto/Table_pb2.py +28 -0
- streamlit/proto/Table_pb2.pyi +83 -0
- streamlit/proto/TextAlignmentConfig_pb2.py +27 -0
- streamlit/proto/TextAlignmentConfig_pb2.pyi +69 -0
- streamlit/proto/TextArea_pb2.py +26 -0
- streamlit/proto/TextArea_pb2.pyi +97 -0
- streamlit/proto/TextInput_pb2.py +28 -0
- streamlit/proto/TextInput_pb2.pyi +124 -0
- streamlit/proto/Text_pb2.py +25 -0
- streamlit/proto/Text_pb2.pyi +53 -0
- streamlit/proto/TimeInput_pb2.py +26 -0
- streamlit/proto/TimeInput_pb2.pyi +86 -0
- streamlit/proto/Toast_pb2.py +25 -0
- streamlit/proto/Toast_pb2.pyi +64 -0
- streamlit/proto/Transient_pb2.py +26 -0
- streamlit/proto/Transient_pb2.pyi +53 -0
- streamlit/proto/VegaLiteChart_pb2.py +27 -0
- streamlit/proto/VegaLiteChart_pb2.pyi +92 -0
- streamlit/proto/Video_pb2.py +30 -0
- streamlit/proto/Video_pb2.pyi +129 -0
- streamlit/proto/WidgetStates_pb2.py +31 -0
- streamlit/proto/WidgetStates_pb2.pyi +157 -0
- streamlit/proto/WidthConfig_pb2.py +25 -0
- streamlit/proto/WidthConfig_pb2.pyi +61 -0
- streamlit/proto/__init__.py +15 -0
- streamlit/proto/openmetrics_data_model_pb2.py +58 -0
- streamlit/proto/openmetrics_data_model_pb2.pyi +558 -0
- streamlit/py.typed +0 -0
- streamlit/runtime/__init__.py +50 -0
- streamlit/runtime/app_session.py +1302 -0
- streamlit/runtime/caching/__init__.py +118 -0
- streamlit/runtime/caching/cache_data_api.py +775 -0
- streamlit/runtime/caching/cache_errors.py +143 -0
- streamlit/runtime/caching/cache_resource_api.py +756 -0
- streamlit/runtime/caching/cache_type.py +33 -0
- streamlit/runtime/caching/cache_utils.py +601 -0
- streamlit/runtime/caching/cached_message_replay.py +290 -0
- streamlit/runtime/caching/hashing.py +655 -0
- streamlit/runtime/caching/legacy_cache_api.py +170 -0
- streamlit/runtime/caching/storage/__init__.py +29 -0
- streamlit/runtime/caching/storage/cache_storage_protocol.py +236 -0
- streamlit/runtime/caching/storage/dummy_cache_storage.py +60 -0
- streamlit/runtime/caching/storage/in_memory_cache_storage_wrapper.py +159 -0
- streamlit/runtime/caching/storage/local_disk_cache_storage.py +223 -0
- streamlit/runtime/caching/ttl_cleanup_cache.py +85 -0
- streamlit/runtime/connection_factory.py +498 -0
- streamlit/runtime/context.py +449 -0
- streamlit/runtime/context_util.py +49 -0
- streamlit/runtime/credentials.py +355 -0
- streamlit/runtime/download_data_util.py +53 -0
- streamlit/runtime/forward_msg_cache.py +101 -0
- streamlit/runtime/forward_msg_queue.py +263 -0
- streamlit/runtime/fragment.py +441 -0
- streamlit/runtime/media_file_manager.py +409 -0
- streamlit/runtime/media_file_storage.py +143 -0
- streamlit/runtime/memory_media_file_storage.py +201 -0
- streamlit/runtime/memory_session_storage.py +77 -0
- streamlit/runtime/memory_uploaded_file_manager.py +149 -0
- streamlit/runtime/metrics_util.py +612 -0
- streamlit/runtime/pages_manager.py +160 -0
- streamlit/runtime/runtime.py +775 -0
- streamlit/runtime/runtime_util.py +108 -0
- streamlit/runtime/script_data.py +46 -0
- streamlit/runtime/scriptrunner/__init__.py +38 -0
- streamlit/runtime/scriptrunner/exec_code.py +167 -0
- streamlit/runtime/scriptrunner/magic.py +277 -0
- streamlit/runtime/scriptrunner/magic_funcs.py +32 -0
- streamlit/runtime/scriptrunner/script_cache.py +89 -0
- streamlit/runtime/scriptrunner/script_runner.py +805 -0
- streamlit/runtime/scriptrunner_utils/__init__.py +19 -0
- streamlit/runtime/scriptrunner_utils/exceptions.py +44 -0
- streamlit/runtime/scriptrunner_utils/script_requests.py +311 -0
- streamlit/runtime/scriptrunner_utils/script_run_context.py +277 -0
- streamlit/runtime/secrets.py +533 -0
- streamlit/runtime/session_manager.py +430 -0
- streamlit/runtime/state/__init__.py +47 -0
- streamlit/runtime/state/common.py +256 -0
- streamlit/runtime/state/presentation.py +85 -0
- streamlit/runtime/state/query_params.py +767 -0
- streamlit/runtime/state/query_params_proxy.py +222 -0
- streamlit/runtime/state/safe_session_state.py +146 -0
- streamlit/runtime/state/session_state.py +1299 -0
- streamlit/runtime/state/session_state_proxy.py +153 -0
- streamlit/runtime/state/widgets.py +197 -0
- streamlit/runtime/stats.py +356 -0
- streamlit/runtime/theme_util.py +148 -0
- streamlit/runtime/uploaded_file_manager.py +152 -0
- streamlit/runtime/websocket_session_manager.py +301 -0
- streamlit/source_util.py +97 -0
- streamlit/starlette.py +34 -0
- streamlit/string_util.py +264 -0
- streamlit/temporary_directory.py +67 -0
- streamlit/testing/__init__.py +13 -0
- streamlit/testing/v1/__init__.py +17 -0
- streamlit/testing/v1/app_test.py +1089 -0
- streamlit/testing/v1/element_tree.py +2272 -0
- streamlit/testing/v1/local_script_runner.py +176 -0
- streamlit/testing/v1/util.py +61 -0
- streamlit/time_util.py +73 -0
- streamlit/type_util.py +480 -0
- streamlit/url_util.py +120 -0
- streamlit/user_info.py +698 -0
- streamlit/util.py +108 -0
- streamlit/vendor/__init__.py +0 -0
- streamlit/vendor/pympler/__init__.py +0 -0
- streamlit/vendor/pympler/asizeof.py +2870 -0
- streamlit/version.py +18 -0
- streamlit/watcher/__init__.py +28 -0
- streamlit/watcher/event_based_path_watcher.py +500 -0
- streamlit/watcher/folder_black_list.py +82 -0
- streamlit/watcher/local_sources_watcher.py +297 -0
- streamlit/watcher/path_watcher.py +244 -0
- streamlit/watcher/polling_path_watcher.py +138 -0
- streamlit/watcher/util.py +223 -0
- streamlit/web/__init__.py +13 -0
- streamlit/web/bootstrap.py +463 -0
- streamlit/web/cache_storage_manager_config.py +38 -0
- streamlit/web/cli.py +465 -0
- streamlit/web/server/__init__.py +30 -0
- streamlit/web/server/app_discovery.py +422 -0
- streamlit/web/server/app_static_file_handler.py +102 -0
- streamlit/web/server/authlib_tornado_integration.py +125 -0
- streamlit/web/server/bidi_component_request_handler.py +193 -0
- streamlit/web/server/browser_websocket_handler.py +341 -0
- streamlit/web/server/component_file_utils.py +105 -0
- streamlit/web/server/component_request_handler.py +107 -0
- streamlit/web/server/media_file_handler.py +148 -0
- streamlit/web/server/oauth_authlib_routes.py +314 -0
- streamlit/web/server/oidc_mixin.py +138 -0
- streamlit/web/server/routes.py +257 -0
- streamlit/web/server/server.py +555 -0
- streamlit/web/server/server_util.py +235 -0
- streamlit/web/server/starlette/__init__.py +23 -0
- streamlit/web/server/starlette/starlette_app.py +541 -0
- streamlit/web/server/starlette/starlette_app_utils.py +306 -0
- streamlit/web/server/starlette/starlette_auth_routes.py +584 -0
- streamlit/web/server/starlette/starlette_gzip_middleware.py +121 -0
- streamlit/web/server/starlette/starlette_path_security_middleware.py +97 -0
- streamlit/web/server/starlette/starlette_routes.py +884 -0
- streamlit/web/server/starlette/starlette_server.py +496 -0
- streamlit/web/server/starlette/starlette_server_config.py +55 -0
- streamlit/web/server/starlette/starlette_static_routes.py +181 -0
- streamlit/web/server/starlette/starlette_websocket.py +560 -0
- streamlit/web/server/stats_request_handler.py +116 -0
- streamlit/web/server/upload_file_request_handler.py +158 -0
- streamlit/web/server/websocket_headers.py +56 -0
- streamlit_data_editor_plus-0.1.0.dist-info/METADATA +76 -0
- streamlit_data_editor_plus-0.1.0.dist-info/RECORD +456 -0
- streamlit_data_editor_plus-0.1.0.dist-info/WHEEL +5 -0
- streamlit_data_editor_plus-0.1.0.dist-info/entry_points.txt +2 -0
- streamlit_data_editor_plus-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1712 @@
|
|
|
1
|
+
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2026)
|
|
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
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import re
|
|
17
|
+
from collections.abc import Sequence
|
|
18
|
+
from dataclasses import dataclass
|
|
19
|
+
from datetime import date, datetime, time, timedelta
|
|
20
|
+
from textwrap import dedent
|
|
21
|
+
from typing import (
|
|
22
|
+
TYPE_CHECKING,
|
|
23
|
+
Any,
|
|
24
|
+
Final,
|
|
25
|
+
Literal,
|
|
26
|
+
TypeAlias,
|
|
27
|
+
cast,
|
|
28
|
+
overload,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
from streamlit.elements.lib.form_utils import current_form_id
|
|
32
|
+
from streamlit.elements.lib.layout_utils import (
|
|
33
|
+
LayoutConfig,
|
|
34
|
+
WidthWithoutContent,
|
|
35
|
+
validate_width,
|
|
36
|
+
)
|
|
37
|
+
from streamlit.elements.lib.policies import (
|
|
38
|
+
check_widget_policies,
|
|
39
|
+
maybe_raise_label_warnings,
|
|
40
|
+
)
|
|
41
|
+
from streamlit.elements.lib.utils import (
|
|
42
|
+
Key,
|
|
43
|
+
LabelVisibility,
|
|
44
|
+
compute_and_register_element_id,
|
|
45
|
+
get_label_visibility_proto_value,
|
|
46
|
+
to_key,
|
|
47
|
+
)
|
|
48
|
+
from streamlit.errors import StreamlitAPIException
|
|
49
|
+
from streamlit.proto.DateInput_pb2 import DateInput as DateInputProto
|
|
50
|
+
from streamlit.proto.DateTimeInput_pb2 import DateTimeInput as DateTimeInputProto
|
|
51
|
+
from streamlit.proto.TimeInput_pb2 import TimeInput as TimeInputProto
|
|
52
|
+
from streamlit.runtime.metrics_util import gather_metrics
|
|
53
|
+
from streamlit.runtime.scriptrunner import ScriptRunContext, get_script_run_ctx
|
|
54
|
+
from streamlit.runtime.state import (
|
|
55
|
+
WidgetArgs,
|
|
56
|
+
WidgetCallback,
|
|
57
|
+
WidgetKwargs,
|
|
58
|
+
get_session_state,
|
|
59
|
+
register_widget,
|
|
60
|
+
)
|
|
61
|
+
from streamlit.time_util import adjust_years
|
|
62
|
+
|
|
63
|
+
if TYPE_CHECKING:
|
|
64
|
+
from streamlit.delta_generator import DeltaGenerator
|
|
65
|
+
|
|
66
|
+
# Type for things that point to a specific time (even if a default time, though not None).
|
|
67
|
+
TimeValue: TypeAlias = time | datetime | str | Literal["now"]
|
|
68
|
+
DateTimeScalarValue: TypeAlias = datetime | date | time | str | Literal["now"]
|
|
69
|
+
DateTimeValue: TypeAlias = DateTimeScalarValue | None
|
|
70
|
+
|
|
71
|
+
# Type for things that point to a specific date (even if a default date, including None).
|
|
72
|
+
NullableScalarDateValue: TypeAlias = date | datetime | str | Literal["today"] | None
|
|
73
|
+
|
|
74
|
+
# The accepted input value for st.date_input. Can be a date scalar or a date range.
|
|
75
|
+
DateValue: TypeAlias = NullableScalarDateValue | Sequence[NullableScalarDateValue]
|
|
76
|
+
|
|
77
|
+
# The return value of st.date_input.
|
|
78
|
+
DateWidgetRangeReturn: TypeAlias = tuple[()] | tuple[date] | tuple[date, date]
|
|
79
|
+
DateWidgetReturn: TypeAlias = date | DateWidgetRangeReturn | None
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
DEFAULT_STEP_MINUTES: Final = 15
|
|
83
|
+
ALLOWED_DATE_FORMATS: Final = re.compile(
|
|
84
|
+
r"^(YYYY[/.\-]MM[/.\-]DD|DD[/.\-]MM[/.\-]YYYY|MM[/.\-]DD[/.\-]YYYY)$"
|
|
85
|
+
)
|
|
86
|
+
_DATETIME_UI_FORMAT: Final = "%Y/%m/%d, %H:%M"
|
|
87
|
+
_DEFAULT_MIN_BOUND_TIME: Final = time(hour=0, minute=0)
|
|
88
|
+
_DEFAULT_MAX_BOUND_TIME: Final = time(hour=23, minute=59)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _convert_timelike_to_time(value: TimeValue) -> time:
|
|
92
|
+
if value == "now":
|
|
93
|
+
# Set value default.
|
|
94
|
+
return datetime.now().time().replace(second=0, microsecond=0)
|
|
95
|
+
|
|
96
|
+
if isinstance(value, str):
|
|
97
|
+
try:
|
|
98
|
+
return time.fromisoformat(value)
|
|
99
|
+
except ValueError:
|
|
100
|
+
try:
|
|
101
|
+
return (
|
|
102
|
+
datetime.fromisoformat(value)
|
|
103
|
+
.time()
|
|
104
|
+
.replace(second=0, microsecond=0)
|
|
105
|
+
)
|
|
106
|
+
except ValueError:
|
|
107
|
+
# We throw an error below.
|
|
108
|
+
pass
|
|
109
|
+
|
|
110
|
+
if isinstance(value, datetime):
|
|
111
|
+
return value.time().replace(second=0, microsecond=0)
|
|
112
|
+
|
|
113
|
+
if isinstance(value, time):
|
|
114
|
+
return value
|
|
115
|
+
|
|
116
|
+
raise StreamlitAPIException(
|
|
117
|
+
"The type of value should be one of datetime, time, ISO string or None"
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _convert_datelike_to_date(
|
|
122
|
+
value: NullableScalarDateValue,
|
|
123
|
+
) -> date:
|
|
124
|
+
if isinstance(value, datetime):
|
|
125
|
+
return value.date()
|
|
126
|
+
|
|
127
|
+
if isinstance(value, date):
|
|
128
|
+
return value
|
|
129
|
+
|
|
130
|
+
if value == "today":
|
|
131
|
+
return datetime.now().date()
|
|
132
|
+
|
|
133
|
+
if isinstance(value, str):
|
|
134
|
+
try:
|
|
135
|
+
return date.fromisoformat(value)
|
|
136
|
+
except ValueError:
|
|
137
|
+
try:
|
|
138
|
+
return datetime.fromisoformat(value).date()
|
|
139
|
+
except ValueError:
|
|
140
|
+
# We throw an error below.
|
|
141
|
+
pass
|
|
142
|
+
|
|
143
|
+
raise StreamlitAPIException(
|
|
144
|
+
'Date value should either be an date/datetime or an ISO string or "today"'
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _parse_date_value(value: DateValue) -> tuple[list[date] | None, bool]:
|
|
149
|
+
if value is None:
|
|
150
|
+
return None, False
|
|
151
|
+
|
|
152
|
+
value_tuple: Sequence[NullableScalarDateValue]
|
|
153
|
+
|
|
154
|
+
if isinstance(value, Sequence) and not isinstance(value, str):
|
|
155
|
+
is_range = True
|
|
156
|
+
value_tuple = value # ty: ignore[invalid-assignment]
|
|
157
|
+
else:
|
|
158
|
+
is_range = False
|
|
159
|
+
value_tuple = [cast("NullableScalarDateValue", value)]
|
|
160
|
+
|
|
161
|
+
if len(value_tuple) not in {0, 1, 2}:
|
|
162
|
+
raise StreamlitAPIException(
|
|
163
|
+
"DateInput value should either be an date/datetime or a list/tuple of "
|
|
164
|
+
"0 - 2 date/datetime values"
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
parsed_dates = [_convert_datelike_to_date(v) for v in value_tuple]
|
|
168
|
+
|
|
169
|
+
return parsed_dates, is_range
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def _parse_min_date(
|
|
173
|
+
min_value: NullableScalarDateValue,
|
|
174
|
+
parsed_dates: Sequence[date] | None,
|
|
175
|
+
) -> date:
|
|
176
|
+
parsed_min_date: date
|
|
177
|
+
if isinstance(min_value, (datetime, date, str)):
|
|
178
|
+
parsed_min_date = _convert_datelike_to_date(min_value)
|
|
179
|
+
elif min_value is None:
|
|
180
|
+
if parsed_dates:
|
|
181
|
+
parsed_min_date = adjust_years(parsed_dates[0], years=-10)
|
|
182
|
+
else:
|
|
183
|
+
parsed_min_date = adjust_years(date.today(), years=-10)
|
|
184
|
+
else:
|
|
185
|
+
raise StreamlitAPIException(
|
|
186
|
+
"DateInput min should either be a date/datetime or None"
|
|
187
|
+
)
|
|
188
|
+
return parsed_min_date
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def _parse_max_date(
|
|
192
|
+
max_value: NullableScalarDateValue,
|
|
193
|
+
parsed_dates: Sequence[date] | None,
|
|
194
|
+
) -> date:
|
|
195
|
+
parsed_max_date: date
|
|
196
|
+
if isinstance(max_value, (datetime, date, str)):
|
|
197
|
+
parsed_max_date = _convert_datelike_to_date(max_value)
|
|
198
|
+
elif max_value is None:
|
|
199
|
+
if parsed_dates:
|
|
200
|
+
parsed_max_date = adjust_years(parsed_dates[-1], years=10)
|
|
201
|
+
else:
|
|
202
|
+
parsed_max_date = adjust_years(date.today(), years=10)
|
|
203
|
+
else:
|
|
204
|
+
raise StreamlitAPIException(
|
|
205
|
+
"DateInput max should either be a date/datetime or None"
|
|
206
|
+
)
|
|
207
|
+
return parsed_max_date
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def _normalize_time(value: time) -> time:
|
|
211
|
+
"""Return a time without seconds, microseconds, or timezone info."""
|
|
212
|
+
return value.replace(second=0, microsecond=0, tzinfo=None)
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def _normalize_datetime_value(value: datetime) -> datetime:
|
|
216
|
+
"""Return a datetime without seconds, microseconds, or timezone info."""
|
|
217
|
+
if value.tzinfo is not None:
|
|
218
|
+
value = value.replace(tzinfo=None)
|
|
219
|
+
return value.replace(second=0, microsecond=0)
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def _combine_date_time(component_date: date, component_time: time) -> datetime:
|
|
223
|
+
"""Combine a date and time into a normalized datetime."""
|
|
224
|
+
return datetime.combine(component_date, _normalize_time(component_time))
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def _try_parse_datetime_with_format(value: str, fmt: str) -> datetime | None:
|
|
228
|
+
"""Try to parse a datetime string with a specific format."""
|
|
229
|
+
try:
|
|
230
|
+
return datetime.strptime(value, fmt)
|
|
231
|
+
except ValueError:
|
|
232
|
+
return None
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def _convert_datetimelike_to_datetime(
|
|
236
|
+
value: DateTimeScalarValue,
|
|
237
|
+
*,
|
|
238
|
+
fallback_date: date,
|
|
239
|
+
fallback_time: time,
|
|
240
|
+
) -> datetime:
|
|
241
|
+
"""Convert supported datetime inputs into a normalized datetime."""
|
|
242
|
+
fallback_time = _normalize_time(fallback_time)
|
|
243
|
+
|
|
244
|
+
if value == "now":
|
|
245
|
+
return _normalize_datetime_value(datetime.now())
|
|
246
|
+
|
|
247
|
+
if isinstance(value, datetime):
|
|
248
|
+
return _normalize_datetime_value(value)
|
|
249
|
+
|
|
250
|
+
if isinstance(value, date) and not isinstance(value, datetime):
|
|
251
|
+
return _combine_date_time(value, fallback_time)
|
|
252
|
+
|
|
253
|
+
if isinstance(value, time):
|
|
254
|
+
return _combine_date_time(fallback_date, value)
|
|
255
|
+
|
|
256
|
+
if isinstance(value, str):
|
|
257
|
+
stripped_value = value.strip()
|
|
258
|
+
|
|
259
|
+
try:
|
|
260
|
+
parsed_dt = datetime.fromisoformat(stripped_value)
|
|
261
|
+
return _normalize_datetime_value(parsed_dt)
|
|
262
|
+
except ValueError:
|
|
263
|
+
pass
|
|
264
|
+
|
|
265
|
+
for fmt in (
|
|
266
|
+
"%Y/%m/%d %H:%M",
|
|
267
|
+
"%Y/%m/%d %H:%M:%S",
|
|
268
|
+
"%Y-%m-%d %H:%M",
|
|
269
|
+
"%Y-%m-%d %H:%M:%S",
|
|
270
|
+
):
|
|
271
|
+
maybe_parsed_dt = _try_parse_datetime_with_format(stripped_value, fmt)
|
|
272
|
+
if maybe_parsed_dt is not None:
|
|
273
|
+
return _normalize_datetime_value(maybe_parsed_dt)
|
|
274
|
+
|
|
275
|
+
try:
|
|
276
|
+
parsed_date = date.fromisoformat(stripped_value)
|
|
277
|
+
return _combine_date_time(parsed_date, fallback_time)
|
|
278
|
+
except ValueError:
|
|
279
|
+
pass
|
|
280
|
+
|
|
281
|
+
try:
|
|
282
|
+
parsed_time = time.fromisoformat(stripped_value)
|
|
283
|
+
return _combine_date_time(fallback_date, parsed_time)
|
|
284
|
+
except ValueError:
|
|
285
|
+
pass
|
|
286
|
+
|
|
287
|
+
raise StreamlitAPIException(
|
|
288
|
+
"The type of value should be one of datetime, date, time, ISO string, or 'now'."
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
def _default_min_datetime(base_date: date) -> datetime:
|
|
293
|
+
return _combine_date_time(
|
|
294
|
+
adjust_years(base_date, years=-10), _DEFAULT_MIN_BOUND_TIME
|
|
295
|
+
)
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
def _default_max_datetime(base_date: date) -> datetime:
|
|
299
|
+
return _combine_date_time(
|
|
300
|
+
adjust_years(base_date, years=10), _DEFAULT_MAX_BOUND_TIME
|
|
301
|
+
)
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
def _datetime_to_proto_string(value: datetime) -> str:
|
|
305
|
+
return _normalize_datetime_value(value).strftime(_DATETIME_UI_FORMAT)
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
@dataclass(frozen=True)
|
|
309
|
+
class _DateTimeInputValues:
|
|
310
|
+
value: datetime | None
|
|
311
|
+
min: datetime
|
|
312
|
+
max: datetime
|
|
313
|
+
|
|
314
|
+
@classmethod
|
|
315
|
+
def from_raw_values(
|
|
316
|
+
cls,
|
|
317
|
+
value: DateTimeValue,
|
|
318
|
+
min_value: DateTimeValue,
|
|
319
|
+
max_value: DateTimeValue,
|
|
320
|
+
) -> _DateTimeInputValues:
|
|
321
|
+
parsed_value = (
|
|
322
|
+
None
|
|
323
|
+
if value is None
|
|
324
|
+
else _convert_datetimelike_to_datetime(
|
|
325
|
+
value,
|
|
326
|
+
fallback_date=date.today(),
|
|
327
|
+
fallback_time=_DEFAULT_MIN_BOUND_TIME,
|
|
328
|
+
)
|
|
329
|
+
)
|
|
330
|
+
|
|
331
|
+
base_date_for_bounds = (
|
|
332
|
+
parsed_value.date() if parsed_value is not None else date.today()
|
|
333
|
+
)
|
|
334
|
+
|
|
335
|
+
parsed_min = (
|
|
336
|
+
_default_min_datetime(base_date_for_bounds)
|
|
337
|
+
if min_value is None
|
|
338
|
+
else _convert_datetimelike_to_datetime(
|
|
339
|
+
min_value,
|
|
340
|
+
fallback_date=base_date_for_bounds,
|
|
341
|
+
fallback_time=_DEFAULT_MIN_BOUND_TIME,
|
|
342
|
+
)
|
|
343
|
+
)
|
|
344
|
+
|
|
345
|
+
parsed_max = (
|
|
346
|
+
_default_max_datetime(base_date_for_bounds)
|
|
347
|
+
if max_value is None
|
|
348
|
+
else _convert_datetimelike_to_datetime(
|
|
349
|
+
max_value,
|
|
350
|
+
fallback_date=base_date_for_bounds,
|
|
351
|
+
fallback_time=_DEFAULT_MAX_BOUND_TIME,
|
|
352
|
+
)
|
|
353
|
+
)
|
|
354
|
+
|
|
355
|
+
return cls(
|
|
356
|
+
value=parsed_value,
|
|
357
|
+
min=parsed_min,
|
|
358
|
+
max=parsed_max,
|
|
359
|
+
)
|
|
360
|
+
|
|
361
|
+
def __post_init__(self) -> None:
|
|
362
|
+
if self.min > self.max:
|
|
363
|
+
raise StreamlitAPIException(
|
|
364
|
+
f"The `min_value`, set to {self.min}, shouldn't be larger "
|
|
365
|
+
f"than the `max_value`, set to {self.max}."
|
|
366
|
+
)
|
|
367
|
+
|
|
368
|
+
if self.value is not None and (self.value < self.min or self.value > self.max):
|
|
369
|
+
raise StreamlitAPIException(
|
|
370
|
+
f"The default `value` of {self.value} must lie between the `min_value` "
|
|
371
|
+
f"of {self.min} and the `max_value` of {self.max}, inclusively."
|
|
372
|
+
)
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
@dataclass(frozen=True)
|
|
376
|
+
class _DateInputValues:
|
|
377
|
+
value: Sequence[date] | None
|
|
378
|
+
is_range: bool
|
|
379
|
+
max: date
|
|
380
|
+
min: date
|
|
381
|
+
|
|
382
|
+
@classmethod
|
|
383
|
+
def from_raw_values(
|
|
384
|
+
cls,
|
|
385
|
+
value: DateValue,
|
|
386
|
+
min_value: NullableScalarDateValue,
|
|
387
|
+
max_value: NullableScalarDateValue,
|
|
388
|
+
) -> _DateInputValues:
|
|
389
|
+
parsed_value, is_range = _parse_date_value(value=value)
|
|
390
|
+
parsed_min = _parse_min_date(
|
|
391
|
+
min_value=min_value,
|
|
392
|
+
parsed_dates=parsed_value,
|
|
393
|
+
)
|
|
394
|
+
parsed_max = _parse_max_date(
|
|
395
|
+
max_value=max_value,
|
|
396
|
+
parsed_dates=parsed_value,
|
|
397
|
+
)
|
|
398
|
+
|
|
399
|
+
if value == "today":
|
|
400
|
+
v = cast("list[date]", parsed_value)[0]
|
|
401
|
+
if v < parsed_min:
|
|
402
|
+
parsed_value = [parsed_min]
|
|
403
|
+
if v > parsed_max:
|
|
404
|
+
parsed_value = [parsed_max]
|
|
405
|
+
|
|
406
|
+
return cls(
|
|
407
|
+
value=parsed_value,
|
|
408
|
+
is_range=is_range,
|
|
409
|
+
min=parsed_min,
|
|
410
|
+
max=parsed_max,
|
|
411
|
+
)
|
|
412
|
+
|
|
413
|
+
def __post_init__(self) -> None:
|
|
414
|
+
if self.min > self.max:
|
|
415
|
+
raise StreamlitAPIException(
|
|
416
|
+
f"The `min_value`, set to {self.min}, shouldn't be larger "
|
|
417
|
+
f"than the `max_value`, set to {self.max}."
|
|
418
|
+
)
|
|
419
|
+
|
|
420
|
+
if self.value:
|
|
421
|
+
start_value = self.value[0]
|
|
422
|
+
end_value = self.value[-1]
|
|
423
|
+
|
|
424
|
+
if (start_value < self.min) or (end_value > self.max):
|
|
425
|
+
raise StreamlitAPIException(
|
|
426
|
+
f"The default `value` of {self.value} "
|
|
427
|
+
f"must lie between the `min_value` of {self.min} "
|
|
428
|
+
f"and the `max_value` of {self.max}, inclusively."
|
|
429
|
+
)
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
@dataclass
|
|
433
|
+
class DateTimeInputSerde:
|
|
434
|
+
value: datetime | None
|
|
435
|
+
min: datetime
|
|
436
|
+
max: datetime
|
|
437
|
+
|
|
438
|
+
def deserialize(self, ui_value: list[str] | None) -> datetime | None:
|
|
439
|
+
if ui_value is not None and len(ui_value) > 0:
|
|
440
|
+
deserialized = _normalize_datetime_value(
|
|
441
|
+
datetime.strptime(ui_value[0], _DATETIME_UI_FORMAT)
|
|
442
|
+
)
|
|
443
|
+
# Validate against min/max bounds
|
|
444
|
+
# If the value is out of bounds, return the previous valid value
|
|
445
|
+
if deserialized < self.min or deserialized > self.max:
|
|
446
|
+
return self.value
|
|
447
|
+
return deserialized
|
|
448
|
+
return self.value
|
|
449
|
+
|
|
450
|
+
def serialize(self, v: datetime | None) -> list[str]:
|
|
451
|
+
if v is None:
|
|
452
|
+
return []
|
|
453
|
+
return [_datetime_to_proto_string(v)]
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
@dataclass
|
|
457
|
+
class TimeInputSerde:
|
|
458
|
+
value: time | None
|
|
459
|
+
|
|
460
|
+
def deserialize(self, ui_value: str | None) -> time | None:
|
|
461
|
+
return (
|
|
462
|
+
datetime.strptime(ui_value, "%H:%M").time()
|
|
463
|
+
if ui_value is not None
|
|
464
|
+
else self.value
|
|
465
|
+
)
|
|
466
|
+
|
|
467
|
+
def serialize(self, v: datetime | time | None) -> str | None:
|
|
468
|
+
if v is None:
|
|
469
|
+
return None
|
|
470
|
+
if isinstance(v, datetime):
|
|
471
|
+
v = v.time()
|
|
472
|
+
return time.strftime(v, "%H:%M")
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
def _validate_date_value(
|
|
476
|
+
current_value: DateWidgetReturn,
|
|
477
|
+
parsed_values: _DateInputValues,
|
|
478
|
+
has_explicit_bounds: bool,
|
|
479
|
+
) -> tuple[DateWidgetReturn, bool]:
|
|
480
|
+
"""Validate current value against min/max bounds and reset if needed.
|
|
481
|
+
|
|
482
|
+
Only validates when has_explicit_bounds is True (user provided min_value or max_value).
|
|
483
|
+
This avoids incorrectly resetting values against computed default bounds.
|
|
484
|
+
|
|
485
|
+
Parameters
|
|
486
|
+
----------
|
|
487
|
+
current_value : DateWidgetReturn
|
|
488
|
+
The current value of the date input widget. Can be a single date, a tuple of
|
|
489
|
+
dates (for range mode), or None.
|
|
490
|
+
parsed_values : _DateInputValues
|
|
491
|
+
Parsed configuration containing min, max, default value, and whether the widget
|
|
492
|
+
is in range mode.
|
|
493
|
+
has_explicit_bounds : bool
|
|
494
|
+
Whether the user explicitly provided min_value or max_value. If False, validation
|
|
495
|
+
is skipped to avoid resetting against computed default bounds.
|
|
496
|
+
|
|
497
|
+
Returns
|
|
498
|
+
-------
|
|
499
|
+
tuple[DateWidgetReturn, bool]
|
|
500
|
+
A tuple of (validated_value, was_reset) where validated_value is either the
|
|
501
|
+
original value (if valid) or the default value (if reset was needed), and
|
|
502
|
+
was_reset indicates whether a reset occurred.
|
|
503
|
+
"""
|
|
504
|
+
value_needs_reset = False
|
|
505
|
+
|
|
506
|
+
if current_value is None or not has_explicit_bounds:
|
|
507
|
+
return current_value, value_needs_reset
|
|
508
|
+
|
|
509
|
+
# For range inputs, current_value is a tuple; for single inputs, it's a date
|
|
510
|
+
if (
|
|
511
|
+
parsed_values.is_range
|
|
512
|
+
and isinstance(current_value, tuple)
|
|
513
|
+
and len(current_value) > 0
|
|
514
|
+
):
|
|
515
|
+
# For range mode, check if any date in the tuple is outside bounds.
|
|
516
|
+
# Cast to tuple[date, ...] to satisfy the type checker after the length check.
|
|
517
|
+
non_empty_value = cast("tuple[date, ...]", current_value)
|
|
518
|
+
start_date = non_empty_value[0]
|
|
519
|
+
end_date = non_empty_value[-1] if len(non_empty_value) > 1 else start_date
|
|
520
|
+
if start_date < parsed_values.min or end_date > parsed_values.max:
|
|
521
|
+
value_needs_reset = True
|
|
522
|
+
elif not parsed_values.is_range and isinstance(current_value, date):
|
|
523
|
+
# For single date mode
|
|
524
|
+
if current_value < parsed_values.min or current_value > parsed_values.max:
|
|
525
|
+
value_needs_reset = True
|
|
526
|
+
else:
|
|
527
|
+
# Type mismatch: widget mode doesn't match current value type (e.g., range mode
|
|
528
|
+
# with a single date value or single mode with a tuple). Reset to match the mode.
|
|
529
|
+
value_needs_reset = True
|
|
530
|
+
|
|
531
|
+
if not value_needs_reset:
|
|
532
|
+
return current_value, value_needs_reset
|
|
533
|
+
|
|
534
|
+
# Reset to the default value from parsed_values
|
|
535
|
+
if parsed_values.value is None or len(parsed_values.value) == 0:
|
|
536
|
+
return (() if parsed_values.is_range else None), True
|
|
537
|
+
if not parsed_values.is_range:
|
|
538
|
+
return parsed_values.value[0], True
|
|
539
|
+
return cast("DateWidgetReturn", tuple(parsed_values.value)), True
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
def _validate_datetime_value(
|
|
543
|
+
current_value: datetime | None,
|
|
544
|
+
parsed_values: _DateTimeInputValues,
|
|
545
|
+
has_explicit_bounds: bool,
|
|
546
|
+
) -> tuple[datetime | None, bool]:
|
|
547
|
+
"""Validate current datetime value against min/max bounds and determine if reset is needed.
|
|
548
|
+
|
|
549
|
+
Only validates when has_explicit_bounds is True (user provided min_value or max_value).
|
|
550
|
+
This avoids incorrectly determining if reset is needed against computed default bounds.
|
|
551
|
+
|
|
552
|
+
Parameters
|
|
553
|
+
----------
|
|
554
|
+
current_value : datetime | None
|
|
555
|
+
The current value of the datetime input widget.
|
|
556
|
+
parsed_values : _DateTimeInputValues
|
|
557
|
+
Parsed configuration containing min, max, and default value.
|
|
558
|
+
has_explicit_bounds : bool
|
|
559
|
+
Whether the user explicitly provided min_value or max_value. If False, validation
|
|
560
|
+
is skipped to avoid resetting against computed default bounds.
|
|
561
|
+
|
|
562
|
+
Returns
|
|
563
|
+
-------
|
|
564
|
+
tuple[datetime | None, bool]
|
|
565
|
+
A tuple of (validated_value, was_reset) where validated_value is either the
|
|
566
|
+
original value (if valid) or the default value (if reset was needed), and
|
|
567
|
+
was_reset indicates whether a reset occurred.
|
|
568
|
+
"""
|
|
569
|
+
if current_value is None or not has_explicit_bounds:
|
|
570
|
+
return current_value, False
|
|
571
|
+
|
|
572
|
+
if current_value < parsed_values.min or current_value > parsed_values.max:
|
|
573
|
+
return parsed_values.value, True
|
|
574
|
+
|
|
575
|
+
return current_value, False
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
@dataclass
|
|
579
|
+
class DateInputSerde:
|
|
580
|
+
value: _DateInputValues
|
|
581
|
+
|
|
582
|
+
def deserialize(self, ui_value: Any) -> DateWidgetReturn:
|
|
583
|
+
return_value: Sequence[date] | None
|
|
584
|
+
if ui_value is not None:
|
|
585
|
+
return_value = tuple(
|
|
586
|
+
datetime.strptime(v, "%Y/%m/%d").date() for v in ui_value
|
|
587
|
+
)
|
|
588
|
+
else:
|
|
589
|
+
return_value = self.value.value
|
|
590
|
+
|
|
591
|
+
if return_value is None or len(return_value) == 0:
|
|
592
|
+
return () if self.value.is_range else None
|
|
593
|
+
|
|
594
|
+
if not self.value.is_range:
|
|
595
|
+
return return_value[0]
|
|
596
|
+
return cast("DateWidgetReturn", tuple(return_value))
|
|
597
|
+
|
|
598
|
+
def serialize(self, v: DateWidgetReturn) -> list[str]:
|
|
599
|
+
if v is None:
|
|
600
|
+
return []
|
|
601
|
+
|
|
602
|
+
to_serialize = list(v) if isinstance(v, Sequence) else [v]
|
|
603
|
+
return [date.strftime(v, "%Y/%m/%d") for v in to_serialize]
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
class TimeWidgetsMixin:
|
|
607
|
+
@overload
|
|
608
|
+
def time_input(
|
|
609
|
+
self,
|
|
610
|
+
label: str,
|
|
611
|
+
value: TimeValue = "now",
|
|
612
|
+
key: Key | None = None,
|
|
613
|
+
help: str | None = None,
|
|
614
|
+
on_change: WidgetCallback | None = None,
|
|
615
|
+
args: WidgetArgs | None = None,
|
|
616
|
+
kwargs: WidgetKwargs | None = None,
|
|
617
|
+
*, # keyword-only arguments:
|
|
618
|
+
disabled: bool = False,
|
|
619
|
+
label_visibility: LabelVisibility = "visible",
|
|
620
|
+
step: int | timedelta = timedelta(minutes=DEFAULT_STEP_MINUTES),
|
|
621
|
+
width: WidthWithoutContent = "stretch",
|
|
622
|
+
) -> time:
|
|
623
|
+
pass
|
|
624
|
+
|
|
625
|
+
@overload
|
|
626
|
+
def time_input(
|
|
627
|
+
self,
|
|
628
|
+
label: str,
|
|
629
|
+
value: None = None,
|
|
630
|
+
key: Key | None = None,
|
|
631
|
+
help: str | None = None,
|
|
632
|
+
on_change: WidgetCallback | None = None,
|
|
633
|
+
args: WidgetArgs | None = None,
|
|
634
|
+
kwargs: WidgetKwargs | None = None,
|
|
635
|
+
*, # keyword-only arguments:
|
|
636
|
+
disabled: bool = False,
|
|
637
|
+
label_visibility: LabelVisibility = "visible",
|
|
638
|
+
step: int | timedelta = timedelta(minutes=DEFAULT_STEP_MINUTES),
|
|
639
|
+
width: WidthWithoutContent = "stretch",
|
|
640
|
+
) -> time | None:
|
|
641
|
+
pass
|
|
642
|
+
|
|
643
|
+
@gather_metrics("time_input")
|
|
644
|
+
def time_input(
|
|
645
|
+
self,
|
|
646
|
+
label: str,
|
|
647
|
+
value: TimeValue | None = "now",
|
|
648
|
+
key: Key | None = None,
|
|
649
|
+
help: str | None = None,
|
|
650
|
+
on_change: WidgetCallback | None = None,
|
|
651
|
+
args: WidgetArgs | None = None,
|
|
652
|
+
kwargs: WidgetKwargs | None = None,
|
|
653
|
+
*, # keyword-only arguments:
|
|
654
|
+
disabled: bool = False,
|
|
655
|
+
label_visibility: LabelVisibility = "visible",
|
|
656
|
+
step: int | timedelta = timedelta(minutes=DEFAULT_STEP_MINUTES),
|
|
657
|
+
width: WidthWithoutContent = "stretch",
|
|
658
|
+
) -> time | None:
|
|
659
|
+
r"""Display a time input widget.
|
|
660
|
+
|
|
661
|
+
Parameters
|
|
662
|
+
----------
|
|
663
|
+
label : str
|
|
664
|
+
A short label explaining to the user what this time input is for.
|
|
665
|
+
The label can optionally contain GitHub-flavored Markdown of the
|
|
666
|
+
following types: Bold, Italics, Strikethroughs, Inline Code, Links,
|
|
667
|
+
and Images. Images display like icons, with a max height equal to
|
|
668
|
+
the font height.
|
|
669
|
+
|
|
670
|
+
Unsupported Markdown elements are unwrapped so only their children
|
|
671
|
+
(text contents) render. Display unsupported elements as literal
|
|
672
|
+
characters by backslash-escaping them. E.g.,
|
|
673
|
+
``"1\. Not an ordered list"``.
|
|
674
|
+
|
|
675
|
+
See the ``body`` parameter of |st.markdown|_ for additional,
|
|
676
|
+
supported Markdown directives.
|
|
677
|
+
|
|
678
|
+
For accessibility reasons, you should never set an empty label, but
|
|
679
|
+
you can hide it with ``label_visibility`` if needed. In the future,
|
|
680
|
+
we may disallow empty labels by raising an exception.
|
|
681
|
+
|
|
682
|
+
.. |st.markdown| replace:: ``st.markdown``
|
|
683
|
+
.. _st.markdown: https://docs.streamlit.io/develop/api-reference/text/st.markdown
|
|
684
|
+
|
|
685
|
+
value : "now", datetime.time, datetime.datetime, str, or None
|
|
686
|
+
The value of this widget when it first renders. This can be one of
|
|
687
|
+
the following:
|
|
688
|
+
|
|
689
|
+
- ``"now"`` (default): The widget initializes with the current time.
|
|
690
|
+
- A ``datetime.time`` or ``datetime.datetime`` object: The widget
|
|
691
|
+
initializes with the given time, ignoring any date if included.
|
|
692
|
+
- An ISO-formatted time (hh:mm[:ss.sss]) or datetime
|
|
693
|
+
(YYYY-MM-DD hh:mm[:ss]) string: The widget initializes with the
|
|
694
|
+
given time, ignoring any date if included.
|
|
695
|
+
- ``None``: The widget initializes with no time and returns
|
|
696
|
+
``None`` until the user selects a time.
|
|
697
|
+
|
|
698
|
+
key : str or int
|
|
699
|
+
An optional string or integer to use as the unique key for the widget.
|
|
700
|
+
If this is omitted, a key will be generated for the widget
|
|
701
|
+
based on its content. No two widgets may have the same key.
|
|
702
|
+
|
|
703
|
+
help : str or None
|
|
704
|
+
A tooltip that gets displayed next to the widget label. Streamlit
|
|
705
|
+
only displays the tooltip when ``label_visibility="visible"``. If
|
|
706
|
+
this is ``None`` (default), no tooltip is displayed.
|
|
707
|
+
|
|
708
|
+
The tooltip can optionally contain GitHub-flavored Markdown,
|
|
709
|
+
including the Markdown directives described in the ``body``
|
|
710
|
+
parameter of ``st.markdown``.
|
|
711
|
+
|
|
712
|
+
on_change : callable
|
|
713
|
+
An optional callback invoked when this time_input's value changes.
|
|
714
|
+
|
|
715
|
+
args : list or tuple
|
|
716
|
+
An optional list or tuple of args to pass to the callback.
|
|
717
|
+
|
|
718
|
+
kwargs : dict
|
|
719
|
+
An optional dict of kwargs to pass to the callback.
|
|
720
|
+
|
|
721
|
+
disabled : bool
|
|
722
|
+
An optional boolean that disables the time input if set to
|
|
723
|
+
``True``. The default is ``False``.
|
|
724
|
+
|
|
725
|
+
label_visibility : "visible", "hidden", or "collapsed"
|
|
726
|
+
The visibility of the label. The default is ``"visible"``. If this
|
|
727
|
+
is ``"hidden"``, Streamlit displays an empty spacer instead of the
|
|
728
|
+
label, which can help keep the widget aligned with other widgets.
|
|
729
|
+
If this is ``"collapsed"``, Streamlit displays no label or spacer.
|
|
730
|
+
|
|
731
|
+
step : int or timedelta
|
|
732
|
+
The stepping interval in seconds. This defaults to ``900`` (15
|
|
733
|
+
minutes). You can also pass a ``datetime.timedelta`` object. The
|
|
734
|
+
value must be between 60 seconds and 23 hours.
|
|
735
|
+
|
|
736
|
+
width : "stretch" or int
|
|
737
|
+
The width of the time input widget. This can be one of the following:
|
|
738
|
+
|
|
739
|
+
- ``"stretch"`` (default): The width of the widget matches the
|
|
740
|
+
width of the parent container.
|
|
741
|
+
- An integer specifying the width in pixels: The widget has a
|
|
742
|
+
fixed width. If the specified width is greater than the width of
|
|
743
|
+
the parent container, the width of the widget matches the width
|
|
744
|
+
of the parent container.
|
|
745
|
+
|
|
746
|
+
Returns
|
|
747
|
+
-------
|
|
748
|
+
datetime.time or None
|
|
749
|
+
The current value of the time input widget or ``None`` if no time has been
|
|
750
|
+
selected.
|
|
751
|
+
|
|
752
|
+
Example
|
|
753
|
+
-------
|
|
754
|
+
**Example 1: Basic usage**
|
|
755
|
+
|
|
756
|
+
>>> import datetime
|
|
757
|
+
>>> import streamlit as st
|
|
758
|
+
>>>
|
|
759
|
+
>>> t = st.time_input("Set an alarm for", datetime.time(8, 45))
|
|
760
|
+
>>> st.write("Alarm is set for", t)
|
|
761
|
+
|
|
762
|
+
.. output::
|
|
763
|
+
https://doc-time-input.streamlit.app/
|
|
764
|
+
height: 260px
|
|
765
|
+
|
|
766
|
+
**Example 2: Empty initial value**
|
|
767
|
+
|
|
768
|
+
To initialize an empty time input, use ``None`` as the value:
|
|
769
|
+
|
|
770
|
+
>>> import datetime
|
|
771
|
+
>>> import streamlit as st
|
|
772
|
+
>>>
|
|
773
|
+
>>> t = st.time_input("Set an alarm for", value=None)
|
|
774
|
+
>>> st.write("Alarm is set for", t)
|
|
775
|
+
|
|
776
|
+
.. output::
|
|
777
|
+
https://doc-time-input-empty.streamlit.app/
|
|
778
|
+
height: 260px
|
|
779
|
+
|
|
780
|
+
"""
|
|
781
|
+
ctx = get_script_run_ctx()
|
|
782
|
+
return self._time_input(
|
|
783
|
+
label=label,
|
|
784
|
+
value=value,
|
|
785
|
+
key=key,
|
|
786
|
+
help=help,
|
|
787
|
+
on_change=on_change,
|
|
788
|
+
args=args,
|
|
789
|
+
kwargs=kwargs,
|
|
790
|
+
disabled=disabled,
|
|
791
|
+
label_visibility=label_visibility,
|
|
792
|
+
step=step,
|
|
793
|
+
width=width,
|
|
794
|
+
ctx=ctx,
|
|
795
|
+
)
|
|
796
|
+
|
|
797
|
+
def _time_input(
|
|
798
|
+
self,
|
|
799
|
+
label: str,
|
|
800
|
+
value: TimeValue | None = "now",
|
|
801
|
+
key: Key | None = None,
|
|
802
|
+
help: str | None = None,
|
|
803
|
+
on_change: WidgetCallback | None = None,
|
|
804
|
+
args: WidgetArgs | None = None,
|
|
805
|
+
kwargs: WidgetKwargs | None = None,
|
|
806
|
+
*, # keyword-only arguments:
|
|
807
|
+
disabled: bool = False,
|
|
808
|
+
label_visibility: LabelVisibility = "visible",
|
|
809
|
+
step: int | timedelta = timedelta(minutes=DEFAULT_STEP_MINUTES),
|
|
810
|
+
width: WidthWithoutContent = "stretch",
|
|
811
|
+
ctx: ScriptRunContext | None = None,
|
|
812
|
+
) -> time | None:
|
|
813
|
+
key = to_key(key)
|
|
814
|
+
|
|
815
|
+
check_widget_policies(
|
|
816
|
+
self.dg,
|
|
817
|
+
key,
|
|
818
|
+
on_change,
|
|
819
|
+
default_value=value if value != "now" else None,
|
|
820
|
+
)
|
|
821
|
+
maybe_raise_label_warnings(label, label_visibility)
|
|
822
|
+
|
|
823
|
+
parsed_time: time | None
|
|
824
|
+
parsed_time = None if value is None else _convert_timelike_to_time(value)
|
|
825
|
+
|
|
826
|
+
element_id = compute_and_register_element_id(
|
|
827
|
+
"time_input",
|
|
828
|
+
user_key=key,
|
|
829
|
+
# Ensure stable ID when key is provided; only whitelist step since it
|
|
830
|
+
# affects the selection granularity and available options.
|
|
831
|
+
key_as_main_identity={"step"},
|
|
832
|
+
dg=self.dg,
|
|
833
|
+
label=label,
|
|
834
|
+
value=parsed_time if isinstance(value, (datetime, time)) else value,
|
|
835
|
+
help=help,
|
|
836
|
+
step=step,
|
|
837
|
+
width=width,
|
|
838
|
+
)
|
|
839
|
+
del value
|
|
840
|
+
|
|
841
|
+
session_state = get_session_state().filtered_state
|
|
842
|
+
if key is not None and key in session_state and session_state[key] is None:
|
|
843
|
+
parsed_time = None
|
|
844
|
+
|
|
845
|
+
time_input_proto = TimeInputProto()
|
|
846
|
+
time_input_proto.id = element_id
|
|
847
|
+
time_input_proto.label = label
|
|
848
|
+
if parsed_time is not None:
|
|
849
|
+
time_input_proto.default = time.strftime(parsed_time, "%H:%M")
|
|
850
|
+
time_input_proto.form_id = current_form_id(self.dg)
|
|
851
|
+
if not isinstance(step, (int, timedelta)):
|
|
852
|
+
raise StreamlitAPIException(
|
|
853
|
+
f"`step` can only be `int` or `timedelta` but {type(step)} is provided."
|
|
854
|
+
)
|
|
855
|
+
if isinstance(step, timedelta):
|
|
856
|
+
step = step.seconds
|
|
857
|
+
if step < 60 or step > timedelta(hours=23).seconds:
|
|
858
|
+
raise StreamlitAPIException(
|
|
859
|
+
f"`step` must be between 60 seconds and 23 hours but is currently set to {step} seconds."
|
|
860
|
+
)
|
|
861
|
+
time_input_proto.step = step
|
|
862
|
+
time_input_proto.disabled = disabled
|
|
863
|
+
time_input_proto.label_visibility.value = get_label_visibility_proto_value(
|
|
864
|
+
label_visibility
|
|
865
|
+
)
|
|
866
|
+
|
|
867
|
+
if help is not None:
|
|
868
|
+
time_input_proto.help = dedent(help)
|
|
869
|
+
|
|
870
|
+
serde = TimeInputSerde(parsed_time)
|
|
871
|
+
widget_state = register_widget(
|
|
872
|
+
time_input_proto.id,
|
|
873
|
+
on_change_handler=on_change,
|
|
874
|
+
args=args,
|
|
875
|
+
kwargs=kwargs,
|
|
876
|
+
deserializer=serde.deserialize,
|
|
877
|
+
serializer=serde.serialize,
|
|
878
|
+
ctx=ctx,
|
|
879
|
+
value_type="string_value",
|
|
880
|
+
)
|
|
881
|
+
|
|
882
|
+
if widget_state.value_changed:
|
|
883
|
+
if (serialized_value := serde.serialize(widget_state.value)) is not None:
|
|
884
|
+
time_input_proto.value = serialized_value
|
|
885
|
+
time_input_proto.set_value = True
|
|
886
|
+
|
|
887
|
+
validate_width(width)
|
|
888
|
+
layout_config = LayoutConfig(width=width)
|
|
889
|
+
|
|
890
|
+
self.dg._enqueue("time_input", time_input_proto, layout_config=layout_config)
|
|
891
|
+
return widget_state.value
|
|
892
|
+
|
|
893
|
+
@overload
|
|
894
|
+
def datetime_input(
|
|
895
|
+
self,
|
|
896
|
+
label: str,
|
|
897
|
+
value: None,
|
|
898
|
+
min_value: DateTimeValue = None,
|
|
899
|
+
max_value: DateTimeValue = None,
|
|
900
|
+
*, # keyword-only arguments:
|
|
901
|
+
key: Key | None = None,
|
|
902
|
+
help: str | None = None,
|
|
903
|
+
on_change: WidgetCallback | None = None,
|
|
904
|
+
args: WidgetArgs | None = None,
|
|
905
|
+
kwargs: WidgetKwargs | None = None,
|
|
906
|
+
format: str = "YYYY/MM/DD",
|
|
907
|
+
step: int | timedelta = timedelta(minutes=DEFAULT_STEP_MINUTES),
|
|
908
|
+
disabled: bool = False,
|
|
909
|
+
label_visibility: LabelVisibility = "visible",
|
|
910
|
+
width: WidthWithoutContent = "stretch",
|
|
911
|
+
) -> datetime | None: ...
|
|
912
|
+
|
|
913
|
+
@overload
|
|
914
|
+
def datetime_input(
|
|
915
|
+
self,
|
|
916
|
+
label: str,
|
|
917
|
+
value: DateTimeScalarValue = "now",
|
|
918
|
+
min_value: DateTimeValue = None,
|
|
919
|
+
max_value: DateTimeValue = None,
|
|
920
|
+
*, # keyword-only arguments:
|
|
921
|
+
key: Key | None = None,
|
|
922
|
+
help: str | None = None,
|
|
923
|
+
on_change: WidgetCallback | None = None,
|
|
924
|
+
args: WidgetArgs | None = None,
|
|
925
|
+
kwargs: WidgetKwargs | None = None,
|
|
926
|
+
format: str = "YYYY/MM/DD",
|
|
927
|
+
step: int | timedelta = timedelta(minutes=DEFAULT_STEP_MINUTES),
|
|
928
|
+
disabled: bool = False,
|
|
929
|
+
label_visibility: LabelVisibility = "visible",
|
|
930
|
+
width: WidthWithoutContent = "stretch",
|
|
931
|
+
) -> datetime: ...
|
|
932
|
+
|
|
933
|
+
@gather_metrics("datetime_input")
|
|
934
|
+
def datetime_input(
|
|
935
|
+
self,
|
|
936
|
+
label: str,
|
|
937
|
+
value: DateTimeValue = "now",
|
|
938
|
+
min_value: DateTimeValue = None,
|
|
939
|
+
max_value: DateTimeValue = None,
|
|
940
|
+
*, # keyword-only arguments:
|
|
941
|
+
key: Key | None = None,
|
|
942
|
+
help: str | None = None,
|
|
943
|
+
on_change: WidgetCallback | None = None,
|
|
944
|
+
args: WidgetArgs | None = None,
|
|
945
|
+
kwargs: WidgetKwargs | None = None,
|
|
946
|
+
format: str = "YYYY/MM/DD",
|
|
947
|
+
step: int | timedelta = timedelta(minutes=DEFAULT_STEP_MINUTES),
|
|
948
|
+
disabled: bool = False,
|
|
949
|
+
label_visibility: LabelVisibility = "visible",
|
|
950
|
+
width: WidthWithoutContent = "stretch",
|
|
951
|
+
) -> datetime | None:
|
|
952
|
+
r"""Display a date and time input widget.
|
|
953
|
+
|
|
954
|
+
Parameters
|
|
955
|
+
----------
|
|
956
|
+
label : str
|
|
957
|
+
A short label explaining to the user what this datetime input is for.
|
|
958
|
+
The label can optionally contain GitHub-flavored Markdown of the
|
|
959
|
+
following types: Bold, Italics, Strikethroughs, Inline Code, Links,
|
|
960
|
+
and Images. Images display like icons, with a max height equal to
|
|
961
|
+
the font height.
|
|
962
|
+
|
|
963
|
+
Unsupported Markdown elements are unwrapped so only their children
|
|
964
|
+
(text contents) render. Display unsupported elements as literal
|
|
965
|
+
characters by backslash-escaping them. E.g.,
|
|
966
|
+
``"1\. Not an ordered list"``.
|
|
967
|
+
|
|
968
|
+
See the ``body`` parameter of |st.markdown|_ for additional,
|
|
969
|
+
supported Markdown directives.
|
|
970
|
+
|
|
971
|
+
For accessibility reasons, you should never set an empty label, but
|
|
972
|
+
you can hide it with ``label_visibility`` if needed. In the future,
|
|
973
|
+
we may disallow empty labels by raising an exception.
|
|
974
|
+
|
|
975
|
+
.. |st.markdown| replace:: ``st.markdown``
|
|
976
|
+
.. _st.markdown: https://docs.streamlit.io/develop/api-reference/text/st.markdown
|
|
977
|
+
|
|
978
|
+
value : "now", datetime.datetime, datetime.date, datetime.time, str, or None
|
|
979
|
+
The value of this widget when it first renders. This can be one of
|
|
980
|
+
the following:
|
|
981
|
+
|
|
982
|
+
- ``"now"`` (default): The widget initializes with the current date and time.
|
|
983
|
+
- A ``datetime.datetime`` object: The widget initializes with the given
|
|
984
|
+
datetime, stripping any timezone information.
|
|
985
|
+
- A ``datetime.date`` object: The widget initializes with the given date
|
|
986
|
+
at 00:00.
|
|
987
|
+
- A ``datetime.time`` object: The widget initializes with today's date
|
|
988
|
+
and the provided time.
|
|
989
|
+
- An ISO-formatted datetime (YYYY-MM-DD hh:mm[:ss]) or date/time
|
|
990
|
+
string: The widget initializes with the parsed value.
|
|
991
|
+
- ``None``: The widget initializes with no value and returns ``None``
|
|
992
|
+
until the user selects a datetime.
|
|
993
|
+
|
|
994
|
+
min_value : "now", datetime.datetime, datetime.date, datetime.time, str, or None
|
|
995
|
+
The minimum selectable datetime. This can be any of the datetime
|
|
996
|
+
types accepted by ``value``.
|
|
997
|
+
|
|
998
|
+
If this is ``None`` (default), the minimum selectable datetime is
|
|
999
|
+
ten years before the initial value. If no initial value is set, the
|
|
1000
|
+
minimum selectable datetime is ten years before today at 00:00.
|
|
1001
|
+
|
|
1002
|
+
max_value : "now", datetime.datetime, datetime.date, datetime.time, str, or None
|
|
1003
|
+
The maximum selectable datetime. This can be any of the datetime
|
|
1004
|
+
types accepted by ``value``.
|
|
1005
|
+
|
|
1006
|
+
If this is ``None`` (default), the maximum selectable datetime is
|
|
1007
|
+
ten years after the initial value. If no initial value is set, the
|
|
1008
|
+
maximum selectable datetime is ten years after today at 23:59.
|
|
1009
|
+
|
|
1010
|
+
key : str or int
|
|
1011
|
+
An optional string or integer to use as the unique key for the widget.
|
|
1012
|
+
If this is omitted, a key will be generated for the widget based on its
|
|
1013
|
+
content. No two widgets may have the same key.
|
|
1014
|
+
|
|
1015
|
+
help : str or None
|
|
1016
|
+
A tooltip that gets displayed next to the widget label. Streamlit
|
|
1017
|
+
only displays the tooltip when ``label_visibility="visible"``. If
|
|
1018
|
+
this is ``None`` (default), no tooltip is displayed.
|
|
1019
|
+
|
|
1020
|
+
The tooltip can optionally contain GitHub-flavored Markdown,
|
|
1021
|
+
including the Markdown directives described in the ``body``
|
|
1022
|
+
parameter of ``st.markdown``.
|
|
1023
|
+
|
|
1024
|
+
on_change : callable
|
|
1025
|
+
An optional callback invoked when this datetime_input's value changes.
|
|
1026
|
+
|
|
1027
|
+
args : list or tuple
|
|
1028
|
+
An optional list or tuple of args to pass to the callback.
|
|
1029
|
+
|
|
1030
|
+
kwargs : dict
|
|
1031
|
+
An optional dict of kwargs to pass to the callback.
|
|
1032
|
+
|
|
1033
|
+
format : str
|
|
1034
|
+
A format string controlling how the interface displays dates.
|
|
1035
|
+
Supports ``"YYYY/MM/DD"`` (default), ``"DD/MM/YYYY"``, or ``"MM/DD/YYYY"``.
|
|
1036
|
+
You may also use a period (.) or hyphen (-) as separators. This
|
|
1037
|
+
doesn't affect the time format.
|
|
1038
|
+
|
|
1039
|
+
step : int or timedelta
|
|
1040
|
+
The stepping interval in seconds. This defaults to ``900`` (15
|
|
1041
|
+
minutes). You can also pass a ``datetime.timedelta`` object. The
|
|
1042
|
+
value must be between 60 seconds and 23 hours.
|
|
1043
|
+
|
|
1044
|
+
disabled : bool
|
|
1045
|
+
An optional boolean that disables the widget if set to ``True``.
|
|
1046
|
+
The default is ``False``.
|
|
1047
|
+
|
|
1048
|
+
label_visibility : "visible", "hidden", or "collapsed"
|
|
1049
|
+
The visibility of the label. The default is ``"visible"``. If this
|
|
1050
|
+
is ``"hidden"``, Streamlit displays an empty spacer instead of the
|
|
1051
|
+
label, which can help keep the widget aligned with other widgets.
|
|
1052
|
+
If this is ``"collapsed"``, Streamlit displays no label or spacer.
|
|
1053
|
+
|
|
1054
|
+
width : "stretch" or int
|
|
1055
|
+
The width of the widget. This can be one of the following:
|
|
1056
|
+
|
|
1057
|
+
- ``"stretch"`` (default): The width of the widget matches the width
|
|
1058
|
+
of the parent container.
|
|
1059
|
+
- An integer specifying the width in pixels: The widget has a fixed
|
|
1060
|
+
width. If the specified width is greater than the width of the
|
|
1061
|
+
parent container, the widget matches the container width.
|
|
1062
|
+
|
|
1063
|
+
Returns
|
|
1064
|
+
-------
|
|
1065
|
+
datetime.datetime or None
|
|
1066
|
+
The current value of the datetime input widget (without timezone)
|
|
1067
|
+
or ``None`` if no value has been selected.
|
|
1068
|
+
|
|
1069
|
+
Examples
|
|
1070
|
+
--------
|
|
1071
|
+
**Example 1: Basic usage**
|
|
1072
|
+
|
|
1073
|
+
>>> import datetime
|
|
1074
|
+
>>> import streamlit as st
|
|
1075
|
+
>>>
|
|
1076
|
+
>>> event_time = st.datetime_input(
|
|
1077
|
+
... "Schedule your event",
|
|
1078
|
+
... datetime.datetime(2025, 11, 19, 16, 45),
|
|
1079
|
+
... )
|
|
1080
|
+
>>> st.write("Event scheduled for", event_time)
|
|
1081
|
+
|
|
1082
|
+
.. output::
|
|
1083
|
+
https://doc-datetime-input.streamlit.app/
|
|
1084
|
+
height: 500px
|
|
1085
|
+
|
|
1086
|
+
**Example 2: Empty initial value**
|
|
1087
|
+
|
|
1088
|
+
To initialize an empty datetime input, use ``None`` as the value:
|
|
1089
|
+
|
|
1090
|
+
>>> import datetime
|
|
1091
|
+
>>> import streamlit as st
|
|
1092
|
+
>>>
|
|
1093
|
+
>>> event_time = st.datetime_input("Schedule your event", value=None)
|
|
1094
|
+
>>> st.write("Event scheduled for", event_time)
|
|
1095
|
+
|
|
1096
|
+
.. output::
|
|
1097
|
+
https://doc-datetime-input-empty.streamlit.app/
|
|
1098
|
+
height: 500px
|
|
1099
|
+
|
|
1100
|
+
"""
|
|
1101
|
+
ctx = get_script_run_ctx()
|
|
1102
|
+
return self._datetime_input(
|
|
1103
|
+
label=label,
|
|
1104
|
+
value=value,
|
|
1105
|
+
min_value=min_value,
|
|
1106
|
+
max_value=max_value,
|
|
1107
|
+
key=key,
|
|
1108
|
+
help=help,
|
|
1109
|
+
on_change=on_change,
|
|
1110
|
+
args=args,
|
|
1111
|
+
kwargs=kwargs,
|
|
1112
|
+
format=format,
|
|
1113
|
+
step=step,
|
|
1114
|
+
disabled=disabled,
|
|
1115
|
+
label_visibility=label_visibility,
|
|
1116
|
+
width=width,
|
|
1117
|
+
ctx=ctx,
|
|
1118
|
+
)
|
|
1119
|
+
|
|
1120
|
+
def _datetime_input(
|
|
1121
|
+
self,
|
|
1122
|
+
label: str,
|
|
1123
|
+
value: DateTimeValue = "now",
|
|
1124
|
+
min_value: DateTimeValue = None,
|
|
1125
|
+
max_value: DateTimeValue = None,
|
|
1126
|
+
*, # keyword-only arguments:
|
|
1127
|
+
key: Key | None = None,
|
|
1128
|
+
help: str | None = None,
|
|
1129
|
+
on_change: WidgetCallback | None = None,
|
|
1130
|
+
args: WidgetArgs | None = None,
|
|
1131
|
+
kwargs: WidgetKwargs | None = None,
|
|
1132
|
+
format: str = "YYYY/MM/DD",
|
|
1133
|
+
step: int | timedelta = timedelta(minutes=DEFAULT_STEP_MINUTES),
|
|
1134
|
+
disabled: bool = False,
|
|
1135
|
+
label_visibility: LabelVisibility = "visible",
|
|
1136
|
+
width: WidthWithoutContent = "stretch",
|
|
1137
|
+
ctx: ScriptRunContext | None = None,
|
|
1138
|
+
) -> datetime | None:
|
|
1139
|
+
key = to_key(key)
|
|
1140
|
+
|
|
1141
|
+
check_widget_policies(
|
|
1142
|
+
self.dg,
|
|
1143
|
+
key,
|
|
1144
|
+
on_change,
|
|
1145
|
+
default_value=value if value != "now" else None,
|
|
1146
|
+
)
|
|
1147
|
+
maybe_raise_label_warnings(label, label_visibility)
|
|
1148
|
+
|
|
1149
|
+
datetime_values = _DateTimeInputValues.from_raw_values(
|
|
1150
|
+
value=value,
|
|
1151
|
+
min_value=min_value,
|
|
1152
|
+
max_value=max_value,
|
|
1153
|
+
)
|
|
1154
|
+
|
|
1155
|
+
default_value = datetime_values.value
|
|
1156
|
+
min_value_proto = _datetime_to_proto_string(datetime_values.min)
|
|
1157
|
+
max_value_proto = _datetime_to_proto_string(datetime_values.max)
|
|
1158
|
+
|
|
1159
|
+
if isinstance(value, (datetime, date, time)):
|
|
1160
|
+
value_for_id: Any = (
|
|
1161
|
+
None
|
|
1162
|
+
if default_value is None
|
|
1163
|
+
else _datetime_to_proto_string(default_value)
|
|
1164
|
+
)
|
|
1165
|
+
else:
|
|
1166
|
+
value_for_id = value
|
|
1167
|
+
|
|
1168
|
+
element_id = compute_and_register_element_id(
|
|
1169
|
+
"date_time_input",
|
|
1170
|
+
user_key=key,
|
|
1171
|
+
# Format is whitelisted because of a bug in the BaseWeb date input component.
|
|
1172
|
+
# Step is whitelisted because it invalidates the current selection.
|
|
1173
|
+
# We might be able to unlock this as a follow-up.
|
|
1174
|
+
key_as_main_identity={"format", "step"},
|
|
1175
|
+
dg=self.dg,
|
|
1176
|
+
label=label,
|
|
1177
|
+
value=value_for_id,
|
|
1178
|
+
min_value=min_value_proto,
|
|
1179
|
+
max_value=max_value_proto,
|
|
1180
|
+
help=help,
|
|
1181
|
+
format=format,
|
|
1182
|
+
step=step,
|
|
1183
|
+
width=width,
|
|
1184
|
+
)
|
|
1185
|
+
# Track if user explicitly set bounds (before del)
|
|
1186
|
+
has_explicit_bounds = min_value is not None or max_value is not None
|
|
1187
|
+
del value, min_value, max_value
|
|
1188
|
+
|
|
1189
|
+
if not bool(ALLOWED_DATE_FORMATS.match(format)):
|
|
1190
|
+
raise StreamlitAPIException(
|
|
1191
|
+
f"The provided format (`{format}`) is not valid. DateTimeInput format "
|
|
1192
|
+
"should be one of `YYYY/MM/DD`, `DD/MM/YYYY`, or `MM/DD/YYYY` "
|
|
1193
|
+
"and can also use a period (.) or hyphen (-) as separators."
|
|
1194
|
+
)
|
|
1195
|
+
|
|
1196
|
+
if not isinstance(step, (int, timedelta)):
|
|
1197
|
+
raise StreamlitAPIException(
|
|
1198
|
+
f"`step` can only be `int` or `timedelta` but {type(step)} is provided."
|
|
1199
|
+
)
|
|
1200
|
+
step_seconds = (
|
|
1201
|
+
int(step.total_seconds()) if isinstance(step, timedelta) else step
|
|
1202
|
+
)
|
|
1203
|
+
if step_seconds < 60 or step_seconds > timedelta(hours=23).seconds:
|
|
1204
|
+
raise StreamlitAPIException(
|
|
1205
|
+
f"`step` must be between 60 seconds and 23 hours but is currently set to {step_seconds} seconds."
|
|
1206
|
+
)
|
|
1207
|
+
|
|
1208
|
+
session_state = get_session_state().filtered_state
|
|
1209
|
+
default_value_for_proto = default_value
|
|
1210
|
+
if key is not None and key in session_state and session_state[key] is None:
|
|
1211
|
+
default_value_for_proto = None
|
|
1212
|
+
|
|
1213
|
+
date_time_input_proto = DateTimeInputProto()
|
|
1214
|
+
date_time_input_proto.id = element_id
|
|
1215
|
+
date_time_input_proto.label = label
|
|
1216
|
+
if default_value_for_proto is not None:
|
|
1217
|
+
date_time_input_proto.default[:] = [
|
|
1218
|
+
_datetime_to_proto_string(default_value_for_proto)
|
|
1219
|
+
]
|
|
1220
|
+
date_time_input_proto.min = min_value_proto
|
|
1221
|
+
date_time_input_proto.max = max_value_proto
|
|
1222
|
+
date_time_input_proto.form_id = current_form_id(self.dg)
|
|
1223
|
+
date_time_input_proto.step = step_seconds
|
|
1224
|
+
date_time_input_proto.disabled = disabled
|
|
1225
|
+
date_time_input_proto.label_visibility.value = get_label_visibility_proto_value(
|
|
1226
|
+
label_visibility
|
|
1227
|
+
)
|
|
1228
|
+
date_time_input_proto.format = format
|
|
1229
|
+
date_time_input_proto.is_range = False
|
|
1230
|
+
|
|
1231
|
+
if help is not None:
|
|
1232
|
+
date_time_input_proto.help = dedent(help)
|
|
1233
|
+
|
|
1234
|
+
serde = DateTimeInputSerde(
|
|
1235
|
+
value=default_value_for_proto,
|
|
1236
|
+
min=datetime_values.min,
|
|
1237
|
+
max=datetime_values.max,
|
|
1238
|
+
)
|
|
1239
|
+
widget_state = register_widget(
|
|
1240
|
+
date_time_input_proto.id,
|
|
1241
|
+
on_change_handler=on_change,
|
|
1242
|
+
args=args,
|
|
1243
|
+
kwargs=kwargs,
|
|
1244
|
+
deserializer=serde.deserialize,
|
|
1245
|
+
serializer=serde.serialize,
|
|
1246
|
+
ctx=ctx,
|
|
1247
|
+
value_type="string_array_value",
|
|
1248
|
+
)
|
|
1249
|
+
|
|
1250
|
+
# Validate the current value against the new min/max bounds.
|
|
1251
|
+
# Only validate when user explicitly provided min_value or max_value.
|
|
1252
|
+
current_value, value_needs_reset = _validate_datetime_value(
|
|
1253
|
+
widget_state.value, datetime_values, has_explicit_bounds
|
|
1254
|
+
)
|
|
1255
|
+
|
|
1256
|
+
if value_needs_reset and key is not None:
|
|
1257
|
+
# Update session_state so subsequent accesses in this run
|
|
1258
|
+
# return the corrected value. Use reset_state_value to avoid
|
|
1259
|
+
# the "cannot be modified after widget instantiated" error.
|
|
1260
|
+
get_session_state().reset_state_value(key, current_value)
|
|
1261
|
+
|
|
1262
|
+
if value_needs_reset or widget_state.value_changed:
|
|
1263
|
+
date_time_input_proto.value[:] = serde.serialize(current_value)
|
|
1264
|
+
date_time_input_proto.set_value = True
|
|
1265
|
+
|
|
1266
|
+
validate_width(width)
|
|
1267
|
+
layout_config = LayoutConfig(width=width)
|
|
1268
|
+
|
|
1269
|
+
self.dg._enqueue(
|
|
1270
|
+
"date_time_input", date_time_input_proto, layout_config=layout_config
|
|
1271
|
+
)
|
|
1272
|
+
return current_value
|
|
1273
|
+
|
|
1274
|
+
@overload
|
|
1275
|
+
def date_input(
|
|
1276
|
+
self,
|
|
1277
|
+
label: str,
|
|
1278
|
+
value: date | datetime | str | Literal["today"] = "today",
|
|
1279
|
+
min_value: NullableScalarDateValue = None,
|
|
1280
|
+
max_value: NullableScalarDateValue = None,
|
|
1281
|
+
key: Key | None = None,
|
|
1282
|
+
help: str | None = None,
|
|
1283
|
+
on_change: WidgetCallback | None = None,
|
|
1284
|
+
args: WidgetArgs | None = None,
|
|
1285
|
+
kwargs: WidgetKwargs | None = None,
|
|
1286
|
+
*, # keyword-only arguments:
|
|
1287
|
+
format: str = "YYYY/MM/DD",
|
|
1288
|
+
disabled: bool = False,
|
|
1289
|
+
label_visibility: LabelVisibility = "visible",
|
|
1290
|
+
width: WidthWithoutContent = "stretch",
|
|
1291
|
+
) -> date: ...
|
|
1292
|
+
|
|
1293
|
+
@overload
|
|
1294
|
+
def date_input(
|
|
1295
|
+
self,
|
|
1296
|
+
label: str,
|
|
1297
|
+
value: None,
|
|
1298
|
+
min_value: NullableScalarDateValue = None,
|
|
1299
|
+
max_value: NullableScalarDateValue = None,
|
|
1300
|
+
key: Key | None = None,
|
|
1301
|
+
help: str | None = None,
|
|
1302
|
+
on_change: WidgetCallback | None = None,
|
|
1303
|
+
args: WidgetArgs | None = None,
|
|
1304
|
+
kwargs: WidgetKwargs | None = None,
|
|
1305
|
+
*, # keyword-only arguments:
|
|
1306
|
+
format: str = "YYYY/MM/DD",
|
|
1307
|
+
disabled: bool = False,
|
|
1308
|
+
label_visibility: LabelVisibility = "visible",
|
|
1309
|
+
width: WidthWithoutContent = "stretch",
|
|
1310
|
+
) -> date | None: ...
|
|
1311
|
+
|
|
1312
|
+
@overload
|
|
1313
|
+
def date_input(
|
|
1314
|
+
self,
|
|
1315
|
+
label: str,
|
|
1316
|
+
value: tuple[NullableScalarDateValue]
|
|
1317
|
+
| tuple[NullableScalarDateValue, NullableScalarDateValue]
|
|
1318
|
+
| list[NullableScalarDateValue],
|
|
1319
|
+
min_value: NullableScalarDateValue = None,
|
|
1320
|
+
max_value: NullableScalarDateValue = None,
|
|
1321
|
+
key: Key | None = None,
|
|
1322
|
+
help: str | None = None,
|
|
1323
|
+
on_change: WidgetCallback | None = None,
|
|
1324
|
+
args: WidgetArgs | None = None,
|
|
1325
|
+
kwargs: WidgetKwargs | None = None,
|
|
1326
|
+
*, # keyword-only arguments:
|
|
1327
|
+
format: str = "YYYY/MM/DD",
|
|
1328
|
+
disabled: bool = False,
|
|
1329
|
+
label_visibility: LabelVisibility = "visible",
|
|
1330
|
+
width: WidthWithoutContent = "stretch",
|
|
1331
|
+
) -> DateWidgetRangeReturn: ...
|
|
1332
|
+
|
|
1333
|
+
@gather_metrics("date_input")
|
|
1334
|
+
def date_input(
|
|
1335
|
+
self,
|
|
1336
|
+
label: str,
|
|
1337
|
+
value: DateValue = "today",
|
|
1338
|
+
min_value: NullableScalarDateValue = None,
|
|
1339
|
+
max_value: NullableScalarDateValue = None,
|
|
1340
|
+
key: Key | None = None,
|
|
1341
|
+
help: str | None = None,
|
|
1342
|
+
on_change: WidgetCallback | None = None,
|
|
1343
|
+
args: WidgetArgs | None = None,
|
|
1344
|
+
kwargs: WidgetKwargs | None = None,
|
|
1345
|
+
*, # keyword-only arguments:
|
|
1346
|
+
format: str = "YYYY/MM/DD",
|
|
1347
|
+
disabled: bool = False,
|
|
1348
|
+
label_visibility: LabelVisibility = "visible",
|
|
1349
|
+
width: WidthWithoutContent = "stretch",
|
|
1350
|
+
) -> DateWidgetReturn:
|
|
1351
|
+
r"""Display a date input widget.
|
|
1352
|
+
|
|
1353
|
+
The date input widget can be configured to accept a single date or a
|
|
1354
|
+
date range. The first day of the week is determined from the user's
|
|
1355
|
+
locale in their browser.
|
|
1356
|
+
|
|
1357
|
+
Parameters
|
|
1358
|
+
----------
|
|
1359
|
+
label : str
|
|
1360
|
+
A short label explaining to the user what this date input is for.
|
|
1361
|
+
The label can optionally contain GitHub-flavored Markdown of the
|
|
1362
|
+
following types: Bold, Italics, Strikethroughs, Inline Code, Links,
|
|
1363
|
+
and Images. Images display like icons, with a max height equal to
|
|
1364
|
+
the font height.
|
|
1365
|
+
|
|
1366
|
+
Unsupported Markdown elements are unwrapped so only their children
|
|
1367
|
+
(text contents) render. Display unsupported elements as literal
|
|
1368
|
+
characters by backslash-escaping them. E.g.,
|
|
1369
|
+
``"1\. Not an ordered list"``.
|
|
1370
|
+
|
|
1371
|
+
See the ``body`` parameter of |st.markdown|_ for additional,
|
|
1372
|
+
supported Markdown directives.
|
|
1373
|
+
|
|
1374
|
+
For accessibility reasons, you should never set an empty label, but
|
|
1375
|
+
you can hide it with ``label_visibility`` if needed. In the future,
|
|
1376
|
+
we may disallow empty labels by raising an exception.
|
|
1377
|
+
|
|
1378
|
+
.. |st.markdown| replace:: ``st.markdown``
|
|
1379
|
+
.. _st.markdown: https://docs.streamlit.io/develop/api-reference/text/st.markdown
|
|
1380
|
+
|
|
1381
|
+
value : "today", datetime.date, datetime.datetime, str, list/tuple of these, or None
|
|
1382
|
+
The value of this widget when it first renders. This can be one of
|
|
1383
|
+
the following:
|
|
1384
|
+
|
|
1385
|
+
- ``"today"`` (default): The widget initializes with the current date.
|
|
1386
|
+
- A ``datetime.date`` or ``datetime.datetime`` object: The widget
|
|
1387
|
+
initializes with the given date, ignoring any time if included.
|
|
1388
|
+
- An ISO-formatted date (YYYY-MM-DD) or datetime
|
|
1389
|
+
(YYYY-MM-DD hh:mm:ss) string: The widget initializes with the
|
|
1390
|
+
given date, ignoring any time if included.
|
|
1391
|
+
- A list or tuple with up to two of the above: The widget will
|
|
1392
|
+
initialize with the given date interval and return a tuple of the
|
|
1393
|
+
selected interval. You can pass an empty list to initialize the
|
|
1394
|
+
widget with an empty interval or a list with one value to
|
|
1395
|
+
initialize only the beginning date of the iterval.
|
|
1396
|
+
- ``None``: The widget initializes with no date and returns
|
|
1397
|
+
``None`` until the user selects a date.
|
|
1398
|
+
|
|
1399
|
+
min_value : "today", datetime.date, datetime.datetime, str, or None
|
|
1400
|
+
The minimum selectable date. This can be any of the date types
|
|
1401
|
+
accepted by ``value``, except list or tuple.
|
|
1402
|
+
|
|
1403
|
+
If this is ``None`` (default), the minimum selectable date is ten
|
|
1404
|
+
years before the initial value. If the initial value is an
|
|
1405
|
+
interval, the minimum selectable date is ten years before the start
|
|
1406
|
+
date of the interval. If no initial value is set, the minimum
|
|
1407
|
+
selectable date is ten years before today.
|
|
1408
|
+
|
|
1409
|
+
max_value : "today", datetime.date, datetime.datetime, str, or None
|
|
1410
|
+
The maximum selectable date. This can be any of the date types
|
|
1411
|
+
accepted by ``value``, except list or tuple.
|
|
1412
|
+
|
|
1413
|
+
If this is ``None`` (default), the maximum selectable date is ten
|
|
1414
|
+
years after the initial value. If the initial value is an interval,
|
|
1415
|
+
the maximum selectable date is ten years after the end date of the
|
|
1416
|
+
interval. If no initial value is set, the maximum selectable date
|
|
1417
|
+
is ten years after today.
|
|
1418
|
+
|
|
1419
|
+
key : str or int
|
|
1420
|
+
An optional string or integer to use as the unique key for the widget.
|
|
1421
|
+
If this is omitted, a key will be generated for the widget
|
|
1422
|
+
based on its content. No two widgets may have the same key.
|
|
1423
|
+
|
|
1424
|
+
help : str or None
|
|
1425
|
+
A tooltip that gets displayed next to the widget label. Streamlit
|
|
1426
|
+
only displays the tooltip when ``label_visibility="visible"``. If
|
|
1427
|
+
this is ``None`` (default), no tooltip is displayed.
|
|
1428
|
+
|
|
1429
|
+
The tooltip can optionally contain GitHub-flavored Markdown,
|
|
1430
|
+
including the Markdown directives described in the ``body``
|
|
1431
|
+
parameter of ``st.markdown``.
|
|
1432
|
+
|
|
1433
|
+
on_change : callable
|
|
1434
|
+
An optional callback invoked when this date_input's value changes.
|
|
1435
|
+
|
|
1436
|
+
args : list or tuple
|
|
1437
|
+
An optional list or tuple of args to pass to the callback.
|
|
1438
|
+
|
|
1439
|
+
kwargs : dict
|
|
1440
|
+
An optional dict of kwargs to pass to the callback.
|
|
1441
|
+
|
|
1442
|
+
format : str
|
|
1443
|
+
A format string controlling how the interface should display dates.
|
|
1444
|
+
Supports ``"YYYY/MM/DD"`` (default), ``"DD/MM/YYYY"``, or ``"MM/DD/YYYY"``.
|
|
1445
|
+
You may also use a period (.) or hyphen (-) as separators.
|
|
1446
|
+
|
|
1447
|
+
disabled : bool
|
|
1448
|
+
An optional boolean that disables the date input if set to
|
|
1449
|
+
``True``. The default is ``False``.
|
|
1450
|
+
|
|
1451
|
+
label_visibility : "visible", "hidden", or "collapsed"
|
|
1452
|
+
The visibility of the label. The default is ``"visible"``. If this
|
|
1453
|
+
is ``"hidden"``, Streamlit displays an empty spacer instead of the
|
|
1454
|
+
label, which can help keep the widget aligned with other widgets.
|
|
1455
|
+
If this is ``"collapsed"``, Streamlit displays no label or spacer.
|
|
1456
|
+
|
|
1457
|
+
width : "stretch" or int
|
|
1458
|
+
The width of the date input widget. This can be one of the following:
|
|
1459
|
+
|
|
1460
|
+
- ``"stretch"`` (default): The width of the widget matches the
|
|
1461
|
+
width of the parent container.
|
|
1462
|
+
- An integer specifying the width in pixels: The widget has a
|
|
1463
|
+
fixed width. If the specified width is greater than the width of
|
|
1464
|
+
the parent container, the width of the widget matches the width
|
|
1465
|
+
of the parent container.
|
|
1466
|
+
|
|
1467
|
+
Returns
|
|
1468
|
+
-------
|
|
1469
|
+
datetime.date or a tuple with 0-2 dates or None
|
|
1470
|
+
The current value of the date input widget or ``None`` if no date has been
|
|
1471
|
+
selected.
|
|
1472
|
+
|
|
1473
|
+
Examples
|
|
1474
|
+
--------
|
|
1475
|
+
**Example 1: Basic usage**
|
|
1476
|
+
|
|
1477
|
+
>>> import datetime
|
|
1478
|
+
>>> import streamlit as st
|
|
1479
|
+
>>>
|
|
1480
|
+
>>> d = st.date_input("When's your birthday", datetime.date(2019, 7, 6))
|
|
1481
|
+
>>> st.write("Your birthday is:", d)
|
|
1482
|
+
|
|
1483
|
+
.. output::
|
|
1484
|
+
https://doc-date-input.streamlit.app/
|
|
1485
|
+
height: 380px
|
|
1486
|
+
|
|
1487
|
+
**Example 2: Date range**
|
|
1488
|
+
|
|
1489
|
+
>>> import datetime
|
|
1490
|
+
>>> import streamlit as st
|
|
1491
|
+
>>>
|
|
1492
|
+
>>> today = datetime.datetime.now()
|
|
1493
|
+
>>> next_year = today.year + 1
|
|
1494
|
+
>>> jan_1 = datetime.date(next_year, 1, 1)
|
|
1495
|
+
>>> dec_31 = datetime.date(next_year, 12, 31)
|
|
1496
|
+
>>>
|
|
1497
|
+
>>> d = st.date_input(
|
|
1498
|
+
... "Select your vacation for next year",
|
|
1499
|
+
... (jan_1, datetime.date(next_year, 1, 7)),
|
|
1500
|
+
... jan_1,
|
|
1501
|
+
... dec_31,
|
|
1502
|
+
... format="MM.DD.YYYY",
|
|
1503
|
+
... )
|
|
1504
|
+
>>> d
|
|
1505
|
+
|
|
1506
|
+
.. output::
|
|
1507
|
+
https://doc-date-input1.streamlit.app/
|
|
1508
|
+
height: 380px
|
|
1509
|
+
|
|
1510
|
+
**Example 3: Empty initial value**
|
|
1511
|
+
|
|
1512
|
+
To initialize an empty date input, use ``None`` as the value:
|
|
1513
|
+
|
|
1514
|
+
>>> import datetime
|
|
1515
|
+
>>> import streamlit as st
|
|
1516
|
+
>>>
|
|
1517
|
+
>>> d = st.date_input("When's your birthday", value=None)
|
|
1518
|
+
>>> st.write("Your birthday is:", d)
|
|
1519
|
+
|
|
1520
|
+
.. output::
|
|
1521
|
+
https://doc-date-input-empty.streamlit.app/
|
|
1522
|
+
height: 380px
|
|
1523
|
+
|
|
1524
|
+
"""
|
|
1525
|
+
ctx = get_script_run_ctx()
|
|
1526
|
+
return self._date_input(
|
|
1527
|
+
label=label,
|
|
1528
|
+
value=value,
|
|
1529
|
+
min_value=min_value,
|
|
1530
|
+
max_value=max_value,
|
|
1531
|
+
key=key,
|
|
1532
|
+
help=help,
|
|
1533
|
+
on_change=on_change,
|
|
1534
|
+
args=args,
|
|
1535
|
+
kwargs=kwargs,
|
|
1536
|
+
disabled=disabled,
|
|
1537
|
+
label_visibility=label_visibility,
|
|
1538
|
+
format=format,
|
|
1539
|
+
width=width,
|
|
1540
|
+
ctx=ctx,
|
|
1541
|
+
)
|
|
1542
|
+
|
|
1543
|
+
def _date_input(
|
|
1544
|
+
self,
|
|
1545
|
+
label: str,
|
|
1546
|
+
value: DateValue = "today",
|
|
1547
|
+
min_value: NullableScalarDateValue = None,
|
|
1548
|
+
max_value: NullableScalarDateValue = None,
|
|
1549
|
+
key: Key | None = None,
|
|
1550
|
+
help: str | None = None,
|
|
1551
|
+
on_change: WidgetCallback | None = None,
|
|
1552
|
+
args: WidgetArgs | None = None,
|
|
1553
|
+
kwargs: WidgetKwargs | None = None,
|
|
1554
|
+
*, # keyword-only arguments:
|
|
1555
|
+
format: str = "YYYY/MM/DD",
|
|
1556
|
+
disabled: bool = False,
|
|
1557
|
+
label_visibility: LabelVisibility = "visible",
|
|
1558
|
+
width: WidthWithoutContent = "stretch",
|
|
1559
|
+
ctx: ScriptRunContext | None = None,
|
|
1560
|
+
) -> DateWidgetReturn:
|
|
1561
|
+
key = to_key(key)
|
|
1562
|
+
|
|
1563
|
+
check_widget_policies(
|
|
1564
|
+
self.dg,
|
|
1565
|
+
key,
|
|
1566
|
+
on_change,
|
|
1567
|
+
default_value=value if value != "today" else None,
|
|
1568
|
+
)
|
|
1569
|
+
maybe_raise_label_warnings(label, label_visibility)
|
|
1570
|
+
|
|
1571
|
+
def parse_date_deterministic_for_id(v: NullableScalarDateValue) -> str | None:
|
|
1572
|
+
if v == "today":
|
|
1573
|
+
# For ID purposes, no need to parse the input string.
|
|
1574
|
+
return None
|
|
1575
|
+
if isinstance(v, str):
|
|
1576
|
+
# For ID purposes, no need to parse the input string.
|
|
1577
|
+
return v
|
|
1578
|
+
if isinstance(v, datetime):
|
|
1579
|
+
return date.strftime(v.date(), "%Y/%m/%d")
|
|
1580
|
+
if isinstance(v, date):
|
|
1581
|
+
return date.strftime(v, "%Y/%m/%d")
|
|
1582
|
+
|
|
1583
|
+
return None
|
|
1584
|
+
|
|
1585
|
+
parsed_min_date = parse_date_deterministic_for_id(min_value)
|
|
1586
|
+
parsed_max_date = parse_date_deterministic_for_id(max_value)
|
|
1587
|
+
|
|
1588
|
+
parsed: str | list[str | None] | None
|
|
1589
|
+
if value == "today":
|
|
1590
|
+
parsed = None
|
|
1591
|
+
elif isinstance(value, Sequence):
|
|
1592
|
+
parsed = [parse_date_deterministic_for_id(v) for v in value] # ty: ignore[invalid-argument-type]
|
|
1593
|
+
else:
|
|
1594
|
+
parsed = parse_date_deterministic_for_id(value)
|
|
1595
|
+
|
|
1596
|
+
# TODO: this is missing the error path, integrate with the dateinputvalues parsing
|
|
1597
|
+
|
|
1598
|
+
element_id = compute_and_register_element_id(
|
|
1599
|
+
"date_input",
|
|
1600
|
+
user_key=key,
|
|
1601
|
+
# Ensure stable ID when key is provided. Only format is whitelisted because
|
|
1602
|
+
# there is a bug in baseweb where changing the format dynamically leads to
|
|
1603
|
+
# a wrongly formatted date. min_value and max_value support dynamic changes.
|
|
1604
|
+
key_as_main_identity={"format"},
|
|
1605
|
+
dg=self.dg,
|
|
1606
|
+
label=label,
|
|
1607
|
+
value=parsed,
|
|
1608
|
+
min_value=parsed_min_date,
|
|
1609
|
+
max_value=parsed_max_date,
|
|
1610
|
+
help=help,
|
|
1611
|
+
format=format,
|
|
1612
|
+
width=width,
|
|
1613
|
+
)
|
|
1614
|
+
if not bool(ALLOWED_DATE_FORMATS.match(format)):
|
|
1615
|
+
raise StreamlitAPIException(
|
|
1616
|
+
f"The provided format (`{format}`) is not valid. DateInput format "
|
|
1617
|
+
"should be one of `YYYY/MM/DD`, `DD/MM/YYYY`, or `MM/DD/YYYY` "
|
|
1618
|
+
"and can also use a period (.) or hyphen (-) as separators."
|
|
1619
|
+
)
|
|
1620
|
+
|
|
1621
|
+
parsed_values = _DateInputValues.from_raw_values(
|
|
1622
|
+
value=value,
|
|
1623
|
+
min_value=min_value,
|
|
1624
|
+
max_value=max_value,
|
|
1625
|
+
)
|
|
1626
|
+
|
|
1627
|
+
# Track if user explicitly set bounds (before del)
|
|
1628
|
+
has_explicit_bounds = min_value is not None or max_value is not None
|
|
1629
|
+
|
|
1630
|
+
if value == "today":
|
|
1631
|
+
# We need to know if this is a single or range date_input, but don't have
|
|
1632
|
+
# a default value, so we check if session_state can tell us.
|
|
1633
|
+
# We already calculated the id, so there is no risk of this causing
|
|
1634
|
+
# the id to change.
|
|
1635
|
+
|
|
1636
|
+
session_state = get_session_state().filtered_state
|
|
1637
|
+
|
|
1638
|
+
if key is not None and key in session_state:
|
|
1639
|
+
state_value = session_state[key]
|
|
1640
|
+
parsed_values = _DateInputValues.from_raw_values(
|
|
1641
|
+
value=state_value,
|
|
1642
|
+
min_value=min_value,
|
|
1643
|
+
max_value=max_value,
|
|
1644
|
+
)
|
|
1645
|
+
|
|
1646
|
+
del value, min_value, max_value
|
|
1647
|
+
|
|
1648
|
+
date_input_proto = DateInputProto()
|
|
1649
|
+
date_input_proto.id = element_id
|
|
1650
|
+
date_input_proto.is_range = parsed_values.is_range
|
|
1651
|
+
date_input_proto.disabled = disabled
|
|
1652
|
+
date_input_proto.label_visibility.value = get_label_visibility_proto_value(
|
|
1653
|
+
label_visibility
|
|
1654
|
+
)
|
|
1655
|
+
date_input_proto.format = format
|
|
1656
|
+
date_input_proto.label = label
|
|
1657
|
+
if parsed_values.value is None:
|
|
1658
|
+
# An empty array represents the empty state. The reason for using an empty
|
|
1659
|
+
# array here is that we cannot optional keyword for repeated fields
|
|
1660
|
+
# in protobuf.
|
|
1661
|
+
date_input_proto.default[:] = []
|
|
1662
|
+
else:
|
|
1663
|
+
date_input_proto.default[:] = [
|
|
1664
|
+
date.strftime(v, "%Y/%m/%d") for v in parsed_values.value
|
|
1665
|
+
]
|
|
1666
|
+
date_input_proto.min = date.strftime(parsed_values.min, "%Y/%m/%d")
|
|
1667
|
+
date_input_proto.max = date.strftime(parsed_values.max, "%Y/%m/%d")
|
|
1668
|
+
date_input_proto.form_id = current_form_id(self.dg)
|
|
1669
|
+
|
|
1670
|
+
if help is not None:
|
|
1671
|
+
date_input_proto.help = dedent(help)
|
|
1672
|
+
|
|
1673
|
+
serde = DateInputSerde(parsed_values)
|
|
1674
|
+
|
|
1675
|
+
widget_state = register_widget(
|
|
1676
|
+
date_input_proto.id,
|
|
1677
|
+
on_change_handler=on_change,
|
|
1678
|
+
args=args,
|
|
1679
|
+
kwargs=kwargs,
|
|
1680
|
+
deserializer=serde.deserialize,
|
|
1681
|
+
serializer=serde.serialize,
|
|
1682
|
+
ctx=ctx,
|
|
1683
|
+
value_type="string_array_value",
|
|
1684
|
+
)
|
|
1685
|
+
|
|
1686
|
+
# Validate the current value against the new min/max bounds.
|
|
1687
|
+
# Only validate when user explicitly provided min_value or max_value.
|
|
1688
|
+
current_value, value_needs_reset = _validate_date_value(
|
|
1689
|
+
widget_state.value, parsed_values, has_explicit_bounds
|
|
1690
|
+
)
|
|
1691
|
+
|
|
1692
|
+
# Reset if needed.
|
|
1693
|
+
if value_needs_reset and key is not None:
|
|
1694
|
+
# Update session_state so subsequent accesses in this run
|
|
1695
|
+
# return the corrected value. Use reset_state_value to avoid
|
|
1696
|
+
# the "cannot be modified after widget instantiated" error.
|
|
1697
|
+
get_session_state().reset_state_value(key, current_value)
|
|
1698
|
+
|
|
1699
|
+
if value_needs_reset or widget_state.value_changed:
|
|
1700
|
+
date_input_proto.value[:] = serde.serialize(current_value)
|
|
1701
|
+
date_input_proto.set_value = True
|
|
1702
|
+
|
|
1703
|
+
validate_width(width)
|
|
1704
|
+
layout_config = LayoutConfig(width=width)
|
|
1705
|
+
|
|
1706
|
+
self.dg._enqueue("date_input", date_input_proto, layout_config=layout_config)
|
|
1707
|
+
return current_value
|
|
1708
|
+
|
|
1709
|
+
@property
|
|
1710
|
+
def dg(self) -> DeltaGenerator:
|
|
1711
|
+
"""Get our DeltaGenerator."""
|
|
1712
|
+
return cast("DeltaGenerator", self)
|