PythonAppResource
namespace Aspire.Hosting.Python;
public class PythonAppResource : Aspire.Hosting.ApplicationModel.ExecutableResource, Aspire.Hosting.ApplicationModel.IContainerFilesDestinationResource, Aspire.Hosting.ApplicationModel.IResource, Aspire.Hosting.ApplicationModel.IResourceWithEndpoints, Aspire.Hosting.IResourceWithServiceDiscovery{ // ...}Remarks
Section titled RemarksThis resource allows Python applications (scripts, web servers, APIs, background services) to run as part of a distributed application. The resource manages the Python executable, working directory, and lifecycle of the Python application.
Python applications can expose HTTP endpoints, communicate with other services, and participate in service discovery like other Aspire resources. They support automatic OpenTelemetry instrumentation for observability when configured with the appropriate Python packages.
This resource supports various Python execution environments including:
Constructors1
Section titled ConstructorsExamples
Section titled ExamplesAdd a Python web application using Flask or FastAPI:
var builder = DistributedApplication.CreateBuilder(args);
var python = builder.AddPythonApp("api", "../python-api", "app.py") .WithHttpEndpoint(port: 5000) .WithArgs("--host", "0.0.0.0");
builder.AddProject<Projects.Frontend>("frontend") .WithReference(python);
builder.Build().Run();