This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
Includes: Hosting integration only —
Client integration not included
Note
This integration is part of theAspire Community Toolkit andisn't officially supported by the Aspire team.
In this article, you learn about the Aspire Community Toolkit Python hosting extensions package which provides extra functionality to the AspirePython hosting package.The extensions package lets you runUvicorn anduv applications.
To get started with the Aspire Community Toolkit Python hosting extensions, install the📦 CommunityToolkit.Aspire.Hosting.Python.Extensions NuGet package in the AppHost project.
dotnet add package CommunityToolkit.Aspire.Hosting.Python.ExtensionsFor more information, seedotnet add package orManage package dependencies in .NET applications.
The following sections detail various usages, from running Uvicorn applications to using specific package managers such as uv.
To work with Python apps, they need to be within a virtual environment. To create a virtual environment, refer to theInitialize the Python virtual environment section.
TheUVICORN_PORT environment variable is used to determine the port the Uvicorn application should listen on. By default, this port is randomly assigned by Aspire. The name of the environment variable can be changed by passing a different value to theWithHttpEndpoint method.
In theAppHost.cs file of your AppHost project, call theAddUvicornApp method to add a Uvicorn application to the builder.
var builder = DistributedApplication.CreateBuilder(args);var uvicorn = builder.AddUvicornApp( name: "uvicornapp", projectDirectory: "../uvicornapp-api", appName: "main:app" ) .WithHttpEndpoint(env: "UVICORN_PORT");builder.Build().Run();The Uvicorn application can be added as a reference to other resources in the AppHost project.
Was this page helpful?
Need help with this topic?
Want to try using Ask Learn to clarify or guide you through this topic?
Was this page helpful?
Want to try using Ask Learn to clarify or guide you through this topic?