azure-eventgrid-py – skill DevOps & Hạ tầng cho agent AI
SDK Azure Event Grid cho Python. Dùng để xuất bản sự kiện, xử lý CloudEvents và kiến trúc hướng sự kiện.
Cài skill azure-eventgrid-py bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-eventgrid-py-dbe38.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /azure-eventgrid-py – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-eventgrid-py-dbe38.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $azure-eventgrid-py – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-eventgrid-py-dbe38.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /azure-eventgrid-py – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-eventgrid-py-dbe38.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /azure-eventgrid-py – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
Azure Event Grid SDK for Python
Event routing service for building event-driven applications with pub/sub semantics.
Installation
pip install azure-eventgrid azure-identityEnvironment Variables
EVENTGRID_TOPIC_ENDPOINT=https://<topic-name>.<region>.eventgrid.azure.net/api/events
EVENTGRID_NAMESPACE_ENDPOINT=https://<namespace>.<region>.eventgrid.azure.netAuthentication
from azure.identity import DefaultAzureCredential
from azure.eventgrid import EventGridPublisherClient
credential = DefaultAzureCredential()
endpoint = "https://<topic-name>.<region>.eventgrid.azure.net/api/events"
client = EventGridPublisherClient(endpoint, credential)Event Types
| Format | Class | Use Case |
|--------|-------|----------|
| Cloud Events 1.0 | CloudEvent | Standard, interoperable (recommended) |
| Event Grid Schema | EventGridEvent | Azure-native format |
Publish CloudEvents
from azure.eventgrid import EventGridPublisherClient
from azure.core.messaging import CloudEvent
from azure.identity import DefaultAzureCredential
client = EventGridPublisherClient(endpoint, DefaultAzureCredential())
# Single event
event = CloudEvent(
type="MyApp.Events.OrderCreated",
source="/myapp/orders",
data={"order_id": "12345", "amount": 99.99}
)
client.send(event)
# Multiple events
events = [
CloudEvent(
type="MyApp.Events.OrderCreated",
source="/myapp/orders",
data={"order_id": f"order-{i}"}
)
for i in range(10)
]
client.send(events)Publish EventGridEvents
from azure.eventgrid import EventGridEvent
from datetime import datetime, timezone
event = EventGridEvent(
subject="/myapp/orders/12345",
event_type="MyApp.Events.OrderCreated",
data={"order_id": "12345", "amount": 99.99},
data_version="1.0"
)
client.send(event)Event Properties
CloudEvent Properties
event = CloudEvent(
type="MyApp.Events.ItemCreated", # Required: event type
source="/myapp/items", # Required: event source
data={"key": "value"}, # Event payload
subject="items/123", # Optional: subject/path
datacontenttype="application/json", # Optional: content type
dataschema="https://schema.example", # Optional: schema URL
time=datetime.now(timezone.utc), # Optional: timestamp
extensions={"custom": "value"} # Optional: custom attributes
)EventGridEvent Properties
event = EventGridEvent(
subject="/myapp/items/123", # Required: subject
event_type="MyApp.ItemCreated", # Required: event type
data={"key": "value"}, # Required: event payload
data_version="1.0", # Required: schema version
topic="/subscriptions/.../topics/...", # Optional: auto-set
event_time=datetime.now(timezone.utc) # Optional: timestamp
)Async Client
from azure.eventgrid.aio import EventGridPublisherClient
from azure.identity.aio import DefaultAzureCredential
async def publish_events():
async with DefaultAzureCredential() as credential, \
EventGridPublisherClient(endpoint, credential) as client:
event = CloudEvent(
type="MyApp.Events.Test",
source="/myapp",
data={"message": "hello"}
)
await client.send(event)
import asyncio
asyncio.run(publish_events())Namespace Topics (Event Grid Namespaces)
For Event Grid Namespaces (pull delivery):
from azure.eventgrid.aio import EventGridPublisherClient
# Namespace endpoint (different from custom topic)
namespace_endpoint = "https://<namespace>.<region>.eventgrid.azure.net"
topic_name = "my-topic"
async with EventGridPublisherClient(
endpoint=namespace_endpoint,
credential=credential, # an open azure.identity.aio credential
namespace_topic=topic_name,
) as client:
await client.send(event)Namespace topics support CloudEvents; construct the namespace client with namespace_topic, not as a send-only keyword. Match examples to the installed SDK version. Use a test topic and synthetic payloads; publishing can trigger real subscribers. Authentication needs the scoped data-sender role, and application consumers must handle duplicate delivery/idempotency. Close both async clients and credentials. See [official Python SDK guide](https://learn.microsoft.com/en-us/python/api/overview/azure/eventgrid-readme?view=azure-python).
Best Practices
1. Use CloudEvents for new applications (industry standard)
2. Batch events when publishing multiple events
3. Include meaningful subjects for filtering
4. Use async client for high-throughput scenarios
5. Handle retries — Event Grid has built-in retry
6. Set appropriate event types for routing and filtering
When to Use
This skill is applicable to execute the workflow or actions described in the overview.
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
Skill liên quan
- azure-eventhub-dotnet – SDK Azure Event Hubs cho .NET.
- azure-eventhub-py – SDK Azure Event Hubs cho Python để xử lý streaming. Dùng cho nhập sự kiện thông lượng…
- azure-eventhub-ts – Xử lý streaming sự kiện thông lượng cao và nhập dữ liệu thời gian thực.
- azure-functions – Các mẫu chuyên sâu cho phát triển Azure Functions, bao gồm mô hình isolated worker, điều…
- azure-functions-devsec – Xây dựng ứng dụng serverless trên Azure Functions. Cấu hình trigger, binding và triển…
- azure-identity-dotnet – SDK Azure Identity cho .NET. Thư viện xác thực cho client Azure SDK sử dụng Microsoft…
- azure-identity-java – Xác thực ứng dụng Java với dịch vụ Azure bằng Microsoft Entra ID (Azure AD).
- azure-identity-py – SDK Azure Identity cho xác thực Python. Dùng cho DefaultAzureCredential, managed…