{
  "schema": "https://ai-atoms.com/schemas/skill-v1.json",
  "type": "skill",
  "id": "skill/azure-messaging-webpubsubservice-py",
  "version": "1.0.1",
  "name": "Azure Messaging Webpubsubservice Py",
  "description": "Azure Web PubSub Service SDK for Python. Use for real-time messaging, WebSocket connections, and pub/sub patterns.\nTriggers: \"azure-messaging-webpubsubservice\", \"WebPubSubServiceClient\", \"real-time\", \"WebSocket\", \"pub/sub\".",
  "system_prompt_fragment": "# Azure Web PubSub Service SDK for Python\n\nReal-time messaging with WebSocket connections at scale.\n\n## Installation\n\n```bash\n# Service SDK (server-side)\npip install azure-messaging-webpubsubservice\n\n# Client SDK (for Python WebSocket clients)\npip install azure-messaging-webpubsubclient\n```\n\n## Environment Variables\n\n```bash\nAZURE_WEBPUBSUB_CONNECTION_STRING=Endpoint=https://<name>.webpubsub.azure.com;AccessKey=...\nAZURE_WEBPUBSUB_HUB=my-hub\n```\n\n## Service Client (Server-Side)\n\n### Authentication\n\n```python\nfrom azure.messaging.webpubsubservice import WebPubSubServiceClient\n\n# Connection string\nclient = WebPubSubServiceClient.from_connection_string(\n    connection_string=os.environ[\"AZURE_WEBPUBSUB_CONNECTION_STRING\"],\n    hub=\"my-hub\"\n)\n\n# Entra ID\nfrom azure.identity import DefaultAzureCredential\n\nclient = WebPubSubServiceClient(\n    endpoint=\"https://<name>.webpubsub.azure.com\",\n    hub=\"my-hub\",\n    credential=DefaultAzureCredential()\n)\n```\n\n### Generate Client Access Token\n\n```python\n# Token for anonymous user\ntoken = client.get_client_access_token()\nprint(f\"URL: {token['url']}\")\n\n# Token with user ID\ntoken = client.get_client_access_token(\n    user_id=\"user123\",\n    roles=[\"webpubsub.sendToGroup\", \"webpubsub.joinLeaveGroup\"]\n)\n\n# Token with groups\ntoken = client.get_client_access_token(\n    user_id=\"user123\",\n    groups=[\"group1\", \"group2\"]\n)\n```\n\n### Send to All Clients\n\n```python\n# Send text\nclient.send_to_all(message=\"Hello everyone!\", content_type=\"text/plain\")\n\n# Send JSON\nclient.send_to_all(\n    message={\"type\": \"notification\", \"data\": \"Hello\"},\n    content_type=\"application/json\"\n)\n```\n\n### Send to User\n\n```python\nclient.send_to_user(\n    user_id=\"user123\",\n    message=\"Hello user!\",\n    content_type=\"text/plain\"\n)\n```\n\n### Send to Group\n\n```python\nclient.send_to_group(\n    group=\"my-group\",\n    message=\"Hello group!\",\n    content_type=\"text/plain\"\n)\n```\n\n### Send to Connection\n\n```python\nclient.send_to_connection(\n    connection_id=\"abc123\",\n    message=\"Hello connection!\",\n    content_type=\"text/plain\"\n)\n```\n\n### Group Management\n\n```python\n# Add user to group\nclient.add_user_to_group(group=\"my-group\", user_id=\"user123\")\n\n# Remove user from group\nclient.remove_user_from_group(group=\"my-group\", user_id=\"user123\")\n\n# Add connection to group\nclient.add_connection_to_group(group=\"my-group\", connection_id=\"abc123\")\n\n# Remove connection from group\nclient.remove_connection_from_group(group=\"my-group\", connection_id=\"abc123\")\n```\n\n### Connection Management\n\n```python\n# Check if connection exists\nexists = client.connection_exists(connection_id=\"abc123\")\n\n# Check if user has connections\nexists = client.user_exists(user_id=\"user123\")\n\n# Check if group has connections\nexists = client.group_exists(group=\"my-group\")\n\n# Close connection\nclient.close_connection(connection_id=\"abc123\", reason=\"Session ended\")\n\n# Close all connections for user\nclient.close_all_connections(user_id=\"user123\")\n```\n\n### Grant/Revoke Permissions\n\n```python\nfrom azure.messaging.webpubsubservice import WebPubSubServiceClient\n\n# Grant permission\nclient.grant_permission(\n    permission=\"joinLeaveGroup\",\n    connection_id=\"abc123\",\n    target_name=\"my-group\"\n)\n\n# Revoke permission\nclient.revoke_permission(\n    permission=\"joinLeaveGroup\",\n    connection_id=\"abc123\",\n    target_name=\"my-group\"\n)\n\n# Check permission\nhas_permission = client.check_permission(\n    permission=\"joinLeaveGroup\",\n    connection_id=\"abc123\",\n    target_name=\"my-group\"\n)\n```\n\n## Client SDK (Python WebSocket Client)\n\n```python\nfrom azure.messaging.webpubsubclient import WebPubSubClient\n\nclient = WebPubSubClient(credential=token[\"url\"])\n\n# Event handlers\n@client.on(\"connected\")\ndef on_connected(e):\n    print(f\"Connected: {e.connection_id}\")\n\n@client.on(\"server-message\")\ndef on_message(e):\n    print(f\"Message: {e.data}\")\n\n@client.on(\"group-message\")\ndef on_group_message(e):\n    print(f\"Group {e.group}: {e.data}\")\n\n# Connect and send\nclient.open()\nclient.send_to_group(\"my-group\", \"Hello from Python!\")\n```\n\n## Async Service Client\n\n```python\nfrom azure.messaging.webpubsubservice.aio import WebPubSubServiceClient\nfrom azure.identity.aio import DefaultAzureCredential\n\nasync def broadcast():\n    credential = DefaultAzureCredential()\n    client = WebPubSubServiceClient(\n        endpoint=\"https://<name>.webpubsub.azure.com\",\n        hub=\"my-hub\",\n        credential=credential\n    )\n    \n    await client.send_to_all(\"Hello async!\", content_type=\"text/plain\")\n    \n    await client.close()\n    await credential.close()\n```\n\n## Client Operations\n\n| Operation | Description |\n|-----------|-------------|\n| `get_client_access_token` | Generate WebSocket connection URL |\n| `send_to_all` | Broadcast to all connections |\n| `send_to_user` | Send to specific user |\n| `send_to_group` | Send to group members |\n| `send_to_connection` | Send to specific connection |\n| `add_user_to_group` | Add user to group |\n| `remove_user_from_group` | Remove user from group |\n| `close_connection` | Disconnect client |\n| `connection_exists` | Check connection status |\n\n## Best Practices\n\n1. **Use roles** to limit client permissions\n2. **Use groups** for targeted messaging\n3. **Generate short-lived tokens** for security\n4. **Use user IDs** to send to users across connections\n5. **Handle reconnection** in client applications\n6. **Use JSON** content type for structured data\n7. **Close connections** gracefully with reasons\n\n## When to Use\nThis skill is applicable to execute the workflow or actions described in the overview.",
  "applicable_domains": [
    "devops"
  ],
  "category": "devops",
  "invocation": [
    "/azure-messaging-webpubsubservice-py"
  ],
  "authored_by": "claudeskills.in community",
  "source_url": "https://claudeskills.in/skill/azure-messaging-webpubsubservice-py",
  "provenance": {
    "source": "claudeskills.in",
    "source_url": "https://claudeskills.in/skill/azure-messaging-webpubsubservice-py",
    "license": "unknown",
    "imported_at": "2026-09-03",
    "notes": "Aggregated by claudeskills.in from community GitHub lists."
  },
  "tags": [
    "claudeskills",
    "devops"
  ],
  "lifecycle": "draft"
}