FizzyLogic.Aspire.Python.Hosting 0.1.0-preview-2.12

This is a prerelease version of FizzyLogic.Aspire.Python.Hosting.
dotnet add package FizzyLogic.Aspire.Python.Hosting --version 0.1.0-preview-2.12
NuGet\Install-Package FizzyLogic.Aspire.Python.Hosting -Version 0.1.0-preview-2.12
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FizzyLogic.Aspire.Python.Hosting" Version="0.1.0-preview-2.12" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FizzyLogic.Aspire.Python.Hosting --version 0.1.0-preview-2.12
#r "nuget: FizzyLogic.Aspire.Python.Hosting, 0.1.0-preview-2.12"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install FizzyLogic.Aspire.Python.Hosting as a Cake Addin
#addin nuget:?package=FizzyLogic.Aspire.Python.Hosting&version=0.1.0-preview-2.12&prerelease

// Install FizzyLogic.Aspire.Python.Hosting as a Cake Tool
#tool nuget:?package=FizzyLogic.Aspire.Python.Hosting&version=0.1.0-preview-2.12&prerelease

Aspire hosting extensions for Python projects

Continuous integration NuGet Version

.NET Aspire already has great support for orchestrating C# projects and a fast array of middleware components. This project adds additional support for running Python projects as smoothly as C# projects.

System requirements

  • Python
  • .NET SDK 8 or higher
  • .NET Aspire workload preview 7

Getting started

Before using this extension you should know how to set up an Aspire project. There's an excellent guide in the documentation.

Once you've set up a basic Aspire project, follow the instructions below to get started.

Before you start building

These extensions make a few assumptions about your project:

  • You have a virtual environment in the .venv directory in your Python project. You can set up a virtual environment with venv, rye or poetry.
  • You have a Dockerfile in the root directory of your Python project. A sample Dockerfile can be found here

Note: I haven't added support for Anaconda because I don't use it myself. Feel free to open a PR to add support for Anaconda.

Setting up a Python project

Basic Python projects can be configured using the following code:

using FizzyLogic.Aspire.Python.Hosting;

var builder = DistributedApplication.CreateBuilder(args);

builder.AddPythonProjectWithVirtualEnvironment("batch", "apps/batch");

builder.Build().Run();

By adding a Python project resource, you'll automatically get tracing, logging, and metrics configured. Note that you need to add extra HTTP and HTTPS endpoints yourself by calling .WithHttpEndpoint or WithHttpsEndpoint.

The Python project is deployed as a container when you publish the Aspire application. You'll need a Dockerfile in the Python project directory for the publication to work properly.

Telemetry data is automatically gathered when you have the following package available in your virtual environment:

Setting up a Flask project

Flask applications differ from regular Python projects in that we'll automatically expose an HTTP endpoint for the project. You can configure a new Flask project using the following code:

using FizzyLogic.Aspire.Python.Hosting;

var builder = DistributedApplication.CreateBuilder(args);

builder.AddFlaskProjectWithVirtualEnvironment("flask-service", "apps/flask-service");

builder.Build().Run();

As with regular Python projects, the Flask project is published as a container. You'll need a Dockerfile in the Python project directory for the publication to work properly.

Telemetry data is automatically gathered when you have the following two packages available in your virtual environment:

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.0-preview-2.12 44 5/9/2024
0.1.0-preview-2.11 43 5/9/2024
0.1.0-preview-2.6 44 5/9/2024
0.1.0-preview-1 41 5/8/2024