Skip to content
azure-eventgrid-py logo

Azure Event Grid SDK for Python

azure-eventgrid-py

Azure Event Grid SDK for Python. Use for publishing events, handling CloudEvents, and event-driven architectures.

SKILL.md

Full skill instructions

Azure Event Grid SDK for Python

Event routing service for building event-driven applications with pub/​sub semantics.

Installation

pip install azure-eventgrid azure-identity

Environment Variables

EVENTGRID_TOPIC_ENDPOINT=https://<topic-name>.<region>.eventgrid.azure.net/​api/​events
EVENTGRID_NAMESPACE_ENDPOINT=https://<namespace>.<region>.eventgrid.azure.net

Authentication

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

FormatClassUse Case
Cloud Events 1.0CloudEventStandard, interoperable (recommended)
Event Grid SchemaEventGridEventAzure-native format

Publish CloudEvents

from azure.eventgrid import EventGridPublisherClient, 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():
    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.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=DefaultAzureCredential()
) as client:
    await client.send(
        event,
        namespace_topic=topic_name
    )

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.

More skills from sickn33

api-security-best-practices logo
sickn33/antigravity-awesome-skills

api-security-best-practices

Implement secure API design patterns including authentication, authorization, input validation, rate limiting, and protection against common API vulnerabilities

47.3K 7.4K
View
nextjs-best-practices logo
sickn33/antigravity-awesome-skills

nextjs-best-practices

Next.js App Router principles. Server Components, data fetching, routing patterns.

47.3K 5.7K
View
nextjs-supabase-auth logo
sickn33/antigravity-awesome-skills

nextjs-supabase-auth

Expert integration of Supabase Auth with Next.js App Router

47.3K 5.2K
View
browser-automation logo
sickn33/antigravity-awesome-skills

browser-automation

Browser automation powers web testing, scraping, and AI agent

47.3K 5.1K
View
prisma-expert logo
sickn33/antigravity-awesome-skills

prisma-expert

prisma expert

47.3K 3.6K
View
playwright-skill logo
sickn33/antigravity-awesome-skills

playwright-skill

playwright skill

47.3K 3.3K
View
game-development logo
sickn33/antigravity-awesome-skills

game-development

Game development orchestrator. Routes to platform-specific skills based on project needs.

47.3K 2.7K
View
mobile-design logo
sickn33/antigravity-awesome-skills

mobile-design

(Mobile-First · Touch-First · Platform-Respectful)

47.3K 2.6K
View
ui-ux-pro-max logo
sickn33/antigravity-awesome-skills

ui-ux-pro-max

ui ux pro max

47.3K 2.5K
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View