Azure Eventgrid Py
MicrosoftOfficialCreated by Microsoft
- Skill
- Tool integration
- Cloud and DevOps
- MIT
- Low risk
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
The azure-eventgrid-py skill provides developers with the necessary patterns and code examples to integrate Azure Event Grid into Python applications. It covers publishing events using both the industry-standard CloudEvents format and the Azure-native Event Grid schema. The guide emphasizes secure authentication practices using DefaultAzureCredential and provides implementation details for both synchronous and asynchronous communication patterns, including support for Event Grid Namespaces.
What it does
- Publishes events to Azure Event Grid topics.
- Supports both CloudEvent and EventGridEvent schemas.
- Provides patterns for both synchronous and asynchronous event publishing.
- Demonstrates secure authentication using DefaultAzureCredential.
- Includes configuration for Event Grid Namespace topics.
- Outlines best practices for client lifecycle management and event batching.
When to use it
- When building event-driven architectures on Azure.
- When you need to publish events from a Python application to an Event Grid topic.
- When migrating to or implementing the CloudEvents 1.0 standard.
- When implementing high-throughput event publishing using asynchronous clients.
Advantages
- Promotes secure, audit-friendly authentication via DefaultAzureCredential.
- Ensures resource cleanup through mandatory context manager usage.
- Supports industry-standard interoperability via CloudEvents.
- Provides consistent patterns for both sync and async development.
Usage examples
- “How do I publish a single CloudEvent using the Azure Event Grid SDK?”
- The agent provides a code snippet using EventGridPublisherClient and the CloudEvent class, demonstrating how to define the event type, source, and data payload before sending it.
- “Show me how to use the async client for Event Grid.”
- The agent provides an example using azure.eventgrid.aio.EventGridPublisherClient, demonstrating the correct async context manager usage for both the client and credentials.
Install
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/microsoft/azure-eventgrid-py/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip azure-eventgrid-py.zip -d .agents/skills
Documentation by Microsoft
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 # Required for Event Grid topic publishing
EVENTGRID_NAMESPACE_ENDPOINT=https://<namespace>.<region>.eventgrid.azure.net # Required for namespace operations
AZURE_TOKEN_CREDENTIALS=prod # Required only if DefaultAzureCredential is used in productionAuthentication & Lifecycle
🔑 Two rules apply to every code sample below:
Prefer
DefaultAzureCredential. It works locally (Azure CLI / VS Code / Developer CLI) and in Azure (managed identity, workload identity) with no code change. Avoid connection strings, account/API keys — they bypass Entra audit and rotation.
Local dev:
DefaultAzureCredentialworks as-is.Production: set
AZURE_TOKEN_CREDENTIALS=prod(orAZURE_TOKEN_CREDENTIALS=<specific_credential>) to constrain the credential chain to production-safe credentials.Wrap every client in a context manager so HTTP transports, sockets, and token caches are released deterministically:
Sync:
with <Client>(...) as client:Async:
async with <Client>(...) as client:andasync with DefaultAzureCredential() as credential:(fromazure.identity.aio)Snippets may abbreviate this setup, but production code should always follow both rules.
import os
from azure.identity import DefaultAzureCredential, ManagedIdentityCredential
from azure.eventgrid import EventGridPublisherClient
# Local dev: DefaultAzureCredential. Production: set AZURE_TOKEN_CREDENTIALS=prod or AZURE_TOKEN_CREDENTIALS=<specific_credential>
credential = DefaultAzureCredential(require_envvar=True)
# Or use a specific credential directly in production:
# See https://learn.microsoft.com/python/api/overview/azure/identity-readme?view=azure-python#credential-classes
# credential = ManagedIdentityCredential()
endpoint = "https://<topic-name>.<region>.eventgrid.azure.net/api/events"
with EventGridPublisherClient(endpoint, credential) as client:
# Use client here (see following sections for operations)
...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, CloudEvent
from azure.identity import DefaultAzureCredential
with EventGridPublisherClient(endpoint, DefaultAzureCredential()) as client:
# 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():
credential = DefaultAzureCredential()
async with 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 import EventGridPublisherClient
from azure.identity import DefaultAzureCredential
# Namespace endpoint (different from custom topic)
namespace_endpoint = "https://<namespace>.<region>.eventgrid.azure.net"
topic_name = "my-topic"
with EventGridPublisherClient(
endpoint=namespace_endpoint,
credential=DefaultAzureCredential()
) as client:
client.send(
event,
namespace_topic=topic_name
)Best Practices
Pick sync OR async and stay consistent. Do not mix
azure.xxxsync clients withazure.xxx.aioasync clients in the same call path. Choose one mode per module.Always use context managers for clients and async credentials. Wrap every client in
with Client(...) as client:(sync) orasync with Client(...) as client:(async). For asyncDefaultAzureCredentialfromazure.identity.aio, also useasync with credential:so tokens and transports are cleaned up.Use
DefaultAzureCredentialfor portable auth across local dev and Azure (avoid connection strings / API keys when possible).Use CloudEvents for new applications (industry standard)
Batch events when publishing multiple events
Include meaningful subjects for filtering
Use async client for high-throughput scenarios
Handle retries — Event Grid has built-in retry
Set appropriate event types for routing and filtering
Reference Files
| File | Contents |
|---|---|
| references/capabilities.md | Additional non-hero capabilities, operation-group coverage, and production checklists. |
| references/non-hero-scenarios.md | Dedicated non-hero examples for secondary/advanced scenarios. |
Files
- ATTRIBUTION.mdAdded by AutoGineer965 B
- LICENSELicence file added by AutoGineer1.1 KiB
- SKILL.md7.2 KiB
- references/capabilities.md1.3 KiB
- references/non-hero-scenarios.md1.6 KiB
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs an API key, Needs Python
Security
What our scanner noticed· Low risk
- Instructions that use the network
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- Microsoft
- Publisher
- Microsoft (Official)
- Source
- microsoft/skills · .github/plugins/azure-sdk-python/skills/azure-eventgrid-py · commit 0696600
- Licence
- MIT License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by Microsoft.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download azure-eventgrid-py.zip