# PythonAppResource

- Kind: `class`
- Package: [Aspire.Hosting.Python](/reference/api/csharp/aspire.hosting.python.md)
- Version: `13.4.0`
- Namespace: `Aspire.Hosting.Python`
- Target framework: `net8.0`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting.Python/PythonAppResource.cs)
- Inherits: `ExecutableResource`
- Implements: `IContainerFilesDestinationResource`, `IResource`, `IResourceWithEndpoints`, `IResourceWithServiceDiscovery`

Represents a Python application resource in the distributed application model.

## Definition

```csharp
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
{
    // ...
}
```

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

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

## Constructors

- [PythonAppResource(string, string, string)](/reference/api/csharp/aspire.hosting.python/pythonappresource/constructors.md#constructor-string-string-string) -- Represents a Python application resource in the distributed application model.

## Examples

Add a Python web application using Flask or FastAPI:

```csharp
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();
```
