From c8224770b69e8a7ae79c6c996f525822a69678ef Mon Sep 17 00:00:00 2001 From: Tommaso Stocchi Date: Tue, 19 Nov 2024 17:22:50 +0100 Subject: [PATCH 1/6] article for python - uvicorn --- .../hosting-python-extensions.md | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 docs/community-toolkit/hosting-python-extensions.md diff --git a/docs/community-toolkit/hosting-python-extensions.md b/docs/community-toolkit/hosting-python-extensions.md new file mode 100644 index 0000000000..799ade5fce --- /dev/null +++ b/docs/community-toolkit/hosting-python-extensions.md @@ -0,0 +1,58 @@ +--- +title: Python hosting extensions +description: Learn about the .NET Aspire Community Toolkit Python hosting extensions package which provides extra functionality to the .NET Aspire Python hosting package. +ms.date: 11/19/2024 +--- + +# .NET Aspire Community Toolkit Python hosting extensions + +[!INCLUDE [includes-hosting](../includes/includes-hosting.md)] + +[!INCLUDE [banner](includes/banner.md)] + +In this article, you learn about the .NET Aspire Community Toolkit Python hosting extensions package which provides extra functionality to the .NET Aspire [Python hosting package](https://nuget.org/packages/Aspire.Hosting.Python). +The extensions package lets you run [Uvicorn](https://www.uvicorn.org/) applications. + +## Hosting integration + +To get started with the .NET Aspire Community Toolkit Python hosting extensions, install the [📦 CommunityToolkit.Aspire.Hosting.Python.Extensions](https://nuget.org/packages/CommunityToolkit.Aspire.Hosting.Python.Extensions) NuGet package in the AppHost project. + +### [.NET CLI](#tab/dotnet-cli) + +```dotnetcli +dotnet add package CommunityToolkit.Aspire.Hosting.Python.Extensions +``` + +### [PackageReference](#tab/package-reference) + +```xml + +``` + +--- + +For more information, see [dotnet add package](/dotnet/core/tools/dotnet-add-package) or [Manage package dependencies in .NET applications](/dotnet/core/tools/dependencies). + +## Example usage + +To work with Python apps, they need to be within a virtual environment. To create a virtual environment, refer to the [Initialize the Python virtual environment](../get-started/build-aspire-apps-with-python.md?tabs=powershell#initialize-the-python-virtual-environment) section. + +In the _:::no-loc text="Program.cs":::_ file of your app host project, call the `AddUvicornApp` method to add a Uvicorn application to the builder. + +```csharp +var builder = DistributedApplication.CreateBuilder(args); + +var uvicorn = builder.AddUvicornApp("uvicornapp", "../uvicornapp-api", "main:app") + .WithHttpEndpoint(env: "PORT"); +``` + +The `PORT` environment variable is used to determine the port the Uvicorn application should listen on. By default, this port is randomly assigned by .NET Aspire. The name of the environment variable can be changed by passing a different value to the method. + +The Uvicorn application can be added as a reference to other resources in the AppHost project. + +## See also + +- [Orchestrate Python apps in .NET Aspire](../get-started/build-aspire-apps-with-Python.md) +- [.NET Aspire Community Toolkit GitHub repo](https://github.com/CommunityToolkit/Aspire) +- [Sample Python apps](https://github.com/CommunityToolkit/Aspire/tree/main/examples/python) From fea61f39d907d07efa143bbe864a253c58ee1283 Mon Sep 17 00:00:00 2001 From: Tommaso Stocchi Date: Tue, 19 Nov 2024 17:31:59 +0100 Subject: [PATCH 2/6] updates toc --- docs/toc.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/toc.yml b/docs/toc.yml index bd3f6fe467..83f0eb32b0 100644 --- a/docs/toc.yml +++ b/docs/toc.yml @@ -267,6 +267,8 @@ items: href: community-toolkit/hosting-java.md - name: Node.js extensions href: community-toolkit/hosting-nodejs-extensions.md + - name: Python extensions + href: community-toolkit/hosting-python-extensions.md - name: Ollama href: community-toolkit/ollama.md - name: Meilisearch From b12fdeac7ac3ef280c01691284b1cbb77fb642d7 Mon Sep 17 00:00:00 2001 From: Tommaso Stocchi Date: Fri, 22 Nov 2024 15:58:22 +0100 Subject: [PATCH 3/6] removes trailing spaces --- docs/community-toolkit/hosting-python-extensions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/community-toolkit/hosting-python-extensions.md b/docs/community-toolkit/hosting-python-extensions.md index 799ade5fce..4e0462df2c 100644 --- a/docs/community-toolkit/hosting-python-extensions.md +++ b/docs/community-toolkit/hosting-python-extensions.md @@ -10,7 +10,7 @@ ms.date: 11/19/2024 [!INCLUDE [banner](includes/banner.md)] -In this article, you learn about the .NET Aspire Community Toolkit Python hosting extensions package which provides extra functionality to the .NET Aspire [Python hosting package](https://nuget.org/packages/Aspire.Hosting.Python). +In this article, you learn about the .NET Aspire Community Toolkit Python hosting extensions package which provides extra functionality to the .NET Aspire [Python hosting package](https://nuget.org/packages/Aspire.Hosting.Python). The extensions package lets you run [Uvicorn](https://www.uvicorn.org/) applications. ## Hosting integration From 62a32d0a0dfebf1f3e5a92695dfe585ed6ad91f1 Mon Sep 17 00:00:00 2001 From: Tommaso Stocchi Date: Sun, 24 Nov 2024 11:08:04 +0100 Subject: [PATCH 4/6] Update docs/community-toolkit/hosting-python-extensions.md Co-authored-by: David Pine --- docs/community-toolkit/hosting-python-extensions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/community-toolkit/hosting-python-extensions.md b/docs/community-toolkit/hosting-python-extensions.md index 4e0462df2c..54bb8389e9 100644 --- a/docs/community-toolkit/hosting-python-extensions.md +++ b/docs/community-toolkit/hosting-python-extensions.md @@ -4,7 +4,7 @@ description: Learn about the .NET Aspire Community Toolkit Python hosting extens ms.date: 11/19/2024 --- -# .NET Aspire Community Toolkit Python hosting extensions +# Community Toolkit Python hosting extensions [!INCLUDE [includes-hosting](../includes/includes-hosting.md)] From a1172ce41dd813562741148d8efc85dbc6c4881b Mon Sep 17 00:00:00 2001 From: Tommaso Stocchi Date: Sun, 24 Nov 2024 11:08:14 +0100 Subject: [PATCH 5/6] Update docs/community-toolkit/hosting-python-extensions.md Co-authored-by: David Pine --- docs/community-toolkit/hosting-python-extensions.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/community-toolkit/hosting-python-extensions.md b/docs/community-toolkit/hosting-python-extensions.md index 54bb8389e9..d820bd04e7 100644 --- a/docs/community-toolkit/hosting-python-extensions.md +++ b/docs/community-toolkit/hosting-python-extensions.md @@ -43,8 +43,14 @@ In the _:::no-loc text="Program.cs":::_ file of your app host project, call the ```csharp var builder = DistributedApplication.CreateBuilder(args); -var uvicorn = builder.AddUvicornApp("uvicornapp", "../uvicornapp-api", "main:app") +var uvicorn = builder.AddUvicornApp( + name: "uvicornapp", + projectDirectory: "../uvicornapp-api", + appName: "main:app" + ) .WithHttpEndpoint(env: "PORT"); + +builder.Build().Run(); ``` The `PORT` environment variable is used to determine the port the Uvicorn application should listen on. By default, this port is randomly assigned by .NET Aspire. The name of the environment variable can be changed by passing a different value to the method. From af56015d33a9560129df0e60b38cb892ddd51455 Mon Sep 17 00:00:00 2001 From: Tommaso Stocchi Date: Sun, 24 Nov 2024 11:08:19 +0100 Subject: [PATCH 6/6] Update docs/community-toolkit/hosting-python-extensions.md Co-authored-by: David Pine --- docs/community-toolkit/hosting-python-extensions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/community-toolkit/hosting-python-extensions.md b/docs/community-toolkit/hosting-python-extensions.md index d820bd04e7..312f72f5d8 100644 --- a/docs/community-toolkit/hosting-python-extensions.md +++ b/docs/community-toolkit/hosting-python-extensions.md @@ -1,5 +1,5 @@ --- -title: Python hosting extensions +title: Community Toolkit Python hosting extensions description: Learn about the .NET Aspire Community Toolkit Python hosting extensions package which provides extra functionality to the .NET Aspire Python hosting package. ms.date: 11/19/2024 ---