Skip to content
DocsTry Aspire
DocsTry

StreamlitAppHostingExtension Methods

ClassMethods1 member
Provides extension methods for adding Streamlit applications to an Hosting.IDistributedApplicationBuilder.
AddStreamlitApp(IDistributedApplicationBuilder, string, string, string)Section titled AddStreamlitApp(IDistributedApplicationBuilder, string, string, string)extensionIResourceBuilder<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)
{
// ...
}
}
builderIDistributedApplicationBuilderThe Hosting.IDistributedApplicationBuilder to add the resource to.
namestringThe name of the Streamlit application.
appDirectorystringThe path to the directory containing the Streamlit application.
scriptPathstringThe 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();