[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-0e197678-ff29-4238-b27a-9cc364d973af":3,"$fxod_N-3TiqmMr59I5ukr2gcYBmkg8XZDSQ3Jpk_KEZ0":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},"0e197678-ff29-4238-b27a-9cc364d973af","azure-eventhub-py","Azure事件中心Python SDK流式处理。用于高吞吐量事件摄取、生产者、消费者和检查点。","cat_coding_devops","mod_coding","sickn33,coding","---\nname: azure-eventhub-py\ndescription: Azure Event Hubs SDK for Python streaming. Use for high-throughput event ingestion, producers, consumers, and checkpointing.\nrisk: unknown\nsource: community\ndate_added: '2026-02-27'\n---\n\n# Azure Event Hubs SDK for Python\n\nBig data streaming platform for high-throughput event ingestion.\n\n## Installation\n\n```bash\npip install azure-eventhub azure-identity\n# For checkpointing with blob storage\npip install azure-eventhub-checkpointstoreblob-aio\n```\n\n## Environment Variables\n\n```bash\nEVENT_HUB_FULLY_QUALIFIED_NAMESPACE=\u003Cnamespace>.servicebus.windows.net\nEVENT_HUB_NAME=my-eventhub\nSTORAGE_ACCOUNT_URL=https:\u002F\u002F\u003Caccount>.blob.core.windows.net\nCHECKPOINT_CONTAINER=checkpoints\n```\n\n## Authentication\n\n```python\nfrom azure.identity import DefaultAzureCredential\nfrom azure.eventhub import EventHubProducerClient, EventHubConsumerClient\n\ncredential = DefaultAzureCredential()\nnamespace = \"\u003Cnamespace>.servicebus.windows.net\"\neventhub_name = \"my-eventhub\"\n\n# Producer\nproducer = EventHubProducerClient(\n    fully_qualified_namespace=namespace,\n    eventhub_name=eventhub_name,\n    credential=credential\n)\n\n# Consumer\nconsumer = EventHubConsumerClient(\n    fully_qualified_namespace=namespace,\n    eventhub_name=eventhub_name,\n    consumer_group=\"$Default\",\n    credential=credential\n)\n```\n\n## Client Types\n\n| Client | Purpose |\n|--------|---------|\n| `EventHubProducerClient` | Send events to Event Hub |\n| `EventHubConsumerClient` | Receive events from Event Hub |\n| `BlobCheckpointStore` | Track consumer progress |\n\n## Send Events\n\n```python\nfrom azure.eventhub import EventHubProducerClient, EventData\nfrom azure.identity import DefaultAzureCredential\n\nproducer = EventHubProducerClient(\n    fully_qualified_namespace=\"\u003Cnamespace>.servicebus.windows.net\",\n    eventhub_name=\"my-eventhub\",\n    credential=DefaultAzureCredential()\n)\n\nwith producer:\n    # Create batch (handles size limits)\n    event_data_batch = producer.create_batch()\n    \n    for i in range(10):\n        try:\n            event_data_batch.add(EventData(f\"Event {i}\"))\n        except ValueError:\n            # Batch is full, send and create new one\n            producer.send_batch(event_data_batch)\n            event_data_batch = producer.create_batch()\n            event_data_batch.add(EventData(f\"Event {i}\"))\n    \n    # Send remaining\n    producer.send_batch(event_data_batch)\n```\n\n### Send to Specific Partition\n\n```python\n# By partition ID\nevent_data_batch = producer.create_batch(partition_id=\"0\")\n\n# By partition key (consistent hashing)\nevent_data_batch = producer.create_batch(partition_key=\"user-123\")\n```\n\n## Receive Events\n\n### Simple Receive\n\n```python\nfrom azure.eventhub import EventHubConsumerClient\n\ndef on_event(partition_context, event):\n    print(f\"Partition: {partition_context.partition_id}\")\n    print(f\"Data: {event.body_as_str()}\")\n    partition_context.update_checkpoint(event)\n\nconsumer = EventHubConsumerClient(\n    fully_qualified_namespace=\"\u003Cnamespace>.servicebus.windows.net\",\n    eventhub_name=\"my-eventhub\",\n    consumer_group=\"$Default\",\n    credential=DefaultAzureCredential()\n)\n\nwith consumer:\n    consumer.receive(\n        on_event=on_event,\n        starting_position=\"-1\",  # Beginning of stream\n    )\n```\n\n### With Blob Checkpoint Store (Production)\n\n```python\nfrom azure.eventhub import EventHubConsumerClient\nfrom azure.eventhub.extensions.checkpointstoreblob import BlobCheckpointStore\nfrom azure.identity import DefaultAzureCredential\n\ncheckpoint_store = BlobCheckpointStore(\n    blob_account_url=\"https:\u002F\u002F\u003Caccount>.blob.core.windows.net\",\n    container_name=\"checkpoints\",\n    credential=DefaultAzureCredential()\n)\n\nconsumer = EventHubConsumerClient(\n    fully_qualified_namespace=\"\u003Cnamespace>.servicebus.windows.net\",\n    eventhub_name=\"my-eventhub\",\n    consumer_group=\"$Default\",\n    credential=DefaultAzureCredential(),\n    checkpoint_store=checkpoint_store\n)\n\ndef on_event(partition_context, event):\n    print(f\"Received: {event.body_as_str()}\")\n    # Checkpoint after processing\n    partition_context.update_checkpoint(event)\n\nwith consumer:\n    consumer.receive(on_event=on_event)\n```\n\n## Async Client\n\n```python\nfrom azure.eventhub.aio import EventHubProducerClient, EventHubConsumerClient\nfrom azure.identity.aio import DefaultAzureCredential\nimport asyncio\n\nasync def send_events():\n    credential = DefaultAzureCredential()\n    \n    async with EventHubProducerClient(\n        fully_qualified_namespace=\"\u003Cnamespace>.servicebus.windows.net\",\n        eventhub_name=\"my-eventhub\",\n        credential=credential\n    ) as producer:\n        batch = await producer.create_batch()\n        batch.add(EventData(\"Async event\"))\n        await producer.send_batch(batch)\n\nasync def receive_events():\n    async def on_event(partition_context, event):\n        print(event.body_as_str())\n        await partition_context.update_checkpoint(event)\n    \n    async with EventHubConsumerClient(\n        fully_qualified_namespace=\"\u003Cnamespace>.servicebus.windows.net\",\n        eventhub_name=\"my-eventhub\",\n        consumer_group=\"$Default\",\n        credential=DefaultAzureCredential()\n    ) as consumer:\n        await consumer.receive(on_event=on_event)\n\nasyncio.run(send_events())\n```\n\n## Event Properties\n\n```python\nevent = EventData(\"My event body\")\n\n# Set properties\nevent.properties = {\"custom_property\": \"value\"}\nevent.content_type = \"application\u002Fjson\"\n\n# Read properties (on receive)\nprint(event.body_as_str())\nprint(event.sequence_number)\nprint(event.offset)\nprint(event.enqueued_time)\nprint(event.partition_key)\n```\n\n## Get Event Hub Info\n\n```python\nwith producer:\n    info = producer.get_eventhub_properties()\n    print(f\"Name: {info['name']}\")\n    print(f\"Partitions: {info['partition_ids']}\")\n    \n    for partition_id in info['partition_ids']:\n        partition_info = producer.get_partition_properties(partition_id)\n        print(f\"Partition {partition_id}: {partition_info['last_enqueued_sequence_number']}\")\n```\n\n## Best Practices\n\n1. **Use batches** for sending multiple events\n2. **Use checkpoint store** in production for reliable processing\n3. **Use async client** for high-throughput scenarios\n4. **Use partition keys** for ordered delivery within a partition\n5. **Handle batch size limits** — catch ValueError when batch is full\n6. **Use context managers** (`with`\u002F`async with`) for proper cleanup\n7. **Set appropriate consumer groups** for different applications\n\n## Reference Files\n\n| File | Contents |\n|------|----------|\n| references\u002Fcheckpointing.md | Checkpoint store patterns, blob checkpointing, checkpoint strategies |\n| references\u002Fpartitions.md | Partition management, load balancing, starting positions |\n| scripts\u002Fsetup_consumer.py | CLI for Event Hub info, consumer setup, and event sending\u002Freceiving |\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,219,1028,"2026-05-16 13:06:22",{"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},"e08cc95d-2ee4-43fd-87d3-2a4ff98e503a","1.0.0","azure-eventhub-py.zip",2296,"uploads\u002Fskills\u002F0e197678-ff29-4238-b27a-9cc364d973af\u002Fazure-eventhub-py.zip","506684087a230d0892f3fc4c8b44e8b2ba743cbb6c45241940e940ebf25ad14b","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":7197}]",{"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]