if 'key' not in st.session_state:
    st.session_state['key'] = 'value'
Updates
st.session_state.key = 'value2'     # Attribute API
st.session_state['key'] = 'value2'  # Dictionary like API
```
Streamlit throws an exception if an uninitialized variable is accessed:
```python
import streamlit as st
st.write(st.session_state['value'])
Throws an exception!
```
Let's now take a look at a few examples that illustrate how to add Session State to our Counter app.
Example 1: Add Session State
Now that we've got a hang of the Session State API, let's update our Counter app to use Session State:
```python
import streamlit as st
st.title('Counter Example')
if 'count' not in st.session_state:
    st.session_state.count = 0
increment = st.button('Increment')
if increment:
    st.session_state.count += 1
