-
Notifications
You must be signed in to change notification settings - Fork 168
Add Python templates and onboarding documentation #5304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7619157
Initial plan
Copilot 2e8bfba
Add Python template and onboarding documentation
Copilot b79c5b3
Fix Python version requirement consistency
Copilot 70d2439
Update Python template docs to use Aspire CLI and correct template st…
Copilot d35361e
Remove duplicate File-based AppHost section
Copilot 718554a
Apply all suggestions from @alistairmatthews review
Copilot 32143c8
Change .NET CLI commands to Aspire CLI in build-aspire-apps-with-pyth…
Copilot 362b7c2
Replace CLI commands with interactive Aspire CLI steps
Copilot ea3142e
Integrated feedback from @davidfowl.
alistairmatthews 8f9dd7f
Added an aspire run screenshot and updated another.
alistairmatthews e7dd915
A couple of small corrections.
alistairmatthews 75a6d9c
Update docs/get-started/build-aspire-python-app.md
alistairmatthews File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,17 @@ The following Aspire solution templates are available, assume the solution is na | |
| - **AspireSample.Web**: An [ASP.NET Core Blazor App](/aspnet/core/blazor) project with default Aspire service configurations, this project depends on the [**AspireSample.ServiceDefaults**](#service-defaults) project. | ||
| - **AspireSample.Test**: Either an [MSTest](#mstest-project), [NUnit](#nunit-project), or [xUnit](#xunit-project) test project with project references to the [**AspireSample.AppHost**](#app-host) and an example _WebTests.cs_ file demonstrating an integration test. | ||
|
|
||
| <a name="python-app"></a> | ||
|
|
||
| - **Aspire Python App**: A full-stack Aspire application with a Python backend and JavaScript frontend. This template uses a file-based AppHost and includes: | ||
alistairmatthews marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - **apphost.cs**: A file-based AppHost that orchestrates the Python backend and JavaScript frontend. | ||
alistairmatthews marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - **app**: A Python backend using [FastAPI](https://fastapi.tiangolo.com/) framework with OpenTelemetry instrumentation. | ||
alistairmatthews marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - **frontend**: A JavaScript frontend using [React](https://react.dev/) framework with Vite. | ||
alistairmatthews marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| > [!NOTE] | ||
| > The Aspire Python template is currently under development. For more information and updates, see [GitHub: Aspire issue #11865](https://github.com/dotnet/aspire/issues/11865). For now, you can manually add Python applications to an existing Aspire solution using the guidance in [Orchestrate Python apps in Aspire](../get-started/build-aspire-apps-with-python.md). | ||
alistairmatthews marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### Project templates | ||
|
|
||
| The following Aspire project templates are available: | ||
|
|
@@ -96,21 +107,30 @@ To create an Aspire solution or project using the .NET CLI, use the [dotnet new] | |
|
|
||
| To create a basic [Aspire AppHost](app-host-overview.md) project targeting the latest .NET version: | ||
|
|
||
| ```dotnetcli | ||
| dotnet new aspire-apphost | ||
| ```Aspire | ||
| aspire new aspire-apphost | ||
| ``` | ||
|
|
||
| To create an Aspire starter app, which is a full solution with a sample UI and backing API included: | ||
|
|
||
| ```dotnetcli | ||
| dotnet new aspire-starter | ||
| ```Aspire | ||
| aspire new aspire-starter | ||
| ``` | ||
|
|
||
| To create an Aspire app with a Python backend and JavaScript frontend: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be using aspire new not dotnet new
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know, I have it going to work... see #5304 (review) |
||
|
|
||
| ```Aspire | ||
| aspire new aspire-py-starter | ||
| ``` | ||
|
|
||
| > [!NOTE] | ||
| > The `aspire-py-starter` template is currently under development. For more information, see [Build an Aspire app with Python and JavaScript](../get-started/build-aspire-python-app.md). | ||
|
|
||
| > [!TIP] | ||
| > Aspire templates default to using the latest .NET version, even when using an earlier version of the .NET CLI. To manually specify the .NET version, use the `--framework <tfm>` option, e.g. to create a basic [Aspire AppHost](app-host-overview.md) project targeting .NET 8: | ||
| > Aspire templates default to using the latest .NET version, even when using an earlier version of the .NET CLI. To manually specify the .NET version, use the `--framework <tfm>` option, for example to create a basic [Aspire AppHost](app-host-overview.md) project targeting .NET 8: | ||
| > | ||
| > ```dotnetcli | ||
| > dotnet new aspire-apphost --framework net8.0 | ||
| > ```Aspire | ||
| > aspire new aspire-apphost --framework net8.0 | ||
alistairmatthews marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| > ``` | ||
|
|
||
| You need to trust the ASP.NET Core :::no-loc text="localhost"::: certificate before running the app. Run the following command: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,192 @@ | ||
| --- | ||
| title: Build an Aspire app with Python and JavaScript | ||
| description: Learn how to create a new Aspire application with a Python backend and JavaScript frontend using the Aspire Python template. | ||
| ms.date: 10/17/2025 | ||
| ms.custom: sfi-image-nochange | ||
| ai-usage: ai-assisted | ||
| --- | ||
|
|
||
| # Build an Aspire app with Python and JavaScript | ||
|
|
||
| In this article, you learn how to create a new Aspire application using the Aspire Python template. The template creates a solution with a Python backend (using [FastAPI](https://fastapi.tiangolo.com/)) and a JavaScript frontend (using [React](https://react.dev/)), orchestrated by Aspire. This approach is ideal for Python developers who want to build observable, production-ready applications with modern JavaScript frontends. | ||
|
|
||
| > [!NOTE] | ||
| > The Aspire Python template is currently under development. This documentation will be updated as the template becomes available. For now, you can follow the guidance in [Orchestrate Python apps in Aspire](build-aspire-apps-with-python.md) to manually add Python applications to an existing Aspire solution. | ||
| > [!TIP] | ||
| > If you already have an existing Python application and want to add Aspire to it, see [Orchestrate Python apps in Aspire](build-aspire-apps-with-python.md). | ||
| [!INCLUDE [aspire-prereqs](../includes/aspire-prereqs.md)] | ||
|
|
||
alistairmatthews marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Additionally, you need to install [Python](https://www.python.org/downloads) on your machine. This article requires Python version 3.12 or later. To verify your Python and pip versions, run the following commands: | ||
|
|
||
| ```console | ||
| python --version | ||
| ``` | ||
|
|
||
| ```console | ||
| pip --version | ||
| ``` | ||
|
|
||
| To download Python (including `pip`), see the [Python download page](https://www.python.org/downloads). | ||
|
|
||
| You also need to install [Node.js](https://nodejs.org/en/download/package-manager) for the JavaScript frontend. To verify your Node.js and npm versions, run the following commands: | ||
|
|
||
| ```console | ||
| node --version | ||
| ``` | ||
|
|
||
| ```console | ||
| npm --version | ||
| ``` | ||
|
|
||
| To download Node.js (including `npm`), see the [Node.js download page](https://nodejs.org/en/download/package-manager). | ||
|
|
||
| ## Create an Aspire project using the Python template | ||
|
|
||
| > [!IMPORTANT] | ||
| > The `aspire-py-starter` template is currently being developed and might not be available yet. Once released, you'll be able to create a Python-based Aspire application using the following command. For updates on template availability, see [Aspire Python Templates (issue #11865)](https://github.com/dotnet/aspire/issues/11865). | ||
alistairmatthews marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| To create a new Aspire application with a Python backend and JavaScript frontend, use the `aspire-py-starter` template: | ||
|
|
||
| ```Aspire | ||
| aspire new aspire-py-starter | ||
| ``` | ||
alistairmatthews marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| This command creates a new Aspire solution with the following structure: | ||
|
|
||
| - **apphost.cs**: A file-based AppHost that orchestrates the Python backend and JavaScript frontend. | ||
| - **app**: A Python backend using [FastAPI](https://fastapi.tiangolo.com/) framework. | ||
| - **frontend**: A JavaScript frontend using [React](https://react.dev/) framework with Vite. | ||
|
|
||
| ## Explore the project structure | ||
|
|
||
| Navigate to the newly created project directory: | ||
|
|
||
| ```console | ||
| cd MyPythonApp | ||
| ``` | ||
|
|
||
| ### File-based AppHost | ||
|
|
||
| The solution uses a file-based AppHost with a single _apphost.cs_ file. This file contains the orchestration logic for both the Python backend and JavaScript frontend. The AppHost uses `AddPythonScript` to add the Python backend and `AddViteApp` to add the React frontend. | ||
alistairmatthews marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### Python backend | ||
|
|
||
| The Python backend is located in the _app_ directory. It uses the [FastAPI](https://fastapi.tiangolo.com/) framework to create RESTful APIs. The backend includes: | ||
|
|
||
| - A virtual environment for Python dependencies. | ||
| - A _requirements.txt_ file listing required Python packages. | ||
| - An _app.py_ file containing the FastAPI application code. | ||
| - OpenTelemetry instrumentation for observability. | ||
|
|
||
| ### JavaScript frontend | ||
|
|
||
| The JavaScript frontend is located in the _frontend_ directory. It uses [React](https://react.dev/) with Vite to create the user interface. The frontend includes: | ||
alistairmatthews marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - A _package.json_ file listing required npm packages. | ||
| - Source code in the _src_ directory. | ||
| - Configuration for connecting to the backend API. | ||
|
|
||
| ## Set up the Python environment | ||
|
|
||
| Navigate to the Python backend directory: | ||
|
|
||
| ```console | ||
| cd app | ||
| ``` | ||
|
|
||
| Create and activate a Python virtual environment: | ||
|
|
||
| ### [Unix/macOS](#tab/bash) | ||
|
|
||
| ```bash | ||
| python -m venv .venv | ||
| source .venv/bin/activate | ||
| ``` | ||
|
|
||
| ### [Windows](#tab/powershell) | ||
|
|
||
| ```powershell | ||
| python -m venv .venv | ||
| .venv\Scripts\Activate.ps1 | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| Install the Python dependencies: | ||
|
|
||
| ```console | ||
| python -m pip install --upgrade pip | ||
| python -m pip install -r requirements.txt | ||
| ``` | ||
|
|
||
| ## Set up the JavaScript environment | ||
|
|
||
| Navigate to the JavaScript frontend directory: | ||
|
|
||
| ```console | ||
| cd ../frontend | ||
| ``` | ||
|
|
||
| Install the npm dependencies: | ||
|
|
||
| ```console | ||
| npm install | ||
| ``` | ||
|
|
||
| ## Run the application | ||
|
|
||
| Navigate back to the solution root directory: | ||
|
|
||
| ```console | ||
| cd .. | ||
| ``` | ||
|
|
||
| Run the AppHost to start the application: | ||
|
|
||
| ```Aspire | ||
| aspire run | ||
| ``` | ||
|
|
||
| The Aspire dashboard opens in your browser. You should see both the Python backend and JavaScript frontend listed as resources. | ||
|
|
||
| ## Explore the Aspire dashboard | ||
|
|
||
| The Aspire dashboard provides a unified view of your application's resources, including: | ||
|
|
||
| - **Resources**: View all running services (Python backend and JavaScript frontend). | ||
| - **Logs**: See consolidated logs from all services. | ||
| - **Traces**: Monitor distributed traces across your application. | ||
| - **Metrics**: View performance metrics and telemetry data. | ||
|
|
||
| Select the **Endpoints** link for each resource to access: | ||
|
|
||
| - The React frontend user interface. | ||
| - The FastAPI backend API documentation (Swagger UI). | ||
|
|
||
| ## Understand telemetry and observability | ||
|
|
||
| The Python backend and JavaScript frontend are both configured with OpenTelemetry for observability. This means: | ||
|
|
||
| - **Logs** from both applications are collected and displayed in the Aspire dashboard. | ||
| - **Traces** show the flow of requests across services. | ||
| - **Metrics** provide insights into application performance. | ||
|
|
||
| The template includes OpenTelemetry packages configured to export telemetry data to the Aspire dashboard automatically. | ||
|
|
||
| ## Next steps | ||
|
|
||
| Now that you have a working Aspire application with Python and JavaScript: | ||
|
|
||
| - Explore the FastAPI backend code and add new API endpoints. | ||
| - Customize the React frontend to create your user interface. | ||
| - Add additional services or resources to your AppHost. | ||
| - Deploy your application to a cloud environment. | ||
|
|
||
| ## See also | ||
|
|
||
| - [Orchestrate Python apps in Aspire](build-aspire-apps-with-python.md) | ||
| - [Orchestrate Node.js apps in Aspire](build-aspire-apps-with-nodejs.md) | ||
| - [Aspire templates](../fundamentals/aspire-sdk-templates.md) | ||
| - [GitHub: Aspire issue #11865 - Python Templates](https://github.com/dotnet/aspire/issues/11865) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.