FizzyLogic.Aspire.Python.Hosting
0.1.0-preview-2.12
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
<PackageReference Include="FizzyLogic.Aspire.Python.Hosting" Version="0.1.0-preview-2.12" />
<PackageVersion Include="FizzyLogic.Aspire.Python.Hosting" Version="0.1.0-preview-2.12" />
<PackageReference Include="FizzyLogic.Aspire.Python.Hosting" />
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"
#:package FizzyLogic.Aspire.Python.Hosting@0.1.0-preview-2.12
#addin nuget:?package=FizzyLogic.Aspire.Python.Hosting&version=0.1.0-preview-2.12&prerelease
#tool nuget:?package=FizzyLogic.Aspire.Python.Hosting&version=0.1.0-preview-2.12&prerelease
Aspire hosting extensions for Python projects
.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
.venvdirectory 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:
- opentelemetry-distro (Make sure you install opentelemetry-distro[otlp])
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:
- opentelemetry-distro (Make sure you install opentelemetry-distro[otlp])
- opentelemetry-instrumentation-flask
| Product | Versions 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Aspire.Hosting (>= 8.0.0-preview.7.24251.11)
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 | 662 | 5/9/2024 |
| 0.1.0-preview-2.11 | 115 | 5/9/2024 |
| 0.1.0-preview-2.6 | 113 | 5/9/2024 |
| 0.1.0-preview-1 | 105 | 5/8/2024 |