/dapr-skills:create-pubsub-pythonfrom dapr-skills
Creates a Dapr pub/sub app in Python with FastAPI, supporting publisher, subscriber, or both with declarative, programmatic, or streaming subscriptions.
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 creates a Dapr pub/sub application in Python: a FastAPI publisher, a subscriber or both, sharing the message contract the user described and one dapr.yaml. The subscriber uses a declarative (default), programmatic or streaming subscription.
The application is built from the user's own domain. There is no built-in sample scenario: the event, its fields, its topic and what the subscriber does with it all come from the Check specification interview, and every template is filled in from the placeholder vocabulary in ../dapr-shared/pubsub-placeholders.md.
You MUST follow these phases in strict order:
## Show final message section: the closing sentence followed by the Dev Dashboard recommendation. Do NOT add any other text, summary, or commentary.The following must be installed by the user before this skill can run. Do not run the check-prereq skills; assume the prerequisites are installed.
Python packages (handled during project setup): dapr 1.19.0, or dapr[fastapi] 1.19.0 for a programmatic subscriber — from Dapr 1.19 the FastAPI extension is an extra of the dapr distribution, not a separate dapr-ext-fastapi package. Plus fastapi 0.118.2, pydantic 2.12.0, uvicorn 0.37.0. Optional: the Diagrid Dapr Dev Dashboard.
Background on delivery guarantees, CloudEvents and the subscription types: ../dapr-shared/pubsub-concepts.md.
Placeholder vocabulary used by every template: ../dapr-shared/pubsub-placeholders.md.
Never build a default scenario. The application is about the user's domain, and the templates are placeholders waiting for it. Infer everything the prompt already says, then ask only what is missing, one question at a time, waiting for each answer. If the prompt gives no domain at all, ask for it — do not invent one and do not fall back to an order-processing example.
Domain, first:
<id_field>: the handler deduplicates on it, so there must be exactly one per
event. Ask for the type of each field when the name does not make it obvious, and note any constraint
the domain implies — it becomes a Pydantic Field(...) rule.Then the wiring:
DaprApp(app).subscribe(...) in code) or streaming (the app pulls messages; no inbound port)". Inference: "streaming", "no inbound port" or "pull" → streaming; "programmatic", DaprApp, "dapr[fastapi]" or the pre-1.19 name "dapr-ext-fastapi" → programmatic; "declarative" or "subscription YAML" → declarative.<ProjectRoot> (the folder) and <root-kebab> (lowercase, hyphen-separated, used for app ids and package names).There is no hosting or style question: Python uses dapr run and FastAPI.
Feature rules:
<TopicName>-deadletter) is on unless the user declines, and always comes with the inbound retry policy.REFERENCE.md → Routing, TTL and raw payload).Before creating any file, write out the resolved values and restate them to the user in two or three
lines, so a wrong reading is caught before it is scaffolded. Resolve them exactly as
../dapr-shared/pubsub-placeholders.md defines them:
| Placeholder | Resolved from |
|---|---|
<EventName>, <event_fields>, <id_field> | questions 2 and 3 |
<event_name>, <EventDescription> | <EventName>, in snake_case and as a lowercase noun phrase |
<TopicName>, <DeadLetterTopicName> | question 2; the dead-letter topic is <TopicName>-deadletter |
<TOPIC_CONST>, <DEAD_LETTER_TOPIC_CONST> | UPPER_SNAKE_CASE of <TopicName> |
<publish_route>, <subscribe_route>, <dead_letter_route> | <TopicName>; the subscribe route is /events/pubsub/<TopicName> |
<validation_condition>, <handler_body> | questions 3 and 4 |
Fixed, never derived from the domain: the component name pubsub, the constant PUBSUB_NAME, and the
_processed_event_ids idempotency set.
Check once whether the optional Diagrid Dapr Dev Dashboard is installed by following the Check section of ../dapr-shared/dev-dashboard.md (diagrid-dev-dashboard --version). Remember the result (DevDashboardInstalled) for the final message. This check never stops the skill: do not ask the user about it, do not install anything, and continue whether or not the dashboard is installed.
Create the project root folder inside the current location where the terminal is open:
mkdir <ProjectRoot>
cd <ProjectRoot>
Role both (a uv workspace; subscription.yaml only for declarative). A single role is one service folder with models.py and no workspace; replace from contracts import with from models import in the handler, publisher and streaming blocks (they import contracts in the workspace layout). See REFERENCE.md → Folder structures.
<ProjectRoot>/
├── .gitignore
├── pyproject.toml
├── dapr.yaml
├── pubsub.http
├── README.md
├── resources/
│ ├── pubsub.yaml
│ ├── resiliency.yaml
│ └── subscription.yaml
├── contracts/
│ ├── pyproject.toml
│ └── contracts/__init__.py
├── publisher/
│ ├── pyproject.toml
│ └── main.py
└── subscriber/
├── pyproject.toml
├── main.py
└── handler.py
A streaming subscriber has main.py and streaming.py instead of handler.py, and no resources/subscription.yaml.
Copy each file from its shared file and replace every placeholder with the value resolved in Resolving
the placeholders. A file is never written with a placeholder left in it: after writing each one, check it
for a stray < ... >. Ports: publisher appPort 8001 / daprHTTPPort 3501, subscriber appPort 8002 /
daprHTTPPort 3502.
.gitignore: Python style, from https://raw.githubusercontent.com/github/gitignore/refs/heads/main/Python.gitignore.pyproject.toml files (workspace root, contracts, services): ../dapr-shared/python-pubsub-project.md. Take the subscriber dependencies from its table for the chosen type (declarative has no dapr; programmatic takes dapr[fastapi]; streaming has no FastAPI).dapr.yaml: ../dapr-shared/pubsub-dapr-yaml.md (Python block). The appID values are <root-kebab>-publisher and <root-kebab>-subscriber. Omit appPort for a streaming-only subscriber; keep it for declarative and programmatic subscribers.resources/pubsub.yaml: ../dapr-shared/dapr-pubsub-redis.md.resources/resiliency.yaml: ../dapr-shared/dapr-pubsub-resiliency.md (dead-letter on).resources/subscription.yaml (declarative only): ../dapr-shared/dapr-pubsub-subscription.md. scopes must be exactly the subscriber appID, <root-kebab>-subscriber.../dapr-shared/python-pubsub-publisher.md → Contracts.main.py: ../dapr-shared/python-pubsub-publisher.md → Publish endpoint.../dapr-shared/python-pubsub-subscriber-declarative.md plus handler.py from ../dapr-shared/python-pubsub-handler.md;../dapr-shared/python-pubsub-subscriber-programmatic.md plus the same handler.py;../dapr-shared/python-pubsub-subscriber-streaming.md → Standalone subscriber (create) (streaming.py and main.py, no handler file).REFERENCE.md → Routing, TTL and raw payload.pubsub.http: ../dapr-shared/pubsub-local-http.md, Python variant (snake_case keys, ports 8001, 8002, 3501).Rules that matter:
subscription.yaml with DaprApp or subscribe_with_handler for the same topic.{"status": ...} and never returns 404 (Dapr drops the message).rawPayload.IMPORTANT: After Project Setup you MUST run these exact verification instructions:
uv sync --all-packages in <ProjectRoot>. Single role: run uv sync in the service folder.uv run python -m compileall -q <service folders> (for example contracts publisher subscriber). It must exit with code 0.__pycache__ folders created by the compile step.IMPORTANT: After Verify you MUST run these instructions:
Create a README.md file inside the folder. See REFERENCE.md → README key points. It contains:
dapr init provides it and it is already running in a container.dapr run -f . from the project root, and how to try it with curl plus a link to pubsub.http.GET http://localhost:3502/v1.0/metadata and the Dev Dashboard's subscriptions view.resources/pubsub.yaml is replaced while metadata.name: pubsub stays the same, so no code changes. A heading with no paragraph, or a paragraph without that link, is incomplete. See REFERENCE.md → README key points for the full wording.../dapr-shared/dev-dashboard.md.../dapr-shared/running-with-catalyst.md (<ProjectName> is <root-kebab>).review-pubsub-publishing, review-pubsub-subscriptions and review-pubsub-components.IMPORTANT: This is the LAST step. After Create README.md, your final output MUST be ONLY the message below followed by the Dev Dashboard recommendation — no preamble, no summary, no additional commentary, only replace the with the actual value:
The pub/sub application is created. Open the README.md file in the folder for a summary and instructions for running locally.
Then add, as a separate paragraph, the block from the Final recommendation section of ../dapr-shared/dev-dashboard.md that matches DevDashboardInstalled. Use it as written. Nothing may follow it.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
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-pubsub-pythonAdds Dapr pub/sub to an existing Python FastAPI app. Edits only after you approve a plan. Use for "add pub/sub to my FastAPI app" or "make this Python service subscribe to a Dapr topic". For a new app use create-pubsub-python./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.Other plugins' skills for the same job