Skip to content
Docs Try Aspire

PythonAppResource

Class net8.0
📦 Aspire.Hosting.Python v13.2.0
Represents a Python application resource in the distributed application model.
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
{
// ...
}
ExecutableResourceIContainerFilesDestinationResourceIResourceIResourceWithEndpointsIResourceWithServiceDiscovery

This 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:

  • System Python installations
  • Virtual environments (venv)
  • Conda environments
  • UV-based Python environments

Add 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();