Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit editor mode

Community Toolkit Python hosting extensions

Feedback

In this article

Includes:Hosting integration included Hosting integration only —Client integration not included 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.

Hosting integration

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.Extensions

For more information, seedotnet add package orManage package dependencies in .NET applications.

Example usage

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.

See also

Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, seeour contributor guide.

Feedback

Was this page helpful?

YesNoNo

Need help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?

  • Last updated on

In this article

Was this page helpful?

YesNo
NoNeed help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?