Skip to content
Docs Try Aspire

StreamlitAppHostingExtension Methods

Class Methods 1 member
Provides extension methods for adding Streamlit applications to an Hosting.IDistributedApplicationBuilder.
AddStreamlitApp(IDistributedApplicationBuilder, string, string, string) Section titled AddStreamlitApp(IDistributedApplicationBuilder, string, string, string) extension IResourceBuilder<StreamlitAppResource>
Adds a Streamlit application to the application model.
public static class StreamlitAppHostingExtension
{
public static IResourceBuilder<StreamlitAppResource> AddStreamlitApp(
this IDistributedApplicationBuilder builder,
string name,
string appDirectory,
string scriptPath)
{
// ...
}
}
builder IDistributedApplicationBuilder The Hosting.IDistributedApplicationBuilder to add the resource to.
name string The name of the Streamlit application.
appDirectory string The path to the directory containing the Streamlit application.
scriptPath string The path to the Python script to be run by Streamlit (relative to appDirectory).
IResourceBuilder<StreamlitAppResource> An ApplicationModel.IResourceBuilder`1 for the Streamlit application resource.

This method uses the Aspire.Hosting.Python integration to run Streamlit applications. By default, it uses the .venv virtual environment in the app directory. Use standard Python extension methods like WithVirtualEnvironment, WithPip, or WithUv to customize the environment.

**⚠️ EXPERIMENTAL:** This integration is experimental and subject to change. The underlying implementation will be updated to use public APIs when they become available in Aspire.Hosting.Python (expected in Aspire 13.1).

Add a Streamlit application to the application model:

var builder = DistributedApplication.CreateBuilder(args);
builder.AddStreamlitApp("dashboard", "../streamlit-app", "app.py")
.WithHttpEndpoint(env: "PORT");
builder.Build().Run();