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. | |
The read-only timezone of the user's browser. | |
The read-only timezone offset of the user's browser. |
Function signature[source] | |
---|---|
context.cookies |
Examples
Example 1: Access all available cookies
Show a dictionary of cookies:
Example 2: Access a specific cookie
Show the value of a specific cookie:
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
Example 1: Access all available headers
Show a dictionary of headers (with only the last instance of any repeated key):
Example 2: Access a specific header
Show the value of a specific header (or the last instance if it's repeated):
Show of list of all headers for a given key:
Function signature[source] | |
---|---|
context.timezone |
Example
Access the user's timezone, and format a datetime to display locally:
Function signature[source] | |
---|---|
context.timezone_offset |
Example
Access the user's timezone offset, and format a datetime to display locally:
Still have questions?
Our forums are full of helpful information and Streamlit experts.