streamlit-remote 0.7.2__tar.gz → 0.9.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: streamlit-remote
3
- Version: 0.7.2
3
+ Version: 0.9.0
4
4
  Summary: Run Streamlit apps with optional remote HTTPS access.
5
5
  Author: Yuichiro Tachibana (Tsuchiya)
6
6
  Author-email: Yuichiro Tachibana (Tsuchiya) <t.yic.yt@gmail.com>
@@ -71,8 +71,10 @@ st-remote app.py --https self-signed --no-remote
71
71
  st-remote app.py --https mkcert --no-remote
72
72
  st-remote app.py --https mkcert --mkcert-binary /path/to/mkcert --no-remote
73
73
  st-remote app.py --provider ngrok
74
+ st-remote app.py --provider zrok
74
75
  st-remote app.py --cloudflared-binary /path/to/cloudflared
75
76
  st-remote app.py --provider ngrok --ngrok-binary /path/to/ngrok
77
+ st-remote app.py --provider zrok --zrok-binary /path/to/zrok
76
78
  st-remote app.py --provider ngrok --tunnel-log-level warn
77
79
  st-remote app.py --provider ngrok --remote-auth oauth --oauth-provider google
78
80
  st-remote app.py --provider ngrok --ngrok-traffic-policy-file policy.yml
@@ -90,7 +92,7 @@ Extra arguments after `--` are passed to `python -m streamlit run`.
90
92
 
91
93
  In an interactive terminal, `st-remote` shows a live terminal display with local and remote URLs, process statuses, recent logs, and shortcut help. Use `--no-tui` to keep plain prefixed log output from startup.
92
94
 
93
- Press `r` to restart only the Streamlit server while keeping the remote tunnel process running. This keeps the current tunnel session alive, so providers such as Cloudflare Quick Tunnel and ngrok can continue serving the same public URL while Streamlit restarts behind it.
95
+ Press `r` to restart only the Streamlit server while keeping the remote tunnel process running. This keeps the current tunnel session alive, so providers such as Cloudflare Quick Tunnel, ngrok, and zrok can continue serving the same public URL while Streamlit restarts behind it.
94
96
 
95
97
  Press `t` to toggle between the live terminal display and plain prefixed log output. When switching to plain output, `st-remote` replays recent logs into the normal terminal buffer so you can copy older logs from terminal or tmux history. You can also press `p` to force plain output and `f` to force the live terminal display. In terminals where single-key input is unavailable, the Enter-based commands still work.
96
98
 
@@ -197,6 +199,28 @@ st-remote app.py --provider ngrok --ngrok-traffic-policy-file policy.yml
197
199
 
198
200
  This is useful for provider-specific policies such as OIDC, Basic Auth, IP restrictions, or custom OAuth configuration.
199
201
 
202
+ ### zrok
203
+
204
+ zrok requires the `zrok` command to be installed and available on `PATH`. If it is installed somewhere else, pass `--zrok-binary /path/to/zrok`.
205
+
206
+ Install instructions are available from zrok:
207
+
208
+ https://docs.zrok.io/
209
+
210
+ Before first use, create or sign in to a zrok account and enable your environment:
211
+
212
+ ```bash
213
+ zrok enable
214
+ ```
215
+
216
+ Then run:
217
+
218
+ ```bash
219
+ st-remote app.py --provider zrok
220
+ ```
221
+
222
+ `streamlit-remote` starts zrok with a command such as `zrok share public --headless http://localhost:8501` and opens the HTTPS public share URL after zrok prints it. The `--headless` flag disables zrok's own terminal UI so it does not conflict with `st-remote`'s runtime display.
223
+
200
224
  ## Tunnel Logs
201
225
 
202
226
  Tunnel provider logs are shown by default:
@@ -221,7 +245,7 @@ The design treats HTTPS serving and remote access as separate concepts.
221
245
 
222
246
  HTTPS serving means the user-facing URL uses HTTPS. Remote access means the app is reachable from outside your local machine.
223
247
 
224
- Cloudflare Quick Tunnel and ngrok usually provide both at once: Streamlit can run locally over plain HTTP, while the provider gives you a public HTTPS URL that forwards to the local app.
248
+ Cloudflare Quick Tunnel, ngrok, and zrok usually provide both at once: Streamlit can run locally over plain HTTP, while the provider gives you a public HTTPS URL that forwards to the local app.
225
249
 
226
250
  Local self-signed and mkcert HTTPS are different: Streamlit itself runs with HTTPS locally. You can use local HTTPS without remote access, or combine it with a remote provider when you specifically want HTTPS between the tunnel agent and Streamlit.
227
251
 
@@ -234,6 +258,9 @@ Common combinations:
234
258
  --https off + --provider ngrok
235
259
  Public HTTPS via ngrok, local HTTP Streamlit.
236
260
 
261
+ --https off + --provider zrok
262
+ Public HTTPS via zrok, local HTTP Streamlit.
263
+
237
264
  --https self-signed + --no-remote
238
265
  Local HTTPS Streamlit only.
239
266
 
@@ -250,7 +277,7 @@ For managed self-signed HTTPS with Cloudflare Tunnel, `streamlit-remote` also pa
250
277
 
251
278
  This exposes a local Streamlit app to the internet.
252
279
 
253
- Do not use it for sensitive data unless you have proper authentication and access control in place. Cloudflare Quick Tunnel and ngrok are best suited for development, demos, and temporary sharing.
280
+ Do not use it for sensitive data unless you have proper authentication and access control in place. Cloudflare Quick Tunnel, ngrok, and zrok are best suited for development, demos, and temporary sharing.
254
281
 
255
282
  ngrok remote auth can add provider-level access control before requests reach Streamlit. Cloudflare Quick Tunnel auth is not supported by this package; Cloudflare Access requires a configured Zero Trust application and is outside the current Quick Tunnel workflow.
256
283
 
@@ -45,8 +45,10 @@ st-remote app.py --https self-signed --no-remote
45
45
  st-remote app.py --https mkcert --no-remote
46
46
  st-remote app.py --https mkcert --mkcert-binary /path/to/mkcert --no-remote
47
47
  st-remote app.py --provider ngrok
48
+ st-remote app.py --provider zrok
48
49
  st-remote app.py --cloudflared-binary /path/to/cloudflared
49
50
  st-remote app.py --provider ngrok --ngrok-binary /path/to/ngrok
51
+ st-remote app.py --provider zrok --zrok-binary /path/to/zrok
50
52
  st-remote app.py --provider ngrok --tunnel-log-level warn
51
53
  st-remote app.py --provider ngrok --remote-auth oauth --oauth-provider google
52
54
  st-remote app.py --provider ngrok --ngrok-traffic-policy-file policy.yml
@@ -64,7 +66,7 @@ Extra arguments after `--` are passed to `python -m streamlit run`.
64
66
 
65
67
  In an interactive terminal, `st-remote` shows a live terminal display with local and remote URLs, process statuses, recent logs, and shortcut help. Use `--no-tui` to keep plain prefixed log output from startup.
66
68
 
67
- Press `r` to restart only the Streamlit server while keeping the remote tunnel process running. This keeps the current tunnel session alive, so providers such as Cloudflare Quick Tunnel and ngrok can continue serving the same public URL while Streamlit restarts behind it.
69
+ Press `r` to restart only the Streamlit server while keeping the remote tunnel process running. This keeps the current tunnel session alive, so providers such as Cloudflare Quick Tunnel, ngrok, and zrok can continue serving the same public URL while Streamlit restarts behind it.
68
70
 
69
71
  Press `t` to toggle between the live terminal display and plain prefixed log output. When switching to plain output, `st-remote` replays recent logs into the normal terminal buffer so you can copy older logs from terminal or tmux history. You can also press `p` to force plain output and `f` to force the live terminal display. In terminals where single-key input is unavailable, the Enter-based commands still work.
70
72
 
@@ -171,6 +173,28 @@ st-remote app.py --provider ngrok --ngrok-traffic-policy-file policy.yml
171
173
 
172
174
  This is useful for provider-specific policies such as OIDC, Basic Auth, IP restrictions, or custom OAuth configuration.
173
175
 
176
+ ### zrok
177
+
178
+ zrok requires the `zrok` command to be installed and available on `PATH`. If it is installed somewhere else, pass `--zrok-binary /path/to/zrok`.
179
+
180
+ Install instructions are available from zrok:
181
+
182
+ https://docs.zrok.io/
183
+
184
+ Before first use, create or sign in to a zrok account and enable your environment:
185
+
186
+ ```bash
187
+ zrok enable
188
+ ```
189
+
190
+ Then run:
191
+
192
+ ```bash
193
+ st-remote app.py --provider zrok
194
+ ```
195
+
196
+ `streamlit-remote` starts zrok with a command such as `zrok share public --headless http://localhost:8501` and opens the HTTPS public share URL after zrok prints it. The `--headless` flag disables zrok's own terminal UI so it does not conflict with `st-remote`'s runtime display.
197
+
174
198
  ## Tunnel Logs
175
199
 
176
200
  Tunnel provider logs are shown by default:
@@ -195,7 +219,7 @@ The design treats HTTPS serving and remote access as separate concepts.
195
219
 
196
220
  HTTPS serving means the user-facing URL uses HTTPS. Remote access means the app is reachable from outside your local machine.
197
221
 
198
- Cloudflare Quick Tunnel and ngrok usually provide both at once: Streamlit can run locally over plain HTTP, while the provider gives you a public HTTPS URL that forwards to the local app.
222
+ Cloudflare Quick Tunnel, ngrok, and zrok usually provide both at once: Streamlit can run locally over plain HTTP, while the provider gives you a public HTTPS URL that forwards to the local app.
199
223
 
200
224
  Local self-signed and mkcert HTTPS are different: Streamlit itself runs with HTTPS locally. You can use local HTTPS without remote access, or combine it with a remote provider when you specifically want HTTPS between the tunnel agent and Streamlit.
201
225
 
@@ -208,6 +232,9 @@ Common combinations:
208
232
  --https off + --provider ngrok
209
233
  Public HTTPS via ngrok, local HTTP Streamlit.
210
234
 
235
+ --https off + --provider zrok
236
+ Public HTTPS via zrok, local HTTP Streamlit.
237
+
211
238
  --https self-signed + --no-remote
212
239
  Local HTTPS Streamlit only.
213
240
 
@@ -224,7 +251,7 @@ For managed self-signed HTTPS with Cloudflare Tunnel, `streamlit-remote` also pa
224
251
 
225
252
  This exposes a local Streamlit app to the internet.
226
253
 
227
- Do not use it for sensitive data unless you have proper authentication and access control in place. Cloudflare Quick Tunnel and ngrok are best suited for development, demos, and temporary sharing.
254
+ Do not use it for sensitive data unless you have proper authentication and access control in place. Cloudflare Quick Tunnel, ngrok, and zrok are best suited for development, demos, and temporary sharing.
228
255
 
229
256
  ngrok remote auth can add provider-level access control before requests reach Streamlit. Cloudflare Quick Tunnel auth is not supported by this package; Cloudflare Access requires a configured Zero Trust application and is outside the current Quick Tunnel workflow.
230
257
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "streamlit-remote"
3
- version = "0.7.2"
3
+ version = "0.9.0"
4
4
  description = "Run Streamlit apps with optional remote HTTPS access."
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -2,6 +2,9 @@ from __future__ import annotations
2
2
 
3
3
  import argparse
4
4
  import importlib.util
5
+ import json
6
+ import os
7
+ import select
5
8
  import shlex
6
9
  import sys
7
10
  import threading
@@ -46,7 +49,7 @@ def build_parser() -> argparse.ArgumentParser:
46
49
  parser.add_argument(
47
50
  "--provider",
48
51
  default="cloudflare",
49
- choices=["cloudflare", "ngrok"],
52
+ choices=["cloudflare", "ngrok", "zrok"],
50
53
  help="Remote tunnel provider.",
51
54
  )
52
55
  parser.add_argument(
@@ -65,6 +68,11 @@ def build_parser() -> argparse.ArgumentParser:
65
68
  type=Path,
66
69
  help="Path to the ngrok executable.",
67
70
  )
71
+ parser.add_argument(
72
+ "--zrok-binary",
73
+ type=Path,
74
+ help="Path to the zrok executable.",
75
+ )
68
76
  parser.add_argument(
69
77
  "--https",
70
78
  dest="https_mode",
@@ -237,6 +245,12 @@ def validate_cli_options(namespace: argparse.Namespace) -> None:
237
245
  if namespace.provider != "ngrok":
238
246
  raise CliError("`--ngrok-binary` can only be used with `--provider ngrok`.")
239
247
 
248
+ if namespace.zrok_binary is not None:
249
+ if namespace.no_remote:
250
+ raise CliError("`--zrok-binary` requires remote access. Remove `--no-remote`.")
251
+ if namespace.provider != "zrok":
252
+ raise CliError("`--zrok-binary` can only be used with `--provider zrok`.")
253
+
240
254
  if namespace.mkcert_binary is not None and namespace.https_mode != "mkcert":
241
255
  raise CliError("`--mkcert-binary` can only be used with `--https mkcert`.")
242
256
 
@@ -483,6 +497,9 @@ def run(namespace: argparse.Namespace) -> int:
483
497
  display_toggle_requested=display_toggle_requested,
484
498
  plain_output_requested=plain_output_requested,
485
499
  rich_output_requested=rich_output_requested,
500
+ scroll_log_up=display.scroll_log_up,
501
+ scroll_log_down=display.scroll_log_down,
502
+ reset_log_scroll=display.reset_log_scroll,
486
503
  )
487
504
  if shortcut_thread is not None:
488
505
  display.set_shortcuts_visible(True)
@@ -538,6 +555,9 @@ def start_restart_shortcut_listener(
538
555
  display_toggle_requested: threading.Event | None = None,
539
556
  plain_output_requested: threading.Event | None = None,
540
557
  rich_output_requested: threading.Event | None = None,
558
+ scroll_log_up: Callable[[], bool] | None = None,
559
+ scroll_log_down: Callable[[], bool] | None = None,
560
+ reset_log_scroll: Callable[[], bool] | None = None,
541
561
  ) -> threading.Thread | None:
542
562
  stdin = sys.stdin if input_stream is None else input_stream
543
563
  if not stdin.isatty():
@@ -551,6 +571,9 @@ def start_restart_shortcut_listener(
551
571
  display_toggle_requested=display_toggle_requested,
552
572
  plain_output_requested=plain_output_requested,
553
573
  rich_output_requested=rich_output_requested,
574
+ scroll_log_up=scroll_log_up,
575
+ scroll_log_down=scroll_log_down,
576
+ reset_log_scroll=reset_log_scroll,
554
577
  ):
555
578
  return
556
579
 
@@ -561,6 +584,9 @@ def start_restart_shortcut_listener(
561
584
  display_toggle_requested=display_toggle_requested,
562
585
  plain_output_requested=plain_output_requested,
563
586
  rich_output_requested=rich_output_requested,
587
+ scroll_log_up=scroll_log_up,
588
+ scroll_log_down=scroll_log_down,
589
+ reset_log_scroll=reset_log_scroll,
564
590
  )
565
591
 
566
592
  thread = threading.Thread(
@@ -580,6 +606,9 @@ def listen_for_cbreak_shortcuts(
580
606
  display_toggle_requested: threading.Event | None = None,
581
607
  plain_output_requested: threading.Event | None = None,
582
608
  rich_output_requested: threading.Event | None = None,
609
+ scroll_log_up: Callable[[], bool] | None = None,
610
+ scroll_log_down: Callable[[], bool] | None = None,
611
+ reset_log_scroll: Callable[[], bool] | None = None,
583
612
  ) -> bool:
584
613
  try:
585
614
  import select
@@ -606,18 +635,20 @@ def listen_for_cbreak_shortcuts(
606
635
  if not readable:
607
636
  continue
608
637
 
609
- try:
610
- shortcut = stdin.read(1)
611
- except OSError:
612
- return True
638
+ shortcut = read_cbreak_shortcut(stdin, fd=fd)
613
639
  if shortcut == "":
614
640
  return True
641
+ if shortcut is None:
642
+ continue
615
643
  dispatch_shortcut(
616
644
  shortcut,
617
645
  restart_requested,
618
646
  display_toggle_requested=display_toggle_requested,
619
647
  plain_output_requested=plain_output_requested,
620
648
  rich_output_requested=rich_output_requested,
649
+ scroll_log_up=scroll_log_up,
650
+ scroll_log_down=scroll_log_down,
651
+ reset_log_scroll=reset_log_scroll,
621
652
  )
622
653
  finally:
623
654
  termios.tcsetattr(fd, termios.TCSANOW, previous_terminal_settings)
@@ -633,6 +664,9 @@ def listen_for_line_shortcuts(
633
664
  display_toggle_requested: threading.Event | None = None,
634
665
  plain_output_requested: threading.Event | None = None,
635
666
  rich_output_requested: threading.Event | None = None,
667
+ scroll_log_up: Callable[[], bool] | None = None,
668
+ scroll_log_down: Callable[[], bool] | None = None,
669
+ reset_log_scroll: Callable[[], bool] | None = None,
636
670
  ) -> None:
637
671
  while not stop_requested.is_set():
638
672
  try:
@@ -647,6 +681,9 @@ def listen_for_line_shortcuts(
647
681
  display_toggle_requested=display_toggle_requested,
648
682
  plain_output_requested=plain_output_requested,
649
683
  rich_output_requested=rich_output_requested,
684
+ scroll_log_up=scroll_log_up,
685
+ scroll_log_down=scroll_log_down,
686
+ reset_log_scroll=reset_log_scroll,
650
687
  )
651
688
 
652
689
 
@@ -657,6 +694,9 @@ def dispatch_shortcut(
657
694
  display_toggle_requested: threading.Event | None = None,
658
695
  plain_output_requested: threading.Event | None = None,
659
696
  rich_output_requested: threading.Event | None = None,
697
+ scroll_log_up: Callable[[], bool] | None = None,
698
+ scroll_log_down: Callable[[], bool] | None = None,
699
+ reset_log_scroll: Callable[[], bool] | None = None,
660
700
  ) -> None:
661
701
  normalized = shortcut.strip().lower()
662
702
  if normalized in {"r", "restart"}:
@@ -667,6 +707,87 @@ def dispatch_shortcut(
667
707
  plain_output_requested.set()
668
708
  elif rich_output_requested is not None and normalized in {"f", "fancy", "tui"}:
669
709
  rich_output_requested.set()
710
+ elif scroll_log_up is not None and normalized in {
711
+ "\x10",
712
+ "\x1b[a",
713
+ "\x1boa",
714
+ "k",
715
+ "up",
716
+ "scroll up",
717
+ }:
718
+ scroll_log_up()
719
+ elif scroll_log_down is not None and normalized in {
720
+ "\x0e",
721
+ "\x1b[b",
722
+ "\x1bob",
723
+ "j",
724
+ "down",
725
+ "scroll down",
726
+ }:
727
+ scroll_log_down()
728
+ elif reset_log_scroll is not None and normalized in {"\x1b", "esc", "latest"}:
729
+ reset_log_scroll()
730
+
731
+
732
+ def read_cbreak_shortcut(stdin: TextIO, *, fd: int | None = None) -> str | None:
733
+ first_byte = read_cbreak_byte(stdin, fd=fd)
734
+ if first_byte == b"":
735
+ return ""
736
+
737
+ if first_byte != b"\x1b":
738
+ return first_byte.decode("utf-8", errors="replace")
739
+
740
+ sequence = [first_byte]
741
+ introducer = read_cbreak_byte(stdin, fd=fd, timeout=0.5)
742
+ if introducer == b"":
743
+ return "\x1b"
744
+ sequence.append(introducer)
745
+
746
+ if introducer == b"O":
747
+ final = read_cbreak_byte(stdin, fd=fd, timeout=0.5)
748
+ if final in {b"A", b"B"}:
749
+ sequence.append(final)
750
+ return b"".join(sequence).decode("ascii")
751
+ return None
752
+
753
+ if introducer != b"[":
754
+ return None
755
+
756
+ while len(sequence) < 6:
757
+ next_byte = read_cbreak_byte(stdin, fd=fd, timeout=0.5)
758
+ if next_byte == b"":
759
+ return None
760
+ sequence.append(next_byte)
761
+ if 0x40 <= next_byte[0] <= 0x7E:
762
+ return b"".join(sequence).decode("ascii", errors="ignore")
763
+
764
+ return None
765
+
766
+
767
+ def read_cbreak_byte(
768
+ stdin: TextIO,
769
+ *,
770
+ fd: int | None,
771
+ timeout: float | None = None,
772
+ ) -> bytes:
773
+ if fd is not None:
774
+ if timeout is not None:
775
+ try:
776
+ readable, _, _ = select.select([fd], [], [], timeout)
777
+ except OSError:
778
+ return b""
779
+ if not readable:
780
+ return b""
781
+ try:
782
+ return os.read(fd, 1)
783
+ except OSError:
784
+ return b""
785
+
786
+ try:
787
+ char = stdin.read(1)
788
+ except OSError:
789
+ return b""
790
+ return char.encode()
670
791
 
671
792
 
672
793
  def supervise_processes(
@@ -752,6 +873,9 @@ def selected_tunnel_binary(namespace: argparse.Namespace) -> Path | None:
752
873
  if namespace.provider == "ngrok":
753
874
  return namespace.ngrok_binary
754
875
 
876
+ if namespace.provider == "zrok":
877
+ return namespace.zrok_binary
878
+
755
879
  return None
756
880
 
757
881
 
@@ -793,6 +917,20 @@ def should_print_tunnel_line(line: str, tunnel_log_level: str) -> bool:
793
917
 
794
918
 
795
919
  def classify_tunnel_line(line: str) -> str:
920
+ try:
921
+ payload = json.loads(line)
922
+ except json.JSONDecodeError:
923
+ payload = None
924
+
925
+ if isinstance(payload, dict):
926
+ level = payload.get("level")
927
+ if isinstance(level, str):
928
+ normalized_level = level.lower()
929
+ if normalized_level in {"error", "fatal", "panic"}:
930
+ return "error"
931
+ if normalized_level in {"warn", "warning"}:
932
+ return "warn"
933
+
796
934
  lowered = line.lower()
797
935
  if any(marker in lowered for marker in ("lvl=error", "lvl=crit", " err ", " error", "fatal")):
798
936
  return "error"
@@ -5,6 +5,7 @@ from typing import Literal, Protocol
5
5
 
6
6
  from streamlit_remote.providers.cloudflare import CloudflareQuickTunnelProvider
7
7
  from streamlit_remote.providers.ngrok import NgrokProvider
8
+ from streamlit_remote.providers.zrok import ZrokProvider
8
9
 
9
10
  TunnelLogLevel = Literal["info", "warn", "error", "off"]
10
11
 
@@ -42,4 +43,7 @@ def get_provider(name: str, executable: str | Path | None = None) -> TunnelProvi
42
43
  if name == "ngrok":
43
44
  return NgrokProvider(executable=executable or "ngrok")
44
45
 
46
+ if name == "zrok":
47
+ return ZrokProvider(executable=executable or "zrok")
48
+
45
49
  raise ValueError(f"Unsupported provider: {name}")
@@ -0,0 +1,76 @@
1
+ from __future__ import annotations
2
+
3
+ import re
4
+ from dataclasses import dataclass
5
+ from pathlib import Path
6
+ from urllib.parse import urlparse
7
+
8
+ from streamlit_remote.providers.executables import is_executable_available
9
+ from streamlit_remote.server import bracket_ipv6_host
10
+
11
+ ZROK_SHARE_HOST_RE = re.compile(r"(?<![\w.-])(?:https://)?([A-Za-z0-9-]+\.shares?\.zrok\.io)\b")
12
+
13
+
14
+ @dataclass(frozen=True)
15
+ class ZrokProvider:
16
+ name: str = "zrok"
17
+ log_prefix: str = "zrok"
18
+ executable: str | Path = "zrok"
19
+
20
+ @property
21
+ def install_hint(self) -> str:
22
+ executable = str(self.executable)
23
+ if executable == "zrok":
24
+ return (
25
+ "zrok was not found on PATH. Install zrok from "
26
+ "https://docs.zrok.io/ and enable your environment with `zrok enable`."
27
+ )
28
+ return f"zrok was not found at configured path: {executable}"
29
+
30
+ def build_command(
31
+ self,
32
+ local_url: str,
33
+ *,
34
+ origin_tls_verify: bool = True,
35
+ tunnel_log_level: str = "info",
36
+ traffic_policy_file: Path | None = None,
37
+ ) -> list[str]:
38
+ parsed = urlparse(local_url)
39
+ try:
40
+ local_port = parsed.port
41
+ except ValueError as exc:
42
+ raise ValueError(f"Local URL must include a valid port for zrok: {local_url}") from exc
43
+
44
+ if local_port is None:
45
+ raise ValueError(f"Local URL must include a port for zrok: {local_url}")
46
+
47
+ local_host = local_connect_host(parsed.hostname)
48
+ if local_host is None:
49
+ raise ValueError(f"Local URL must include a host for zrok: {local_url}")
50
+
51
+ command = [str(self.executable), "share", "public", "--headless"]
52
+ if not origin_tls_verify:
53
+ command.append("--insecure")
54
+ command.append(f"{parsed.scheme}://{bracket_ipv6_host(local_host)}:{local_port}")
55
+ return command
56
+
57
+ def parse_public_url(self, line: str) -> str | None:
58
+ match = ZROK_SHARE_HOST_RE.search(line)
59
+ if match is not None:
60
+ return f"https://{match.group(1)}"
61
+
62
+ return None
63
+
64
+ def get_public_url(self) -> str | None:
65
+ return None
66
+
67
+ def is_available(self) -> bool:
68
+ return is_executable_available(self.executable)
69
+
70
+
71
+ def local_connect_host(host: str | None) -> str | None:
72
+ if host == "0.0.0.0":
73
+ return "127.0.0.1"
74
+ if host == "::":
75
+ return "::1"
76
+ return host
@@ -38,6 +38,12 @@ class RuntimeDisplay(Protocol):
38
38
 
39
39
  def set_shortcuts_visible(self, visible: bool) -> None: ...
40
40
 
41
+ def scroll_log_up(self) -> bool: ...
42
+
43
+ def scroll_log_down(self) -> bool: ...
44
+
45
+ def reset_log_scroll(self) -> bool: ...
46
+
41
47
  def streamlit_subprocess_columns(self) -> int | None: ...
42
48
 
43
49
  def info(self, message: str) -> None: ...
@@ -86,6 +92,15 @@ class PlainRuntimeDisplay(RuntimeDisplay):
86
92
  self.info("Runtime shortcuts:")
87
93
  self.info(" r: restart Streamlit while keeping the tunnel running")
88
94
 
95
+ def scroll_log_up(self) -> bool:
96
+ return False
97
+
98
+ def scroll_log_down(self) -> bool:
99
+ return False
100
+
101
+ def reset_log_scroll(self) -> bool:
102
+ return False
103
+
89
104
  def streamlit_subprocess_columns(self) -> int | None:
90
105
  return None
91
106
 
@@ -119,6 +134,9 @@ class RichRuntimeDisplay(RuntimeDisplay):
119
134
  self._local_url: str | None = None
120
135
  self._remote_url: str | None = None
121
136
  self._shortcuts_visible = False
137
+ self._log_window_start: int | None = None
138
+ self._log_ids: deque[int] = deque(maxlen=max_log_lines)
139
+ self._next_log_id = 0
122
140
  self._live: Live | None = None
123
141
  self._lock = threading.Lock()
124
142
 
@@ -175,6 +193,22 @@ class RichRuntimeDisplay(RuntimeDisplay):
175
193
  self._shortcuts_visible = visible
176
194
  self._refresh()
177
195
 
196
+ def scroll_log_up(self) -> bool:
197
+ with self._lock:
198
+ return self._scroll_log(1)
199
+
200
+ def scroll_log_down(self) -> bool:
201
+ with self._lock:
202
+ return self._scroll_log(-1)
203
+
204
+ def reset_log_scroll(self) -> bool:
205
+ with self._lock:
206
+ if self._log_window_start is None:
207
+ return False
208
+ self._log_window_start = None
209
+ self._refresh()
210
+ return True
211
+
178
212
  def streamlit_subprocess_columns(self) -> int | None:
179
213
  # Streamlit formats Rich tracebacks before we can render them without a
180
214
  # source prefix, so give it the prefix-less log panel width.
@@ -188,7 +222,12 @@ class RichRuntimeDisplay(RuntimeDisplay):
188
222
 
189
223
  def log(self, source: str, line: str) -> None:
190
224
  with self._lock:
225
+ anchor = self._log_window_anchor()
191
226
  self._logs.append((source, line))
227
+ self._log_ids.append(self._next_log_id)
228
+ self._next_log_id += 1
229
+ if anchor is not None:
230
+ self._log_window_start = self._find_log_window_anchor(anchor) or 0
192
231
  self._refresh()
193
232
 
194
233
  def set_state(
@@ -207,6 +246,10 @@ class RichRuntimeDisplay(RuntimeDisplay):
207
246
  self._shortcuts_visible = shortcuts_visible
208
247
  self._logs.clear()
209
248
  self._logs.extend(logs)
249
+ self._log_ids.clear()
250
+ self._log_ids.extend(range(len(logs)))
251
+ self._next_log_id = len(logs)
252
+ self._log_window_start = None
210
253
  self._refresh()
211
254
 
212
255
  def _refresh(self) -> None:
@@ -291,6 +334,14 @@ class RichRuntimeDisplay(RuntimeDisplay):
291
334
  if len(logs) <= available_rows:
292
335
  return logs
293
336
 
337
+ if self._log_window_start is not None:
338
+ start = self._clamped_log_window_start(
339
+ self._log_window_start,
340
+ log_count=len(logs),
341
+ available_rows=available_rows,
342
+ )
343
+ return logs[start : start + available_rows]
344
+
294
345
  traceback_spans = self._streamlit_traceback_spans(logs)
295
346
  traceback_span = traceback_spans[-1] if traceback_spans else None
296
347
  if traceback_span is None:
@@ -317,21 +368,125 @@ class RichRuntimeDisplay(RuntimeDisplay):
317
368
  self,
318
369
  logs: list[tuple[str, str]],
319
370
  ) -> list[tuple[str, str]]:
320
- arranged_logs: list[tuple[str, str]] = []
321
- deferred_logs: list[tuple[str, str]] = []
371
+ entries = [(index, log) for index, log in enumerate(logs)]
372
+ return [log for _, log in self._move_interleaved_log_entries_after_tracebacks(entries)]
373
+
374
+ def _scroll_log(self, rows: int) -> bool:
375
+ logs = self._move_interleaved_logs_after_tracebacks(list(self._logs))
376
+ available_rows = max(1, self._layout_heights()[1] - self._PANEL_FRAME_ROWS)
377
+ if len(logs) <= available_rows:
378
+ return False
379
+
380
+ old_start = self._current_log_window_start(logs, available_rows=available_rows)
381
+ new_start = self._clamped_log_window_start(
382
+ old_start - rows,
383
+ log_count=len(logs),
384
+ available_rows=available_rows,
385
+ )
386
+ if new_start == old_start:
387
+ return False
388
+ self._log_window_start = new_start
389
+ self._refresh()
390
+ return True
391
+
392
+ def _current_log_window_start(
393
+ self,
394
+ logs: list[tuple[str, str]],
395
+ *,
396
+ available_rows: int,
397
+ ) -> int:
398
+ if self._log_window_start is not None:
399
+ return self._clamped_log_window_start(
400
+ self._log_window_start,
401
+ log_count=len(logs),
402
+ available_rows=available_rows,
403
+ )
404
+
405
+ return self._default_log_window_start(logs, available_rows=available_rows)
406
+
407
+ def _default_log_window_start(
408
+ self,
409
+ logs: list[tuple[str, str]],
410
+ *,
411
+ available_rows: int,
412
+ ) -> int:
413
+ if len(logs) <= available_rows:
414
+ return 0
415
+
416
+ traceback_spans = self._streamlit_traceback_spans(logs)
417
+ traceback_span = traceback_spans[-1] if traceback_spans else None
418
+ if traceback_span is None:
419
+ return len(logs) - available_rows
420
+
421
+ start, end = traceback_span
422
+ if any(source == STREAMLIT_SOURCE for source, _ in logs[end:]):
423
+ return len(logs) - available_rows
424
+
425
+ traceback_rows = end - start
426
+ if traceback_rows >= available_rows:
427
+ return end - available_rows
428
+
429
+ following_rows = available_rows - traceback_rows
430
+ following_count = min(following_rows, len(logs) - end)
431
+ preceding_rows = available_rows - traceback_rows - following_count
432
+ if preceding_rows:
433
+ return max(0, start - preceding_rows)
434
+ return start
435
+
436
+ def _clamped_log_window_start(
437
+ self,
438
+ start: int,
439
+ *,
440
+ log_count: int,
441
+ available_rows: int,
442
+ ) -> int:
443
+ max_start = max(0, log_count - available_rows)
444
+ return min(max(0, start), max_start)
445
+
446
+ def _log_window_anchor(self) -> int | None:
447
+ if self._log_window_start is None:
448
+ return None
449
+
450
+ entries = self._arranged_log_entries()
451
+ if not entries:
452
+ return None
453
+ start = self._clamped_log_window_start(
454
+ self._log_window_start,
455
+ log_count=len(entries),
456
+ available_rows=max(1, self._layout_heights()[1] - self._PANEL_FRAME_ROWS),
457
+ )
458
+ return entries[start][0]
459
+
460
+ def _find_log_window_anchor(self, anchor: int) -> int | None:
461
+ for index, (log_id, _) in enumerate(self._arranged_log_entries()):
462
+ if log_id == anchor:
463
+ return index
464
+ return None
465
+
466
+ def _arranged_log_entries(self) -> list[tuple[int, tuple[str, str]]]:
467
+ return self._move_interleaved_log_entries_after_tracebacks(
468
+ list(zip(self._log_ids, self._logs, strict=True))
469
+ )
470
+
471
+ def _move_interleaved_log_entries_after_tracebacks(
472
+ self,
473
+ entries: list[tuple[int, tuple[str, str]]],
474
+ ) -> list[tuple[int, tuple[str, str]]]:
475
+ arranged_entries: list[tuple[int, tuple[str, str]]] = []
476
+ deferred_entries: list[tuple[int, tuple[str, str]]] = []
322
477
  in_streamlit_traceback = False
323
478
 
324
- for source, line in logs:
479
+ for log_id, (source, line) in entries:
325
480
  if self._is_streamlit_traceback_marker(source, line):
326
481
  in_streamlit_traceback = True
327
- arranged_logs.append((source, line))
482
+ arranged_entries.append((log_id, (source, line)))
328
483
  elif in_streamlit_traceback and source != STREAMLIT_SOURCE:
329
- deferred_logs.append((source, line))
484
+ deferred_entries.append((log_id, (source, line)))
330
485
  else:
331
- arranged_logs.append((source, line))
486
+ arranged_entries.append((log_id, (source, line)))
332
487
 
333
- arranged_logs.extend(deferred_logs)
334
- return arranged_logs
488
+ arranged_entries.extend(deferred_entries)
489
+ return arranged_entries
335
490
 
336
491
  def _raw_streamlit_traceback_indexes(self, logs: list[tuple[str, str]]) -> set[int]:
337
492
  raw_indexes: set[int] = set()
@@ -425,11 +580,16 @@ class RichRuntimeDisplay(RuntimeDisplay):
425
580
 
426
581
  shortcuts = Text()
427
582
  shortcuts.append("r", style="bold green")
428
- shortcuts.append(" restart Streamlit ")
583
+ shortcuts.append(" restart ")
429
584
  shortcuts.append("t", style="bold cyan")
430
- shortcuts.append(" toggle display ")
585
+ shortcuts.append(" display ")
586
+ shortcuts.append("j/k", style="bold yellow")
587
+ shortcuts.append(" ↑/↓ C-n/p", style="yellow")
588
+ shortcuts.append(" scroll ")
589
+ shortcuts.append("Esc", style="bold yellow")
590
+ shortcuts.append(" latest ")
431
591
  shortcuts.append("Ctrl+C", style="bold red")
432
- shortcuts.append(" stop all")
592
+ shortcuts.append(" stop")
433
593
  return Panel(shortcuts, title="Shortcuts", border_style="green", height=height)
434
594
 
435
595
  def _source_style(self, source: str) -> str:
@@ -564,6 +724,18 @@ class SwitchableRuntimeDisplay(RuntimeDisplay):
564
724
  self._shortcuts_visible = visible
565
725
  self._active_display.set_shortcuts_visible(visible)
566
726
 
727
+ def scroll_log_up(self) -> bool:
728
+ with self._lock:
729
+ return self._active_display.scroll_log_up()
730
+
731
+ def scroll_log_down(self) -> bool:
732
+ with self._lock:
733
+ return self._active_display.scroll_log_down()
734
+
735
+ def reset_log_scroll(self) -> bool:
736
+ with self._lock:
737
+ return self._active_display.reset_log_scroll()
738
+
567
739
  def streamlit_subprocess_columns(self) -> int | None:
568
740
  with self._lock:
569
741
  return self._active_display.streamlit_subprocess_columns()
@@ -13,7 +13,13 @@ class LocalServerConfig:
13
13
 
14
14
  @property
15
15
  def url(self) -> str:
16
- return f"{self.scheme}://{self.host}:{self.port}"
16
+ return f"{self.scheme}://{bracket_ipv6_host(self.host)}:{self.port}"
17
+
18
+
19
+ def bracket_ipv6_host(host: str) -> str:
20
+ if ":" in host and not host.startswith("["):
21
+ return f"[{host}]"
22
+ return host
17
23
 
18
24
 
19
25
  def is_port_available(host: str, port: int) -> bool: