streamlit-nightly 1.33.1.dev20240407__py2.py3-none-any.whl → 1.33.1.dev20240409__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- streamlit/components/lib/__init__.py +13 -0
- streamlit/components/lib/local_component_registry.py +82 -0
- streamlit/components/types/__init__.py +13 -0
- streamlit/components/types/base_component_registry.py +98 -0
- streamlit/components/types/base_custom_component.py +137 -0
- streamlit/components/v1/__init__.py +7 -3
- streamlit/components/v1/component_registry.py +103 -0
- streamlit/components/v1/components.py +9 -375
- streamlit/components/v1/custom_component.py +241 -0
- streamlit/errors.py +6 -0
- streamlit/runtime/runtime.py +12 -0
- streamlit/static/asset-manifest.json +2 -2
- streamlit/static/index.html +1 -1
- streamlit/static/static/js/{main.285df334.js → main.37ad7d13.js} +2 -2
- streamlit/web/server/component_request_handler.py +2 -2
- streamlit/web/server/server.py +1 -2
- {streamlit_nightly-1.33.1.dev20240407.dist-info → streamlit_nightly-1.33.1.dev20240409.dist-info}/METADATA +1 -1
- {streamlit_nightly-1.33.1.dev20240407.dist-info → streamlit_nightly-1.33.1.dev20240409.dist-info}/RECORD +23 -16
- /streamlit/static/static/js/{main.285df334.js.LICENSE.txt → main.37ad7d13.js.LICENSE.txt} +0 -0
- {streamlit_nightly-1.33.1.dev20240407.data → streamlit_nightly-1.33.1.dev20240409.data}/scripts/streamlit.cmd +0 -0
- {streamlit_nightly-1.33.1.dev20240407.dist-info → streamlit_nightly-1.33.1.dev20240409.dist-info}/WHEEL +0 -0
- {streamlit_nightly-1.33.1.dev20240407.dist-info → streamlit_nightly-1.33.1.dev20240409.dist-info}/entry_points.txt +0 -0
- {streamlit_nightly-1.33.1.dev20240407.dist-info → streamlit_nightly-1.33.1.dev20240409.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024)
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024)
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
from __future__ import annotations
|
16
|
+
|
17
|
+
import os
|
18
|
+
import threading
|
19
|
+
from typing import Final
|
20
|
+
|
21
|
+
from streamlit import util
|
22
|
+
from streamlit.components.types.base_component_registry import BaseComponentRegistry
|
23
|
+
from streamlit.components.types.base_custom_component import BaseCustomComponent
|
24
|
+
from streamlit.errors import StreamlitAPIException
|
25
|
+
from streamlit.logger import get_logger
|
26
|
+
|
27
|
+
_LOGGER: Final = get_logger(__name__)
|
28
|
+
|
29
|
+
|
30
|
+
class LocalComponentRegistry(BaseComponentRegistry):
|
31
|
+
def __init__(self) -> None:
|
32
|
+
self._components: dict[str, BaseCustomComponent] = {}
|
33
|
+
self._lock = threading.Lock()
|
34
|
+
|
35
|
+
def __repr__(self) -> str:
|
36
|
+
return util.repr_(self)
|
37
|
+
|
38
|
+
def register_component(self, component: BaseCustomComponent) -> None:
|
39
|
+
"""Register a CustomComponent.
|
40
|
+
|
41
|
+
Parameters
|
42
|
+
----------
|
43
|
+
component : BaseCustomComponent
|
44
|
+
The component to register.
|
45
|
+
"""
|
46
|
+
|
47
|
+
# Validate the component's path
|
48
|
+
abspath = component.abspath
|
49
|
+
if abspath is not None and not os.path.isdir(abspath):
|
50
|
+
raise StreamlitAPIException(f"No such component directory: '{abspath}'")
|
51
|
+
|
52
|
+
with self._lock:
|
53
|
+
existing = self._components.get(component.name)
|
54
|
+
self._components[component.name] = component
|
55
|
+
|
56
|
+
if existing is not None and component != existing:
|
57
|
+
_LOGGER.warning(
|
58
|
+
"%s overriding previously-registered %s",
|
59
|
+
component,
|
60
|
+
existing,
|
61
|
+
)
|
62
|
+
|
63
|
+
_LOGGER.debug("Registered component %s", component)
|
64
|
+
|
65
|
+
def get_component_path(self, name: str) -> str | None:
|
66
|
+
"""Return the filesystem path for the component with the given name.
|
67
|
+
|
68
|
+
If no such component is registered, or if the component exists but is
|
69
|
+
being served from a URL, return None instead.
|
70
|
+
"""
|
71
|
+
component = self._components.get(name, None)
|
72
|
+
return component.abspath if component is not None else None
|
73
|
+
|
74
|
+
def get_module_name(self, name: str) -> str | None:
|
75
|
+
component = self._components.get(name, None)
|
76
|
+
return component.module_name if component is not None else None
|
77
|
+
|
78
|
+
def get_component(self, name: str) -> BaseCustomComponent | None:
|
79
|
+
return self._components.get(name, None)
|
80
|
+
|
81
|
+
def get_components(self) -> list[BaseCustomComponent]:
|
82
|
+
return list(self._components.values())
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024)
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024)
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
from __future__ import annotations
|
16
|
+
|
17
|
+
from abc import abstractmethod
|
18
|
+
from typing import Protocol
|
19
|
+
|
20
|
+
from streamlit.components.types.base_custom_component import BaseCustomComponent
|
21
|
+
|
22
|
+
|
23
|
+
class BaseComponentRegistry(Protocol):
|
24
|
+
"""Interface for ComponentRegistries."""
|
25
|
+
|
26
|
+
@abstractmethod
|
27
|
+
def register_component(self, component: BaseCustomComponent) -> None:
|
28
|
+
"""Register a CustomComponent.
|
29
|
+
|
30
|
+
Parameters
|
31
|
+
----------
|
32
|
+
component : CustomComponent
|
33
|
+
The component to register.
|
34
|
+
"""
|
35
|
+
raise NotImplementedError
|
36
|
+
|
37
|
+
@abstractmethod
|
38
|
+
def get_component_path(self, name: str) -> str | None:
|
39
|
+
"""Return the filesystem path for the component with the given name.
|
40
|
+
|
41
|
+
If no such component is registered, or if the component exists but is
|
42
|
+
being served from a URL, return None instead.
|
43
|
+
|
44
|
+
Parameters
|
45
|
+
----------
|
46
|
+
name: name of the component
|
47
|
+
|
48
|
+
Returns
|
49
|
+
-------
|
50
|
+
str or None
|
51
|
+
The name of the specified component or None if no component with the given name has been registered.
|
52
|
+
"""
|
53
|
+
raise NotImplementedError
|
54
|
+
|
55
|
+
@abstractmethod
|
56
|
+
def get_module_name(self, name: str) -> str | None:
|
57
|
+
"""Return the module name for the component with the given name.
|
58
|
+
|
59
|
+
If no such component is registered, return None instead.
|
60
|
+
|
61
|
+
Parameters
|
62
|
+
----------
|
63
|
+
name: name of the component
|
64
|
+
|
65
|
+
Returns
|
66
|
+
-------
|
67
|
+
str or None
|
68
|
+
The module_name of the specified component or None if no component with the given name has been registered.
|
69
|
+
"""
|
70
|
+
raise NotImplementedError
|
71
|
+
|
72
|
+
@abstractmethod
|
73
|
+
def get_component(self, name: str) -> BaseCustomComponent | None:
|
74
|
+
"""Return the registered component with the given name.
|
75
|
+
|
76
|
+
If no such component is registered, return None instead.
|
77
|
+
|
78
|
+
Parameters
|
79
|
+
----------
|
80
|
+
name: name of the component
|
81
|
+
|
82
|
+
Returns
|
83
|
+
-------
|
84
|
+
component or None
|
85
|
+
The component with the provided name or None if component with the given name has been registered.
|
86
|
+
"""
|
87
|
+
raise NotImplementedError
|
88
|
+
|
89
|
+
@abstractmethod
|
90
|
+
def get_components(self) -> list[BaseCustomComponent]:
|
91
|
+
"""Returns a list of custom components that are registered in this registry.
|
92
|
+
|
93
|
+
Returns
|
94
|
+
-------
|
95
|
+
list[CustomComponents]
|
96
|
+
A list of registered custom components.
|
97
|
+
"""
|
98
|
+
raise NotImplementedError
|
@@ -0,0 +1,137 @@
|
|
1
|
+
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024)
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
from __future__ import annotations
|
16
|
+
|
17
|
+
import os
|
18
|
+
from abc import ABC, abstractmethod
|
19
|
+
from typing import Any
|
20
|
+
|
21
|
+
from streamlit import util
|
22
|
+
from streamlit.errors import StreamlitAPIException
|
23
|
+
|
24
|
+
|
25
|
+
class MarshallComponentException(StreamlitAPIException):
|
26
|
+
"""Class for exceptions generated during custom component marshalling."""
|
27
|
+
|
28
|
+
pass
|
29
|
+
|
30
|
+
|
31
|
+
class BaseCustomComponent(ABC):
|
32
|
+
"""Interface for CustomComponents."""
|
33
|
+
|
34
|
+
def __init__(
|
35
|
+
self,
|
36
|
+
name: str,
|
37
|
+
path: str | None = None,
|
38
|
+
url: str | None = None,
|
39
|
+
module_name: str | None = None,
|
40
|
+
):
|
41
|
+
if (path is None and url is None) or (path is not None and url is not None):
|
42
|
+
raise StreamlitAPIException(
|
43
|
+
"Either 'path' or 'url' must be set, but not both."
|
44
|
+
)
|
45
|
+
|
46
|
+
self._name = name
|
47
|
+
self._path = path
|
48
|
+
self._url = url
|
49
|
+
self._module_name = module_name
|
50
|
+
|
51
|
+
def __repr__(self) -> str:
|
52
|
+
return util.repr_(self)
|
53
|
+
|
54
|
+
def __call__(
|
55
|
+
self,
|
56
|
+
*args,
|
57
|
+
default: Any = None,
|
58
|
+
key: str | None = None,
|
59
|
+
**kwargs,
|
60
|
+
) -> Any:
|
61
|
+
"""An alias for create_instance."""
|
62
|
+
return self.create_instance(*args, default=default, key=key, **kwargs)
|
63
|
+
|
64
|
+
@property
|
65
|
+
def abspath(self) -> str | None:
|
66
|
+
if self._path is None:
|
67
|
+
return None
|
68
|
+
return os.path.abspath(self._path)
|
69
|
+
|
70
|
+
@property
|
71
|
+
def module_name(self) -> str | None:
|
72
|
+
return self._module_name
|
73
|
+
|
74
|
+
@property
|
75
|
+
def name(self) -> str:
|
76
|
+
return self._name
|
77
|
+
|
78
|
+
@property
|
79
|
+
def path(self) -> str | None:
|
80
|
+
return self._path
|
81
|
+
|
82
|
+
@property
|
83
|
+
def url(self) -> str | None:
|
84
|
+
return self._url
|
85
|
+
|
86
|
+
def __str__(self) -> str:
|
87
|
+
return f"'{self.name}': {self.path if self.path is not None else self.url}"
|
88
|
+
|
89
|
+
@abstractmethod
|
90
|
+
def __eq__(self, other) -> bool:
|
91
|
+
"""Equality operator."""
|
92
|
+
return NotImplemented
|
93
|
+
|
94
|
+
@abstractmethod
|
95
|
+
def __ne__(self, other) -> bool:
|
96
|
+
"""Inequality operator."""
|
97
|
+
return NotImplemented
|
98
|
+
|
99
|
+
@abstractmethod
|
100
|
+
def create_instance(
|
101
|
+
self,
|
102
|
+
*args,
|
103
|
+
default: Any = None,
|
104
|
+
key: str | None = None,
|
105
|
+
**kwargs,
|
106
|
+
) -> Any:
|
107
|
+
"""Create a new instance of the component.
|
108
|
+
|
109
|
+
Parameters
|
110
|
+
----------
|
111
|
+
*args
|
112
|
+
Must be empty; all args must be named. (This parameter exists to
|
113
|
+
enforce correct use of the function.)
|
114
|
+
default: any or None
|
115
|
+
The default return value for the component. This is returned when
|
116
|
+
the component's frontend hasn't yet specified a value with
|
117
|
+
`setComponentValue`.
|
118
|
+
key: str or None
|
119
|
+
If not None, this is the user key we use to generate the
|
120
|
+
component's "widget ID".
|
121
|
+
**kwargs
|
122
|
+
Keyword args to pass to the component.
|
123
|
+
|
124
|
+
Raises
|
125
|
+
------
|
126
|
+
MarshallComponentException
|
127
|
+
Raised when args is not empty or component cannot be marshalled.
|
128
|
+
StreamlitAPIException
|
129
|
+
Raised when PyArrow is not installed.
|
130
|
+
|
131
|
+
Returns
|
132
|
+
-------
|
133
|
+
any or None
|
134
|
+
The component's widget value.
|
135
|
+
|
136
|
+
"""
|
137
|
+
raise NotImplementedError
|
@@ -12,11 +12,15 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
"""
|
16
|
+
This directory contains the files and modules for the exposed API.
|
17
|
+
"""
|
18
|
+
|
17
19
|
import streamlit
|
18
|
-
from streamlit.components.v1.
|
20
|
+
from streamlit.components.v1.component_registry import declare_component
|
19
21
|
|
22
|
+
# `html` and `iframe` are part of Custom Components, so they appear in this
|
23
|
+
# `streamlit.components.v1` namespace.
|
20
24
|
html = streamlit._main._html
|
21
25
|
iframe = streamlit._main._iframe
|
22
26
|
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024)
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
from __future__ import annotations
|
16
|
+
|
17
|
+
import inspect
|
18
|
+
import os
|
19
|
+
from types import FrameType
|
20
|
+
|
21
|
+
from streamlit.components.types.base_component_registry import BaseComponentRegistry
|
22
|
+
from streamlit.components.v1.custom_component import CustomComponent
|
23
|
+
from streamlit.runtime import get_instance
|
24
|
+
|
25
|
+
|
26
|
+
def _get_module_name(caller_frame: FrameType) -> str:
|
27
|
+
# Get the caller's module name. `__name__` gives us the module's
|
28
|
+
# fully-qualified name, which includes its package.
|
29
|
+
module = inspect.getmodule(caller_frame)
|
30
|
+
assert module is not None
|
31
|
+
module_name = module.__name__
|
32
|
+
|
33
|
+
# If the caller was the main module that was executed (that is, if the
|
34
|
+
# user executed `python my_component.py`), then this name will be
|
35
|
+
# "__main__" instead of the actual package name. In this case, we use
|
36
|
+
# the main module's filename, sans `.py` extension, as the component name.
|
37
|
+
if module_name == "__main__":
|
38
|
+
file_path = inspect.getfile(caller_frame)
|
39
|
+
filename = os.path.basename(file_path)
|
40
|
+
module_name, _ = os.path.splitext(filename)
|
41
|
+
|
42
|
+
return module_name
|
43
|
+
|
44
|
+
|
45
|
+
def declare_component(
|
46
|
+
name: str,
|
47
|
+
path: str | None = None,
|
48
|
+
url: str | None = None,
|
49
|
+
) -> CustomComponent:
|
50
|
+
"""Create and register a custom component.
|
51
|
+
|
52
|
+
Parameters
|
53
|
+
----------
|
54
|
+
name: str
|
55
|
+
A short, descriptive name for the component. Like, "slider".
|
56
|
+
path: str or None
|
57
|
+
The path to serve the component's frontend files from. Either
|
58
|
+
`path` or `url` must be specified, but not both.
|
59
|
+
url: str or None
|
60
|
+
The URL that the component is served from. Either `path` or `url`
|
61
|
+
must be specified, but not both.
|
62
|
+
|
63
|
+
Returns
|
64
|
+
-------
|
65
|
+
CustomComponent
|
66
|
+
A CustomComponent that can be called like a function.
|
67
|
+
Calling the component will create a new instance of the component
|
68
|
+
in the Streamlit app.
|
69
|
+
|
70
|
+
"""
|
71
|
+
|
72
|
+
# Get our stack frame.
|
73
|
+
current_frame: FrameType | None = inspect.currentframe()
|
74
|
+
assert current_frame is not None
|
75
|
+
# Get the stack frame of our calling function.
|
76
|
+
caller_frame = current_frame.f_back
|
77
|
+
assert caller_frame is not None
|
78
|
+
module_name = _get_module_name(caller_frame)
|
79
|
+
|
80
|
+
# Build the component name.
|
81
|
+
component_name = f"{module_name}.{name}"
|
82
|
+
|
83
|
+
# Create our component object, and register it.
|
84
|
+
component = CustomComponent(
|
85
|
+
name=component_name, path=path, url=url, module_name=module_name
|
86
|
+
)
|
87
|
+
get_instance().component_registry.register_component(component)
|
88
|
+
|
89
|
+
return component
|
90
|
+
|
91
|
+
|
92
|
+
# Keep for backwards-compatibility for now as we don't know whether existing custom
|
93
|
+
# components use this method. We made significant refactors to the custom component
|
94
|
+
# registry code in https://github.com/streamlit/streamlit/pull/8193 and after
|
95
|
+
# that is out in the wild, we can follow-up with more refactorings, e.g. remove
|
96
|
+
# the following class and method. When we do that, we should conduct some testing with
|
97
|
+
# popular custom components.
|
98
|
+
class ComponentRegistry:
|
99
|
+
@classmethod
|
100
|
+
def instance(cls) -> BaseComponentRegistry:
|
101
|
+
"""Returns the ComponentRegistry of the runtime instance."""
|
102
|
+
|
103
|
+
return get_instance().component_registry
|