Streamlit Faker
streamlit-faker is a Python library designed to easily fake Streamlit commands. It allows developers to quickly draft a user interface or use it as a QA tool by generating random parameters for Streamlit functions, streamlining the prototyping process. It is built upon the popular `faker` project. The current version is 0.0.4, and it has an active, though not rapid, release cadence.
Common errors
-
ModuleNotFoundError: No module named 'streamlit_faker'
cause The `streamlit-faker` package is not installed in the current Python environment.fixRun `pip install streamlit-faker` to install the library. -
AttributeError: 'StreamlitFaker' object has no attribute 'non_existent_command'
cause Attempting to call a Streamlit command that does not exist or is not supported by the `streamlit-faker` wrapper.fixVerify the Streamlit command name against the official Streamlit documentation. `streamlit-faker` aims to support common Streamlit commands but might not cover all edge cases or newly introduced APIs immediately.
Warnings
- gotcha streamlit-faker is primarily designed for rapid prototyping and UI drafting. It generates plausible, but random, data and may not accurately reflect complex real-world Streamlit app behavior, especially concerning intricate user interactions, state management, or custom components.
- gotcha When migrating from faked UI to real Streamlit components, ensure proper handling of widget keys (`key` parameter) and `st.session_state` to prevent unexpected behavior. The faked commands automatically handle some aspects, which need manual attention in real code.
- deprecated Prior to v0.0.4, the library internally relied on `streamlit-extras`. This dependency was replaced with `altex`. While this was primarily an internal change, users relying on any indirectly exposed `streamlit-extras` functionality might need to adjust their assumptions about underlying components.
Install
-
pip install streamlit-faker
Imports
- get_streamlit_faker
import streamlit_faker
from streamlit_faker import get_streamlit_faker
Quickstart
import streamlit as st
from streamlit_faker import get_streamlit_faker
st.title("Streamlit Faker Demo")
st_faker = get_streamlit_faker(seed=42) # Optional: set a seed for reproducible fake data
st.subheader("Faked UI Elements:")
st_faker.markdown()
st_faker.selectbox()
st_faker.slider()
st_faker.map()
st_faker.button("Faked Button")
st.info("This entire section was generated with fake data using streamlit-faker.")