Let's learn more about the API to use Session State.
Initialization
The Session State API follows a field-based API, which is very similar to Python dictionaries:
```python
import streamlit as st
Check if 'key' already exists in session_state
If not, then initialize it
if 'key' not in st.session_state:
    st.session_state['key'] = 'value'
Session State also supports the attribute based syntax
if 'key' not in st.session_state:
    st.session_state.key = 'value'
```
Reads and updates
Read the value of an item in Session State by passing the item to st.write :
```python
import streamlit as st
if 'key' not in st.session_state:
    st.session_state['key'] = 'value'
Reads
st.write(st.session_state.key)
Outputs: value
```
Update an item in Session State by assigning it a value:
```python
import streamlit as st
