LoginSignup
3
5

More than 3 years have passed since last update.

【小ネタ】Streamlitのシークレットマネージャー機能を使ってみる

Posted at

はじめに

Streamlitからのお知らせの中にこんなのを見つけて、試しに使ってみたのでメモがてら投稿します。

Try out Secrets
Secrets Management is now available in sharing [just make sure to upgrade to the > 0.80.0 release]. Read more here and check out the docs to get started.

意訳)
シークレットを試してみる
シークレットマネージメントが0.80.0リリース版で使えるようになったよ。
詳細はドキュメントみてね!

Secrets Management(シークレットマネージャー)機能について

パスワード情報を直接ソースに書かずに外部から渡すことができる機能。

サンプルプログラム

streamlit_app.py
import streamlit as st

st.write("DB username:", st.secrets["db_username"])
st.write("DB password:", st.secrets["db_password"])
st.write("My cool secrets:", st.secrets["my_cool_secrets"]["things_i_like"])

ローカル環境では、こんな感じでファイルを用意しておくことで利用可能です。

設定ファイル例)

.streamlit/secrets.toml
db_username = "Jane"
db_password = "12345qwerty"

[my_cool_secrets]
things_i_like = ["Streamlit", "Python"]

■実行結果
スクリーンショット 2021-04-15 8.42.27.png

※ また以下のように環境変数としてもアクセス可能です。

import os
st.write("DB username:", os.environ["db_username"])
st.write("DB password:", os.environ["db_password"])

Appendix

参考サイト

ご意見・ご感想をお待ちしております

今回の記事はいかがでしたか?
・こういう記事が読みたい
・こういうところが良かった
・こうした方が良いのではないか
などなど、率直なご意見を募集しております。
頂いたお声は、今後の記事の質向上に役立たせて頂きますので、お気軽に
コメント欄にてご投稿ください。Twitterでもご意見を受け付けております。
皆様のメッセージをお待ちしております。

3
5
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
3
5