PythonAppResource Constructors
Constructor(string, string, string) Section titled Constructor(string, string, string) public class PythonAppResource{ public PythonAppResource( string name, string executablePath, string appDirectory) { // ... }}Parameters
name string The name of the resource in the application model. executablePath string The path to the Python executable. This can be: appDirectory string The working directory for the Python application. Python scripts and modules will be resolved relative to this directory. This is typically the root directory of your Python project containing your main script and any local modules. Remarks
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:
Examples
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();