A single-file C# AppHost orchestrating a Python FastAPI service. In local
development the app runs natively — Aspire creates a virtual environment from
requirements.txt and launches uvicorn on your machine, no Dockerfile
required. When you run aspire publish, Aspire auto-generates a
Dockerfile for the Python app and emits a docker-compose.yaml, so the same
code ships as a container image. Polyglot: C# AppHost, Python service.
- AppHost: single-file
apphost.cswithAspire.Hosting.Python+Aspire.Hosting.Docker - Service: Python FastAPI text-analyzer, served by
uvicorn - Dev runtime: native (venv on the host) —
AddUvicornApp - Publish artifact: an auto-generated Dockerfile +
docker-compose.yaml
cd samples/python-fastapi-docker
aspire runAspire creates app/.venv, installs requirements.txt, and starts uvicorn
on the host. Try it:
curl -k https://<api-endpoint>/api/info
curl -k -X POST https://<api-endpoint>/api/analyze \
-H 'Content-Type: application/json' \
-d '{"text":"Aspire makes polyglot apps easy. Easy!"}'aspire publish -o ./compose-outputAspire writes compose-output/api.Dockerfile (a production-ready, non-root
Python image) and compose-output/docker-compose.yaml. Build and run it:
docker build -f compose-output/api.Dockerfile -t text-analyzer:local ./app
docker run -d -p 8080:8000 text-analyzer:local main:app --host 0.0.0.0 --port 8000
curl http://localhost:8080/api/infoAddUvicornApp("api", "app", "main:app")— a native Python dev experience (auto venv +uvicorn) with health checks and external endpoints.- No hand-written Dockerfile:
aspire publishgenerates one tailored to the detected Python version and dependencies, then references it from a compose file. - One app model, two runtimes: native
uvicornfor dev, a container image for publish/deploy.
apphost.cs single-file C# AppHost (Python + Docker Compose publish)
aspire.config.json points aspire at apphost.cs
apphost.run.json launch profiles (dashboard/OTLP ports)
app/
main.py FastAPI text-analyzer
requirements.txt fastapi + uvicorn (Aspire builds the venv from this)