# PythonAppResource Constructors

- Package: [Aspire.Hosting.Python](/reference/api/csharp/aspire.hosting.python.md)
- Type: [PythonAppResource](/reference/api/csharp/aspire.hosting.python/pythonappresource.md)
- Kind: `Constructors`
- Members: `1`

Represents a Python application resource in the distributed application model.

## PythonAppResource(string, string, string)

- Name: `Constructor(string, string, string)`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting.Python/PythonAppResource.cs#L63)

Represents a Python application resource in the distributed application model.

```csharp
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:

  - An absolute path: "/usr/bin/python3"
  - A relative path: "./venv/bin/python"
  - A command on the PATH: "python" or "python3"

  The executable is typically located in a virtual environment's bin (Linux/macOS) or Scripts (Windows) directory.
- `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:

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

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