streamlitextras.cookiemanager package

class CookieManager(debug: bool = False)[source]

Bases: object

This is a streamlit component class to manage cookies.

It uses a thin component instance wrapper around the universal-cookie library.

delayed_init()[source]

Used to delay initialization of streamlit objects so this class can be cached

cookie_manager(*args, **kwargs)[source]
set(name, value, expires_at=None, secure=None, path=None, same_site=None, key='set')[source]

Set a cookie with name, value and options. Defaults are set in the JS component and listed below

Parameters
  • name – The name of the cookie

  • value – The value of the cookie

  • expires_at – Datetime of when the cookie expires. Default is set in the js at 1 day from browser timezone.

  • secure – Secure flag, default is true.

  • path – Cookie path, default is /

  • same_site – Same site attribute, default is “strict”

  • key – streamlit key used for the component instance

Returns

True if the operation was successful, else False

get(name, key='get')[source]

Gets a value of a cookie. NOTE: The value isn’t got directly from the component instance This class fills all cookies in self.cookies everytime streamlit instances it on the page

Returns empty {} dict if no result. Returns None if the operation failed.

Parameters

name – The name of the cookie to get the value of

Returns Union[str, dict]

Returns the cookie value, it may be deserialized from JSON to a dict

get_all(key='get_all')[source]

Get a dict of all the cookies in the browser, and update self.cookies

Parameters

key – streamlit key used for the component instance

Returns

A dict of all the cookies

delete(name, key='delete')[source]

Delete a cookie from the browser

Parameters
  • name – the name of the cookie to delete

  • key – streamlit key used for the component instance

Returns

True if the operation was successful, or else False