streamlit-embedcode is a Streamlit custom component that simplifies embedding code snippets from various popular services, including GitHub Gist, GitLab Snippets, Pastebin, CodePen, Ideone, and TagMyCode, directly into Streamlit applications. The library is currently at version 0.1.2. It has an infrequent release cadence, with the last update in May 2021, suggesting a stable and mature, albeit not actively feature-developed, component.
pip install streamlit-embedcodeVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to embed a GitHub Gist into a Streamlit application using the `github_gist` function. The example also shows how to set optional parameters for the embedded content.
Users may need to adjust their browser's security settings to allow third-party cookies or site data for the embedded content to display correctly.
Monitor the stability and embedding policies of the target code-sharing service. Consider providing alternative methods or direct code display using `st.code` as a fallback.
Familiarize yourself with Streamlit's execution model and use `st.session_state` to persist values that should not reset on reruns.
Instruct users to check their browser settings and potentially allow third-party cookies or loosen site isolation settings for the domain hosting the embedded content. Some issues might be resolved by Streamlit itself in newer versions if related to its iframe handling.
Ensure the library is installed with `pip install streamlit-embedcode`. Verify the import statement is `from streamlit_embedcode import [service_function]`, e.g., `from streamlit_embedcode import github_gist`. Check for typos in function names.
Manually stop and restart the Streamlit application from the terminal (`Ctrl+C`, then `streamlit run your_app.py`). Clear your browser's cache, or try a hard refresh (`Ctrl+Shift+R` or `Cmd+Shift+R`). Ensure `watchdog` is installed (`pip install watchdog`) and Streamlit's `fileWatcherType` configuration is set correctly (e.g., `[server] fileWatcherType = "watchdog"`).