Get user id

Is it possible to get the ids of the users running a given Streamlit service? and send a content to that specific user.

Best

1 Like

I think this would be a nice addition if something like this would be possible.
Could for example be used to save information of a user to disks, and to return that specific information from disk back to the user. For example a user uploads images, the app detects objects in the images and lets the user download the results.

Hi @Poyita_de_troya, welcome to the Streamlit community! What would the id represent, something that the user passes in?

Hi! Thanks. Ideally, the user doesn’t need to “register” to any website with some credentials. Simply, 1) streamlit is running 2) a user connects to the URL (assume public IP) 3) the “server” receives a unique id from the user (the user doesn’t setup any id) 4) in a given moment, the server sends information to that specific user.
Is it possible? Or should I create some database tracking each id with a user? I appreciate any advise.

Hey @Poyita_de_troya!

I think the best way to do this would be to create a custom component, which sets a unique ID as a cookie in the user’s browser. If the user is coming back, you can read that cookie and look up if that ID already exists. I once tried hacking something like that together, which kind of worked (even though it didn’t work on Streamlit Sharing). The docs on writing custom components are here and you can build it off this template. To set cookies from the template, you can use this library.

It’s a bit complicated (as components require Javascript) but definitely possible! If you don’t need it instantly I could also have a look at my old code during the next days and see if I can share something with you.

2 Likes

Great! I’ll take a look on it. No, I’m not in a hurry, then, it would be awesome your help.

Thanks