Spaces:
Sleeping
Sleeping
File size: 1,060 Bytes
c9a0fae | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | """Safe access helpers for Streamlit secrets on Hugging Face Spaces."""
from __future__ import annotations
from typing import Any, Optional
def secrets_available() -> bool:
"""Return True when Streamlit secrets are configured."""
try:
import streamlit as st
if not hasattr(st, "secrets"):
return False
_ = st.secrets.keys()
return True
except Exception:
return False
def has_secret(key: str) -> bool:
"""Check whether a top-level secret key exists without raising."""
try:
import streamlit as st
if not hasattr(st, "secrets"):
return False
return key in st.secrets
except Exception:
return False
def get_secret_section(section: str) -> Optional[Any]:
"""Return a secrets section/namespace, or None if unavailable."""
try:
import streamlit as st
if not hasattr(st, "secrets") or section not in st.secrets:
return None
return st.secrets[section]
except Exception:
return None |