[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-eeeebd11-1edf-4c2d-a239-1d946bdd66a5":3,"$fF8K7_QyiC5G6BO7TUFTCDF7eOC5LhCSQ3wQZOs25_ZU":43},{"id":4,"title":5,"description":6,"categoryId":7,"moduleId":8,"tags":9,"prompt":10,"icon":11,"source":12,"sourceUrl":13,"authorId":14,"authorName":15,"isPublic":16,"stars":17,"runs":18,"createdAt":19,"updatedAt":19,"module":20,"category":27,"packages":34},"eeeebd11-1edf-4c2d-a239-1d946bdd66a5","azure-messaging-webpubsubservice-py","Azure Web PubSub 服务 SDK for Python。用于实时消息传递、WebSocket 连接和发布\u002F订阅模式。","cat_coding_devops","mod_coding","sickn33,coding","---\nname: azure-messaging-webpubsubservice-py\ndescription: Azure Web PubSub Service SDK for Python. Use for real-time messaging, WebSocket connections, and pub\u002Fsub patterns.\nrisk: unknown\nsource: community\ndate_added: '2026-02-27'\n---\n\n# 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:\u002F\u002F\u003Cname>.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:\u002F\u002F\u003Cname>.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\u002Fplain\")\n\n# Send JSON\nclient.send_to_all(\n    message={\"type\": \"notification\", \"data\": \"Hello\"},\n    content_type=\"application\u002Fjson\"\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\u002Fplain\"\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\u002Fplain\"\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\u002Fplain\"\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\u002FRevoke 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:\u002F\u002F\u003Cname>.webpubsub.azure.com\",\n        hub=\"my-hub\",\n        credential=credential\n    )\n    \n    await client.send_to_all(\"Hello async!\", content_type=\"text\u002Fplain\")\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.\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","","imported","https:\u002F\u002Fgithub.com\u002Fsickn33\u002Fantigravity-awesome-skills","user_system_seed","SkillOPIC",true,220,768,"2026-05-16 13:06:49",{"id":8,"name":21,"slug":22,"icon":23,"description":24,"sort":25,"createdAt":26},"编程开发","coding","mdi-code-braces","代码生成、调试、审查，提升开发效率",2,"2026-05-16 12:53:40",{"id":7,"name":28,"slug":29,"icon":30,"description":31,"moduleId":8,"sort":32,"skillCount":33,"createdAt":26},"DevOps","devops","mdi-cog-outline","CI\u002FCD、容器化、部署运维",3,162,[35],{"id":36,"skillId":4,"version":37,"fileName":38,"fileSize":39,"filePath":40,"fileHash":41,"manifest":42,"createdAt":19},"a51b7081-8619-4e75-87d5-da3a9fb80be7","1.0.0","azure-messaging-webpubsubservice-py.zip",2023,"uploads\u002Fskills\u002Feeeebd11-1edf-4c2d-a239-1d946bdd66a5\u002Fazure-messaging-webpubsubservice-py.zip","4cbfd4d2a1c1bb99c8e216a1af7f60ff8a9b8b01b4e883e57235a41972ca3258","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":6081}]",{"code":44,"message":45,"data":46},200,"success",{"items":47,"stats":48,"page":51},[],{"averageRating":49,"totalRatings":49,"ratingCounts":50},0,[49,49,49,49,49],{"limit":52,"offset":49,"hasMore":53,"nextOffset":52,"ratedOnly":16},15,false]