다음을 통해 공유


PythonAppResource Class

Definition

Represents a Python application resource in the distributed application model.

public class PythonAppResource : Aspire.Hosting.ApplicationModel.ExecutableResource, Aspire.Hosting.ApplicationModel.IContainerFilesDestinationResource, Aspire.Hosting.IResourceWithServiceDiscovery
public class PythonAppResource : Aspire.Hosting.ApplicationModel.ExecutableResource, Aspire.Hosting.IResourceWithServiceDiscovery
type PythonAppResource = class
    inherit ExecutableResource
    interface IResourceWithServiceDiscovery
    interface IResourceWithEndpoints
    interface IResource
    interface IContainerFilesDestinationResource
type PythonAppResource = class
    inherit ExecutableResource
    interface IResourceWithServiceDiscovery
    interface IResourceWithEndpoints
    interface IResource
Public Class PythonAppResource
Inherits ExecutableResource
Implements IContainerFilesDestinationResource, IResourceWithServiceDiscovery
Public Class PythonAppResource
Inherits ExecutableResource
Implements IResourceWithServiceDiscovery
Inheritance
PythonAppResource
Derived
Implements

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:

Constructors

PythonAppResource(String, String, String)

Represents a Python application resource in the distributed application model.

Properties

Annotations

Gets the annotations associated with the resource.

(Inherited from Resource)
Command

Gets the command associated with this executable resource.

(Inherited from ExecutableResource)
Name

Gets the name of the resource.

(Inherited from Resource)
WorkingDirectory

Gets the working directory for the executable resource.

(Inherited from ExecutableResource)

Extension Methods

GetArgumentValuesAsync(IResourceWithArgs, DistributedApplicationOperation)

Get the arguments from the given resource.

GetDeploymentTargetAnnotation(IResource, IComputeEnvironmentResource)

Gets the deployment target for the specified resource, if any. Throws an exception if there are multiple compute environments and a compute environment is not explicitly specified.

GetEndpoint(IResourceWithEndpoints, String, NetworkIdentifier)

Gets an endpoint reference for the specified endpoint name.

GetEndpoint(IResourceWithEndpoints, String)

Gets an endpoint reference for the specified endpoint name.

GetEndpoints(IResourceWithEndpoints, NetworkIdentifier)

Gets references to all endpoints for the specified resource.

GetEndpoints(IResourceWithEndpoints)

Gets references to all endpoints for the specified resource.

GetEnvironmentVariableValuesAsync(IResourceWithEnvironment, DistributedApplicationOperation)

Get the environment variables from the given resource.

GetReplicaCount(IResource)

Gets the number of replicas for the specified resource. Defaults to 1 if no ReplicaAnnotation is found.

HasAnnotationIncludingAncestorsOfType<T>(IResource)

Gets whether resource or its ancestors have an annotation of type T

HasAnnotationOfType<T>(IResource)

Gets whether resource has an annotation of type T

IsExcludedFromPublish(IResource)

Gets a value indicating whether the resource is excluded from being published.

ProcessArgumentValuesAsync(IResource, DistributedApplicationExecutionContext, Action<Object,String,Exception,Boolean>, ILogger, String, CancellationToken)

Processes argument values for the specified resource in the given execution context.

ProcessArgumentValuesAsync(IResource, DistributedApplicationExecutionContext, Action<Object,String,Exception,Boolean>, ILogger, CancellationToken)

Processes argument values for the specified resource in the given execution context.

ProcessEnvironmentVariableValuesAsync(IResource, DistributedApplicationExecutionContext, Action<String,Object,String,Exception>, ILogger, String, CancellationToken)

Processes environment variable values for the specified resource within the given execution context.

ProcessEnvironmentVariableValuesAsync(IResource, DistributedApplicationExecutionContext, Action<String,Object,String,Exception>, ILogger, CancellationToken)

Processes environment variable values for the specified resource within the given execution context.

RequiresImageBuild(IResource)

Determines whether the specified resource requires image building.

RequiresImageBuildAndPush(IResource)

Determines whether the specified resource requires image building and pushing.

TryGetAnnotationsIncludingAncestorsOfType<T>(IResource, IEnumerable<T>)

Attempts to retrieve all annotations of the specified type from the given resource including from parents.

TryGetAnnotationsOfType<T>(IResource, IEnumerable<T>)

Attempts to retrieve all annotations of the specified type from the given resource.

TryGetContainerImageName(IResource, Boolean, String)

Attempts to get the container image name from the given resource.

TryGetContainerImageName(IResource, String)

Attempts to get the container image name from the given resource.

TryGetContainerMounts(IResource, IEnumerable<ContainerMountAnnotation>)

Attempts to get the container mounts for the specified resource.

TryGetEndpoints(IResource, IEnumerable<EndpointAnnotation>)

Attempts to retrieve the endpoints for the given resource.

TryGetEnvironmentVariables(IResource, IEnumerable<EnvironmentCallbackAnnotation>)

Attempts to get the environment variables from the given resource.

TryGetLastAnnotation<T>(IResource, T)

Attempts to get the last annotation of the specified type from the resource.

TryGetUrls(IResource, IEnumerable<ResourceUrlAnnotation>)

Attempts to retrieve the URLs for the given resource.

IsContainer(IResource)

Determines whether the specified resource is a container resource.

IsEmulator(IResource)

Determines whether the specified resource is an emulator resource.

IsExisting(IResource)

Determines if the resource is an existing resource.

Applies to