cancel
Showing results for 
Search instead for 
Did you mean: 
Administration & Architecture
Explore discussions on Databricks administration, deployment strategies, and architectural best practices. Connect with administrators and architects to optimize your Databricks environment for performance, scalability, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to get logged in user name/email in the databricks streamlit app?

satniks_o
New Contributor III

I have created a Databricks App using streamlit and able to deploy and use it successfully.

I need to get the user name/email address of the logged in user and display in the streamlit app. Is this possible?

If not possible at the moment, any roadmap for adding this feature?

regards,

--

satniks

2 ACCEPTED SOLUTIONS

Accepted Solutions

BigRoux
Databricks Employee
Databricks Employee

Yes, it is possible to retrieve and display the username or email address of the logged-in user in a Streamlit app deployed on Databricks. This can be achieved through two primary approaches:

1. Using "st.experimental_user" in streamlit.

import streamlit as st

# Access the user's email

user_email = st.experimental_user.get("email", "Unknown User")

# Display the email in the app st.write(f"Logged in as: {user_email}")

2. Using HTTP Headers in Databricks Apps.

import os

import streamlit as st

# Access headers passed by Databricks Apps

user_email = os.getenv("X-Forwarded-Email", "Unknown User")

# Display the user's email

st.write(f"Logged in as: {user_email}")

 

Hope this helps. Cheers, Louis.

View solution in original post

Shannon_O
New Contributor III
user_email = st.context.headers.get("X-Forwarded-Email")
st.write(f"email: {user_email}")

View solution in original post

5 REPLIES 5

BigRoux
Databricks Employee
Databricks Employee

Yes, it is possible to retrieve and display the username or email address of the logged-in user in a Streamlit app deployed on Databricks. This can be achieved through two primary approaches:

1. Using "st.experimental_user" in streamlit.

import streamlit as st

# Access the user's email

user_email = st.experimental_user.get("email", "Unknown User")

# Display the email in the app st.write(f"Logged in as: {user_email}")

2. Using HTTP Headers in Databricks Apps.

import os

import streamlit as st

# Access headers passed by Databricks Apps

user_email = os.getenv("X-Forwarded-Email", "Unknown User")

# Display the user's email

st.write(f"Logged in as: {user_email}")

 

Hope this helps. Cheers, Louis.

satniks_o
New Contributor III

X-Forwarded-Email worked. I assume you mean using st.context.headers.get() instead of os.getenv().

Shannon_O
New Contributor III
user_email = st.context.headers.get("X-Forwarded-Email")
st.write(f"email: {user_email}")

satniks_o
New Contributor III

Thanks @BigRoux  and @Shannon_O  for your response.

I tried st.experimental_user.get() API but it gives me hardcoded response as test@example.com 

Suggestion to use X-Forwarded-Email header worked and I got correct email address. Thanks for your help. I am unblocked now.

Carl_B
New Contributor II

I have also tried to deploy a streamlit app, however I was not able to deploy it.

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!

Sign Up Now