LoginSignup
2
1

More than 1 year has passed since last update.

StreamlitでセッションIDを取得する方法

Last updated at Posted at 2022-03-06

Streamlit(version=1.7.0)でセッションIDを取得した時の備忘録

下記コードをstreamlit run session_id_example.pyと実行して、セッションIDを取得できることを確認できた。

session_id_example.py
from streamlit.script_run_context import get_script_run_ctx

ctx = get_script_run_ctx()
print(ctx.session_id)

セッションIDは00e79560-4427-4c8e-9fef-473b52aca4f2といった形式で出力された。

Streamlitはバージョンによって、セッションIDの取得方法が変更されていることがあるみたいなので、注意してください。

(参考) 以前のバージョンのセッションID取得方法

from streamlit.report_thread import get_report_ctx

ctx = get_report_ctx()
print(ctx.session_id)
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1