Hello there đź‘‹

Thanks for stopping by! We use cookies to help us understand how you interact with our website.

By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.

An interface to access user session context.

st.context provides a read-only interface to access headers and cookies for the current user session.

Each property (st.context.headers and st.context.cookies) returns a dictionary of named values.

Class description[source]

st.context()

Attributes

A read-only, dict-like object containing cookies sent in the initial request.

A read-only, dict-like object containing headers sent in the initial request.

A read-only, dict-like object containing cookies sent in the initial request.

Function signature[source]

context.cookies

Examples

Show a dictionary of cookies:

import streamlit as st

st.context.cookies

Show the value of a specific cookie:

import streamlit as st

st.context.cookies["_ga"]

A read-only, dict-like object containing headers sent in the initial request.

Keys are case-insensitive and may be repeated. When keys are repeated, dict-like methods will only return the last instance of each key. Use .get_all(key="your_repeated_key") to see all values if the same header is set multiple times.

Function signature[source]

context.headers

Examples

Show a dictionary of headers (with only the last instance of any repeated key):

import streamlit as st

st.context.headers

Show the value of a specific header (or the last instance if it's repeated):

import streamlit as st

st.context.headers["host"]

Show of list of all headers for a given key:

import streamlit as st

st.context.headers.get_all("pragma")
forum

Still have questions?

Our forums are full of helpful information and Streamlit experts.