# st.fragment

Source: https://docs.streamlit.io/develop/api-reference/execution-flow/st.fragment

> **Tip**
>
> This page only contains information on the `st.fragment` API. For a deeper dive into fragments, see [Fragments](https://docs.streamlit.io/develop/concepts/architecture/fragments). For dashboard patterns with parallel fragments and loading skeletons, see [Build advanced dashboards](https://docs.streamlit.io/develop/concepts/design/dashboards).

* Function signature:

   ```python
   st.fragment(func=None, *, run_every=None, parallel=False, key=None)
   ```

* Parameters:

   | name | type | default | description |
   |---|---|---|---|
   | func | callable |  | The function to turn into a fragment. |
   | run_every | int, float, timedelta, str, or None |  | The time interval between automatic fragment reruns. This can be one of the following:   None (default). An int or float specifying the interval in seconds. A string specifying the time in a format supported by Pandas' Timedelta constructor, e.g. "1D", "1.5 days", or "1h23s". A timedelta object from Python's built-in datetime library, e.g. timedelta(days=1).   If run_every is None, the fragment will only rerun from user-triggered events. |
   | parallel | bool |  | Whether to execute the fragment in parallel during full app reruns. If True, the fragment is dispatched to a thread pool and may execute concurrently with other parallel fragments and the rest of the app script. If False (default), the fragment executes inline on the main thread. Parallel fragments are useful for independent, slow operations that should not block overall app throughput. Full app reruns may overlap several parallel fragments with the main script; reruns confined to a single fragment (such as those triggered after widget interactions) remain sequential so state updates stay deterministic. During the initial parallel run, some Streamlit commands are restricted because they are not safe to call from concurrent threads. These include st.dialog and st.switch_page. Those commands work normally during sequential fragment reruns (e.g., after a widget interaction). Writing to containers created outside the fragment, including st.sidebar and st.bottom, is not supported in a parallel fragment on the initial parallel run or a later fragment rerun.  Warning Fragments dispatched in parallel can run concurrently. Avoid unsynchronized mutations of shared mutable resources across fragments unless you coordinate access explicitly. |
   | key | str, int, or None |  | An optional name for the fragment. If this is None (default), the fragment cannot be targeted by st.rerun. When set, a widget callback can rerun this fragment with st.rerun(""). Each fragment function rendered in a run must use a unique key; multiple call sites of the same function share that key and rerun together. An int key is normalized to its string representation. A fragment key must be unique among the fragments that render in a single run, just like a widget key. The names "app" and "fragment" are reserved and cannot be used as fragment keys. |
