streamlit-node-editor 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.
@@ -0,0 +1,120 @@
1
+ import os
2
+ import streamlit.components.v1 as components
3
+
4
+ _RELEASE = True
5
+
6
+ if _RELEASE:
7
+ _component_func = components.declare_component(
8
+ "streamlit_node_editor",
9
+ path=os.path.join(os.path.dirname(__file__), "frontend/build"),
10
+ )
11
+ else:
12
+ _component_func = components.declare_component(
13
+ "streamlit_node_editor",
14
+ url="http://localhost:3001",
15
+ )
16
+
17
+
18
+ def st_node_editor(node_defs, initial_nodes=None, initial_connections=None,
19
+ height=700, key=None):
20
+ """
21
+ Render a ComfyUI / Unreal Blueprints-style node graph editor.
22
+
23
+ Users can add nodes from a palette, connect typed ports by dragging,
24
+ edit inline parameters, and delete nodes or wires interactively.
25
+
26
+ Parameters
27
+ ----------
28
+ node_defs : dict[str, dict]
29
+ Registry of available node types. Each entry::
30
+
31
+ "Node Name": {
32
+ "category": str, # groups nodes in the palette
33
+ "headerColor": str, # hex color for the node header bar
34
+ "inputs": [ # list of input port definitions
35
+ {"name": str, "type": str}, # type must be a key in port_types
36
+ ],
37
+ "outputs": [ # list of output port definitions
38
+ {"name": str, "type": str},
39
+ ],
40
+ "params": [ # inline editable parameters
41
+ {
42
+ "key": str,
43
+ "label": str,
44
+ "type": str, # "int" | "float" | "string" | "select" | "textarea"
45
+ "default": any, # optional default value
46
+ "options": list[str], # required for type="select"
47
+ }
48
+ ],
49
+ }
50
+
51
+ initial_nodes : list[dict], optional
52
+ Pre-placed nodes on load. Each dict::
53
+
54
+ {"id": str, "type": str, "x": float, "y": float,
55
+ "params": {key: value}}
56
+
57
+ initial_connections : list[dict], optional
58
+ Pre-existing wires. Each dict::
59
+
60
+ {"id": str, "fromNode": str, "fromPort": int,
61
+ "toNode": str, "toPort": int}
62
+
63
+ height : int
64
+ Canvas height in pixels. Default 700.
65
+ key : str, optional
66
+ Streamlit widget key.
67
+
68
+ Returns
69
+ -------
70
+ dict | None
71
+ Current graph state::
72
+
73
+ {
74
+ "nodes": [
75
+ {"id": str, "type": str, "x": float, "y": float,
76
+ "params": {key: value}},
77
+ ...
78
+ ],
79
+ "connections": [
80
+ {"id": str, "fromNode": str, "fromPort": int,
81
+ "toNode": str, "toPort": int},
82
+ ...
83
+ ],
84
+ }
85
+
86
+ Returns None before any interaction.
87
+
88
+ Example
89
+ -------
90
+ >>> from streamlit_node_editor import st_node_editor
91
+ >>>
92
+ >>> NODE_DEFS = {
93
+ ... "Load Data": {
94
+ ... "category": "Sources",
95
+ ... "headerColor": "#4ade80",
96
+ ... "inputs": [],
97
+ ... "outputs": [{"name": "dataframe", "type": "DATAFRAME"}],
98
+ ... "params": [{"key": "path", "label": "CSV path", "type": "string"}],
99
+ ... },
100
+ ... "Filter Rows": {
101
+ ... "category": "Transform",
102
+ ... "headerColor": "#38bdf8",
103
+ ... "inputs": [{"name": "dataframe", "type": "DATAFRAME"}],
104
+ ... "outputs": [{"name": "dataframe", "type": "DATAFRAME"}],
105
+ ... "params": [{"key": "query", "label": "Query", "type": "string"}],
106
+ ... },
107
+ ... }
108
+ >>>
109
+ >>> graph = st_node_editor(NODE_DEFS, height=600, key="pipeline")
110
+ >>> if graph:
111
+ ... st.json(graph)
112
+ """
113
+ return _component_func(
114
+ node_defs=node_defs,
115
+ initial_nodes=initial_nodes or [],
116
+ initial_connections=initial_connections or [],
117
+ height=height,
118
+ key=key,
119
+ default=None,
120
+ )
@@ -0,0 +1,10 @@
1
+ {
2
+ "files": {
3
+ "main.js": "./static/js/main.9884c600.js",
4
+ "index.html": "./index.html",
5
+ "main.9884c600.js.map": "./static/js/main.9884c600.js.map"
6
+ },
7
+ "entrypoints": [
8
+ "static/js/main.9884c600.js"
9
+ ]
10
+ }
@@ -0,0 +1 @@
1
+ <!doctype html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><title>Streamlit Node Editor</title><script defer="defer" src="./static/js/main.9884c600.js"></script></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>