/dapr-skills:add-pubsub-pythonfrom dapr-skills
Adds Dapr pub/sub (publisher, subscriber, or both) to an existing Python FastAPI app. Edits only after user approves a plan.
Ships in dapr-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
This skill adds Dapr pub/sub (publisher, subscriber or both) to a FastAPI app that already exists. It changes nothing before the user approves a written plan, edits existing files with the smallest possible change, follows the project's own conventions, checks that the code still compiles and imports after every step and runs the existing tests at the end. It never changes git state.
You MUST follow these phases in strict order:
DAPR-PUBSUB.md at the project root.## Show final message followed by the Dev Dashboard recommendation. No other text after it.The user must have installed:
requirements.txt or a pyproject.toml.Read-only. Follow Detection in REFERENCE.md. Determine and remember:
FastAPI(). If more than one qualifies, ask which (one question) and wait.requires-python, .python-version, python --version). Below 3.10, stop now and explain; change nothing.## Alternative: dapr[grpc] in ../dapr-shared/python-pubsub-subscriber-programmatic.md and change nothing.uv add. pip with requirements.txt → Edit plus python -m pip install -r requirements.txt in the project venv (ask when no venv exists). pip with a pyproject.toml [project].dependencies → Edit plus python -m pip install -e .. Poetry, PDM, Pipenv and conda (poetry.lock, [tool.poetry], pdm.lock, Pipfile, environment.yml): stop and explain that v1 does not support them; change nothing.uv run with uv, otherwise .venv/Scripts/python.exe (Windows) or .venv/bin/python. Written as <python> below.dapr with extras (dapr[fastapi], dapr[grpc], dapr[workflow]), or the pre-1.19 dapr-ext-fastapi, dapr-ext-grpc, dapr-ext-workflow packages. Any dapr pin below 1.19.0 is a newer package available; any dapr-ext-* package at all is a retired packaging shape (question 1 offers the move to the extra).(pubsub, topic) pairs and types: DaprApp( with .subscribe( (programmatic), subscribe_with_handler( or client.subscribe( (streaming), kind: Subscription YAML (declarative). Also an existing DaprApp, an existing lifespan, existing publish_event( calls.dapr.yaml, its resources folder, every type: pubsub. component, kind: Resiliency files.POST /orders); read-only GET endpoints never qualify. Remember whether an existing test calls it over HTTP (TestClient, httpx).pytest) and git status (read-only). Remember uncommitted changes.Infer from the request first; otherwise ask, one question at a time:
DaprApp, "declarative"); else ask, default declarative. One type per topic; mixed types are allowed, so ask which one the new topic uses. Never subscribe a (pubsub, topic) pair that exists; ask whether to extend the existing handler or use another topic.../dapr-shared/pubsub-placeholders.md.Follow the Check section of ../dapr-shared/dev-dashboard.md (diagrid-dev-dashboard --version) and remember DevDashboardInstalled. Do not ask about it, install it or stop because of it.
Emit the Add Pub/Sub Plan using the template in REFERENCE.md: target, role, subscription type with the reason, packages, new and edited files, Dapr wiring, topics and routes, what is left unchanged, the baseline test run (default yes) and an uncommitted-changes warning when Phase 1 found one. End it with the Questions, each with its default:
app.dependency_overrides[get_<event_name>_publisher] (the exact override target; the skill injects the publisher into the endpoint with Depends(get_<event_name>_publisher)), that without a sidecar each publishing call waits for the health check, so run them with DAPR_HEALTH_TIMEOUT=2 (seconds; POSIX DAPR_HEALTH_TIMEOUT=2 uv run pytest, PowerShell $env:DAPR_HEALTH_TIMEOUT=2 first) for a quick failure, and that this skill does not edit tests. When the request does not mention publishing from an existing action, the default is Yes, but No when an existing test calls it over HTTP (it would need a running sidecar); say so. Without a trigger endpoint, write "No existing endpoint publishes; use the new publish endpoint."Write the file lists as if every default is accepted. Then ask the user to approve, change or stop. A plan is not consent: change nothing until the user says yes. When the request says to go ahead without asking, still show the plan first, then continue with the defaults.
If the baseline test run was kept, run the tests once now (uv run pytest or <python> -m pytest) and remember which failed. Then apply, one step at a time:
dapr==1.19.0, or dapr[fastapi]==1.19.0 for programmatic, per Dependencies per subscription type in REFERENCE.md; plus the updates from question 1. A project that still has dapr-ext-* either moves to the extra (question 1, default yes) or stays on its matched 1.18.3 pair — never a mixture.dapr.yaml entry or append (../dapr-shared/pubsub-dapr-yaml.md), pubsub.yaml (../dapr-shared/dapr-pubsub-redis.md) or reuse of the existing component, resiliency.yaml (../dapr-shared/dapr-pubsub-resiliency.md), and for declarative subscription.yaml (../dapr-shared/dapr-pubsub-subscription.md) with scopes equal to the app id.../dapr-shared/python-pubsub-publisher.md → Contracts), handler.py (../dapr-shared/python-pubsub-handler.md).DaprApp(app), reusing an existing one. Streaming: start and close in the lifespan, merging into an existing one, never replacing it (../dapr-shared/python-pubsub-subscriber-streaming.md → Inside an existing FastAPI app (add))./events/<pubsub>/<topic>; the publish endpoint POST /pubsub/<publish_route> per Adding to an existing FastAPI app in ../dapr-shared/python-pubsub-publisher.md, or the trigger endpoint edit when question 2 was yes: inject the publisher with publisher: Callable[[<EventName>], None] = Depends(get_<event_name>_publisher) exactly as shown in that file (never call a module-level publish function directly, dependency_overrides could not replace it). The new publish code that catches DaprGrpcError must also catch TimeoutError (see Edge cases in REFERENCE.md)..http file or add <ProjectName>.pubsub.http (../dapr-shared/pubsub-local-http.md).Rules for every step:
Edit and the smallest change; never rewrite an existing file with Write or a shell heredoc, because a wholesale rewrite drops the user's formatting and comments and makes the plan's edited-files list untrustworthy. When a shell is awkward, use Edit once per hunk; if Edit is unavailable, use a script that inserts or replaces ONLY the planned lines, then verify the diff shows no other changed lines. Never change files the plan does not list.DaprApp or lifespan; never replace dapr.yaml or an existing resiliency file (append); keep an existing appPort.scopes entry must equal the appID. Use rawPayload (never isRawPayload) as the raw payload metadata key.<python> -m compileall -q <changed files>, and after steps 3–5 also <python> -c "import <app module>". If it fails, fix that step or undo its edits, tell the user and stop. Never continue past a failing check.git commands other than git status.Run the compile and import checks once more and, when tests exist, uv run pytest or <python> -m pytest. With an edited trigger endpoint and no sidecar, run the test command with DAPR_HEALTH_TIMEOUT=2 set for that command only (POSIX DAPR_HEALTH_TIMEOUT=2 uv run pytest; PowerShell $env:DAPR_HEALTH_TIMEOUT=2; uv run pytest) so the expected failure takes seconds instead of the default 60 s per call. Report failures that also failed in the baseline as pre-existing. If the baseline passed and a test that calls the changed endpoint now fails because of the publish call (timeout or connection to the sidecar, e.g. publish_event TimeoutError), report it as an expected consequence of the approved Risk line and name the one-line fix (app.dependency_overrides[get_<event_name>_publisher] = ...); failures unrelated to the publish call are regressions. Never edit tests to make them pass. Do not start dapr run.
Create DAPR-PUBSUB.md at the project root using the template in ../dapr-shared/pubsub-run-doc.md (see Add Pub/Sub run doc notes in REFERENCE.md). In its Tests section, say that tests calling the publishing endpoint need app.dependency_overrides[get_<event_name>_publisher] or a sidecar, and to set DAPR_HEALTH_TIMEOUT=2 when running them without one. Never edit an existing README.md.
IMPORTANT: This is the LAST step. Your output MUST end with the message below followed by the Dev Dashboard recommendation — keep anything before it to one short line (details belong in DAPR-PUBSUB.md). Replace <ProjectName> with the target project name:
Dapr pub/sub is added to . Open DAPR-PUBSUB.md in the project root for what changed and how to run it.
Then add, as a separate paragraph, the block from the Final recommendation section of ../dapr-shared/dev-dashboard.md that matches DevDashboardInstalled. Nothing may follow it.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub diagrid-labs/dapr-skills --plugin dapr-skills33 skills in this plugin
/add-pubsub-dotnetAdds Dapr pub/sub to an existing .NET (ASP.NET Core, plain or Aspire) project. Edits only after you approve a plan. Use for "add pub/sub to my .NET project" or "subscribe this ASP.NET app to a topic". For a new project use create-pubsub-dotnet./add-workflow-dotnetAdds Dapr Workflow, activities and management endpoints to an existing .NET (ASP.NET Core, plain or Aspire) project after you approve a plan. Use for "add a workflow to my .NET project" or "make this process a durable workflow". For a new project use create-workflow-dotnet. For Diagrid use the diagrid plugin./check-prereq-agent-dotnetChecks prerequisites for durable AI agents in .NET with Microsoft Agent Framework on Dapr Workflow. Use for "check prerequisites for .NET agents" or "verify .NET agent environment".Other plugins' skills for the same job