st.context
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. | |
| Function signature[source] | |
|---|---|
context.cookies |
Examples
Show a dictionary of cookies:
PythonShow the value of a specific cookie:
Python
context.headers
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):
PythonShow the value of a specific header (or the last instance if it's repeated):
PythonShow of list of all headers for a given key:
Python
context.timezone_offset
Warning
This method does not exist in version 1.40.0 of Streamlit.
Still have questions?
Our forums are full of helpful information and Streamlit experts.
