Skip to content
Docs Try Aspire
Docs Try

Integrating a FastAPI (Python) app within an Aspire application

Aspire sample
File-based AppHost

Clone, run, and explore this sample

This sample demonstrates integrating a FastAPI (Python) app and a JavaScript frontend using Aspire.

C#JavaScriptNode.jsPython
AppHost

The entry point that composes every resource and dependency in this sample's distributed application.

View on GitHub
apphost.cs
#pragma warning disable ASPIREBROWSERLOGS001
#pragma warning disable ASPIREJAVASCRIPT001
#:sdk Aspire.AppHost.Sdk@13.4.0
#:package Aspire.Hosting.JavaScript@13.4.0
#:package Aspire.Hosting.Browsers@13.4.0-preview.1.26281.18
#:package Aspire.Hosting.Python@13.4.0
#:package Aspire.Hosting.Redis@13.4.0
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddRedis("cache");
var app = builder.AddUvicornApp("app", "./app", "main:app")
.WithUv()
.WithExternalHttpEndpoints()
.WithReference(cache)
.WaitFor(cache)
.WithHttpHealthCheck("/health");
builder.AddViteApp("frontend", "./frontend")
.WithReference(app)
.WaitFor(app)
.WithBrowserLogs()
.PublishAsStaticWebsite("/api", app);
builder.Build().Run();

The sample consists of two apps:

  • app: This is a simple FastAPI-based Python app that returns randomly generated weather forecast data.
  • frontend: This is a Vite-based React app that renders the weather forecast data.

If using the Aspire CLI, run aspire run from this directory.

If using VS Code, open this directory as a workspace and launch the apphost.cs C# file using either the Aspire or C# debuggers.