This is a Python package to turn functions into internal apps powered by Streamlit. It creates forms based on the function's annotation and allows you to run the function with the form's values. Note that this is early-stage project with limited functionality.
This package provides StreamlitInternalApp
class that you can use to create internal apps. It provides component
method decorator that turns any Python function into ComponentForm
class. It is responsible for rendering form with this function arguments as input fields and return type as output. It doesn't infer the runtime types, but rely completely on the typing
annotations. The function's docstring is used as a form's description. Once the form is submitted, the function is called with the form's values and the result is displayed in the output section.
StreamlitInternalApp
is composed of multiple ComponentForm
instances. It is responsible for rendering the sidebar with the list of available forms and the main section with the selected form. It also provides a way to add custom components to the sidebar.
pip install streamlit-internal-app
This package requires Python 3.11+ and Streamlit 1.29+.
StreamlitInternalApp is opinionated and designed to be as simple as possible. Custom validation on the UI side is not supported. It is expected that the function will validate the input and raise an exception if the input is invalid. The exception will be displayed in the output section.
Here is a simple example:
from streamlit_internal_app import StreamlitInternalApp
app = StreamlitInternalApp(title="Example app", description="This is an example app.")
@app.component
def add(a: int, b: int) -> int:
"""Adds two numbers."""
return a + b
app.render()
That's all you need to do to create an internal app. You can the application by executing python -m streamlit run path/to/script.py
.
Here is a table of supported types:
If your annotation is not in the list, the output will be rendered with st.write
by default.
Here is a short demo of how the example app looks like:
Refer to /tests/static/example_app.py
for a full example.
If you have poetry installed you can run the example app with scripts/run_sample_app.sh
, or you can do it with development Docker image.
Refer to scripts/
directory on how to run unit tests, formatting and linting.
There is a built-in support for logging. You can pass use_logging=True
into StreamlitInternalApp
constructor to enable it. It will add custom logging handler that outputs the logs into the output section. "Count weekend days" in /tests/static/example_app.py
is an example.