Share via


PythonAppResourceBuilderExtensions.AddPythonExecutable Method

Definition

Adds a Python executable to the application model.

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.Python.PythonAppResource> AddPythonExecutable(this Aspire.Hosting.IDistributedApplicationBuilder builder, string name, string appDirectory, string executableName);
static member AddPythonExecutable : Aspire.Hosting.IDistributedApplicationBuilder * string * string * string -> Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.Python.PythonAppResource>
<Extension()>
Public Function AddPythonExecutable (builder As IDistributedApplicationBuilder, name As String, appDirectory As String, executableName As String) As IResourceBuilder(Of PythonAppResource)

Parameters

name
String

The name of the resource.

appDirectory
String

The path to the directory containing the python application.

executableName
String

The name of the executable in the virtual environment (e.g., "pytest", "uvicorn", "flask").

Returns

A reference to the IResourceBuilder<T>.

Examples

Add a pytest executable to the application model:

var builder = DistributedApplication.CreateBuilder(args);

builder.AddPythonExecutable("pytest", "../api", "pytest")
       .WithArgs("-q")
       .WithDebugging();

builder.Build().Run();

Remarks

This method runs an executable from the virtual environment's bin directory. By default, the virtual environment folder is expected to be named .venv and located in the app directory. Use WithVirtualEnvironment<T>(IResourceBuilder<T>, String, Boolean) to specify a different virtual environment path. Use WithArgs to pass arguments to the executable.

Unlike scripts and modules, Python executables do not have debugging support enabled by default. Use WithDebugging<T>(IResourceBuilder<T>) to explicitly enable debugging support if the executable is a Python-based tool that can be debugged.

Applies to