Registry / web-framework / streamlit-autorefresh

streamlit-autorefresh

JSON →
library1.0.1pypypi✓ verified 85d ago

Streamlit Autorefresh is a Python library that provides a simple way to automatically refresh Streamlit applications. It works by implementing a frontend-based timer that periodically pings the Streamlit server, triggering a rerun of the application script. This component helps in building dashboards or real-time applications that need to display regularly updated information without relying on problematic infinite loops in the backend. The current version is 1.0.1, with releases typically tied to bug fixes or minor enhancements.

pip install streamlit-autorefresh
INSTALL
IMPORT
SIG · STREAMLIT-AUTOREFR
S
streamlit-autorefresh
web-frameworkpythonv1.0.1
Install
15.6s avg
Import
1381ms
Disk
436MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 1.780s · 448.2MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 15.6s · import 0.982s · 417MB
436MB installed
● package 436MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

st_autorefresh
from streamlit_autorefresh import st_autorefresh

This example demonstrates how to use `st_autorefresh` to trigger reruns of your Streamlit app at a specified interval (2 seconds) and limit the number of refreshes (100 times). It also shows how to use the returned count to display dynamic content.

import streamlit as st from streamlit_autorefresh import st_autorefresh import datetime st.set_page_config(layout='centered', initial_sidebar_state='auto', page_title='Autorefresh Demo') st.title("Streamlit Autorefresh Demo") # Run the autorefresh every 2000 milliseconds (2 seconds) and stop after 100 refreshes count = st_autorefresh(interval=2000, limit=100, key="myautocounter") if count == 0: st.write("Count is zero") elif count % 3 == 0 and count % 5 == 0: st.write("FizzBuzz") elif count % 3 == 0: st.write("Fizz") elif count % 5 == 0: st.write("Buzz") else: st.write(f"Current Count: {count}") st.write(f"Last refreshed at: {datetime.datetime.now().strftime('%H:%M:%S')}")
Debug
Known issues
gotchaUsing a very small `interval` can lead to high CPU utilization on the server, as it constantly pings Streamlit to rerun the script. This can consume significant computing resources.
fix
Use a reasonable `interval` (e.g., several seconds or more) based on your application's actual data update frequency. Monitor server resource usage during development.
affects: All versions
gotchaIf the `key` parameter is not provided or changed, `st_autorefresh` might remount on the Streamlit frontend, leading to a loss of its internal state (like the refresh count).
fix
Always provide a unique `key` parameter to `st_autorefresh`. If you intend to reset the refresh count, change the `key` to a new unique string.
affects: All versions
gotchaUser interactions (e.g., button clicks, widget changes) within the set refresh interval will cause a full Streamlit rerun and effectively reset the `st_autorefresh` timer. This means refreshes might not occur at perfectly fixed intervals from the app's initial load if user interaction is frequent.
fix
This is expected behavior due to Streamlit's rerun model. If strict timing is critical, consider making `st_autorefresh` less susceptible to user interaction by adjusting its placement or using Streamlit's session state more carefully for critical timers.
affects: All versions
gotchaThe `streamlit-autorefresh` component works by having the browser ping the server. If the user's browser tab is closed, goes to sleep, or loses its WebSocket connection to the server (e.g., due to network issues or deployment environment timeouts), the auto-refresh mechanism will stop working.
fix
Ensure stable network connectivity for clients. For deployed apps, configure server/proxy timeouts to be sufficiently long to maintain WebSocket connections. This component is not designed for server-side-initiated push updates or unattended refreshes when the client is disconnected.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'streamlit_autorefresh'
The 'streamlit-autorefresh' library is either not installed in your environment or there is a typo in the import statement.
fix
Install the library using pip: `pip install streamlit-autorefresh`
NameError: name 'st_autorefresh' is not defined
The 'st_autorefresh' function was called without being imported from the 'streamlit_autorefresh' library.
fix
Add the import statement at the top of your Streamlit application: `from streamlit_autorefresh import st_autorefresh`
TypeError: 'str' object cannot be interpreted as an integer
The 'interval' argument of the `st_autorefresh` function expects an integer representing milliseconds, but a string was provided.
fix
Pass an integer value for the 'interval' argument: `st_autorefresh(interval=5000)`
TypeError: st_autorefresh() got an unexpected keyword argument 'interval_secs'
An incorrect keyword argument name was used when calling `st_autorefresh`. The correct argument name for the refresh interval is `interval`.
fix
Change the argument name from `interval_secs` to `interval`: `st_autorefresh(interval=3000)`
TypeError: 'float' object cannot be interpreted as an integer
The 'interval' argument of the `st_autorefresh` function expects an integer representing milliseconds, but a float was provided.
fix
Pass an integer value for the 'interval' argument: `st_autorefresh(interval=2500)`
Upgrade
Version history
1.0.1latest on PyPI · released Jun 25, 2023
Audit
Dependencies
streamlitrequiredstreamlit-autorefresh is a custom Streamlit component and requires Streamlit to function.
Agent activity
21 hits · last 30 days
node
18
OpenAI (training)
1
Resources