PythonAppResource(String, String, String) Constructor
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Represents a Python application resource in the distributed application model.
public PythonAppResource(string name, string executablePath, string appDirectory);
new Aspire.Hosting.Python.PythonAppResource : string * string * string -> Aspire.Hosting.Python.PythonAppResource
Public Sub New (name As String, executablePath As String, appDirectory As String)
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.
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();
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: