An extension to extra-streamlit-components · PyPI | (Github) , I added browser cookie support. You can preserve data between sessions, update, get, and delete browser cookies. Newly added cookies with this module is strictly same-site, so you don’t have to worry about privacy.
Highly advised to be on Streamlit >= 0.84.0 for seamless experience as it harnesses state management for faster performance
Hey @Mohamed
You should definitely add your extensions to the Components Tracker those are very neat features!
Happy Streamlitlin’
Fanilo
Woah! This is amazing Mohammed!
I’ve shared internally with the Dev team.
Best,
Charly
The cookie solution solves a major pain point. Thank you @Mohamed. I am going to experiment with tabs and other features here. Great work!
The tab feature is really cool. I tested it with 6+ elements and some are of course hidden. I was able to drag the tabs but it took me a while to find out that it could be done.
It may be nice to show something like a scrollbar in the bottom if there are many elements. What do you think?
Glad you like it! Will consider that feedback in later iterations of the library.
Quick question Mohammed.
Do you know if the cookie feat works in Streamlit Sharing?
Thanks
Charly
cc: @jrieke
This looks splendid! I can’t wait to incorporate this and the other extra components in my app.
Good going!
I think the pip package’s main.py shall work fine without any additional setup. I tried figuring share.streamlit.io out on but my invitation request hasn’t been processed in days.
cc: @jrieke
FYI @Charly_Wargnier I’ve just shared the package on streamlit sharing @ extra-streamlit-components. Enjoy!
Beautiful!
I’ve shared internally with the team!
Charly
@Mohamed would it take a lot of work to add expiration dates to the cookies that are being set? If not, it would be very useful to add it.
Nice idea @vivekdse, by default it’s set to a day. But will try to make it user configurable in the next iterations.
That would be great. Thank you.
You can update to 0.1.43 now, and add a cookie expiration date as a python datetime
object.
Awesome. I did and it works. Do you want to add the instruction on github on how to add expires_at? I had to dig through the source code for it, and it was worth it Thank you for taking this on quickly.
@Mohamed How to get the cookie from a existed internet address
and judge its specific cookie is exist or not?
if not exist, do redirect operation, only get valid cookie, user can view the app page.
how can we make it come true?
I had made it use asp, it very convenient
like this:
<%
if len(request.cookies("cookie_name"))<1 then
response.redirect("specific address to finish identity check & back to current page url")
end if
%>
can we achieve a similar function?
Well @BeyondMyself this is not considered as a limitiation of this library rather an application design problem. I propose you do either of the following:
- Make this authentication mechanism using a REST API where you expect the response to be a cookie or token which then you can use stx to add the cookie.
- Make the identity check redirect to the app with a query parameter set to the token. i.e.
127.0.0.1:8501?token=1234S3cr3t
then use built in streamlit commands to extract that query parameter and then set it as a cookie - I can remeber seeing a post on this forum mentioning successfully using AOuth2 which as far as I know, does the identity check in a new window browser and returns an auth token, which then you can also add to the browser cookie using stx
Good Luck!
Hi @Mohamed I’ve implemented a secure access with web authentication, and encoded the user information with JWT in the cookies.
But using this package, when I explore the cookies, I cannot see the required cookie.
Do you know if there is any limitation to shoe “secure” cookies?.
Let me attach some pictures to illustrate the problem:
5 out of 7 cookies are shown. But the one I need is not.
The required cookie is an HttpOnly, Secure and SameSite=Strict cookie. Please see next image:
Can you give me any advice?
Hi @MarceTU , one of those 2 not visible cookies must have been set in an other way that through CookieManager so I can’t confirm that behaviour.
However, I am aware of a bug where getting all cookies after setting a cookie might miss showing the newly added cookie. A work around to that is to call get_all
twice back to back and the latest call shall return all cookies correctly.
Have a good one!