Adding experimental_rerun
diff --git a/e2e/scripts/st_experimental_rerun.py b/e2e/scripts/st_experimental_rerun.py
new file mode 100644
index 000000000000..baf2719c10aa
--- /dev/null
+++ b/e2e/scripts/st_experimental_rerun.py
@@ -0,0 +1,30 @@
+# Copyright 2018-2020 Streamlit Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import streamlit as st
+
+
+@st.cache(allow_output_mutation=True)
+def rerun_record():
+    return [0]
+
+
+count = rerun_record()
+count[0] += 1
+
+if count[0] < 4:
+    st.experimental_rerun()
+
+if count[0] >= 4:
+    st.text("Being able to rerun a session is awesome!")
diff --git a/e2e/specs/st_experimental_rerun.spec.ts b/e2e/specs/st_experimental_rerun.spec.ts
new file mode 100644
index 000000000000..5b8fdfa5b206
--- /dev/null
+++ b/e2e/specs/st_experimental_rerun.spec.ts
@@ -0,0 +1,31 @@
+/**
+ * @license
+ * Copyright 2018-2020 Streamlit Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/// <reference types="cypress" />
+
+describe("st.experimental_rerun", () => {
+  before(() => {
+    cy.visit("http://localhost:3000/");
+  });
+
+  it("restarts the session when invoked", () => {
+    cy.get(".element-container .stText").should(
+      "contain",
+      "Being able to rerun a session is awesome!"
+    );
+  });
+});
diff --git a/lib/streamlit/__init__.py b/lib/streamlit/__init__.py
index d60c766f37ed..cdcf7797bc92 100644
--- a/lib/streamlit/__init__.py
+++ b/lib/streamlit/__init__.py
@@ -76,6 +76,8 @@
 from streamlit.report_thread import add_report_ctx as _add_report_ctx
 from streamlit.report_thread import get_report_ctx as _get_report_ctx
 from streamlit.script_runner import StopException
+from streamlit.script_runner import RerunException as _RerunException
+from streamlit.script_request_queue import RerunData as _RerunData
 from streamlit.errors import StreamlitAPIException
 from streamlit.proto import BlockPath_pb2 as _BlockPath_pb2
 from streamlit.proto import ForwardMsg_pb2 as _ForwardMsg_pb2
@@ -507,3 +509,17 @@ def stop():
 
     """
     raise StopException()
+
+
+def experimental_rerun():
+    """Rerun the script immediately.
+
+    When `st.experimental_rerun()` is called, the script is halted - no
+    more statements will be run, and the script will be queued to re-run
+    from the top.
+
+    If this function is called outside of Streamlit, it will raise an
+    Exception.
+    """
+
+    raise _RerunException(_RerunData(None))
diff --git a/scripts/run_bare_integration_tests.py b/scripts/run_bare_integration_tests.py
index abb0d95394e2..df267e7515ba 100755
--- a/scripts/run_bare_integration_tests.py
+++ b/scripts/run_bare_integration_tests.py
@@ -36,6 +36,10 @@
 
 EXCLUDED_FILENAMES = set()  # type: Set[str]
 
+# st_experimental_rerun.py calls st.experimental_rerun which raises a
+# RerunException when called within plain Python.
+EXCLUDED_FILENAMES.add("st_experimental_rerun.py")
+
 # Since there is not DISPLAY set (and since Streamlit is not actually running
 # and fixing Matplotlib in these tests), we set the MPL backend to something
 # that doesn't require a display.

**Issue:**

Fixes https://github.com/streamlit/streamlit/issues/653

**Description:** 

Added `st.experimental_rerun` and `st.experimental_get_session_id`. Given that rerun needed access to the server I chose to make the relevant test be within the e2e testing suite. This e2e test undergoes a few reruns within a thread, and then a couple more just within the main streamlit instance.