kafka-producer-pattern — async Kafka producer for FastAPI kafka-producer-pattern, community, async Kafka producer for FastAPI, ide skills, install kafka-producer-pattern, Claude Code, Cursor, Windsurf

v1.0.0
GitHub

About this Skill

Ideal for FastAPI Agents requiring scalable and secure data pipeline integration with Kafka producer capabilities. kafka-producer-pattern is an asynchronous Kafka producer implementation for FastAPI, ensuring mandatory user isolation and efficient data processing.

Features

Utilizes aiokafka for asynchronous Kafka production
Implements mandatory user isolation for secure data processing
Compatible with FastAPI for building scalable web applications
Supports singleton producer creation for efficient resource management
Handles Kafka unavailability with a fallback mechanism

# Core Topics

safdarayubpk safdarayubpk
[6]
[1]
Updated: 2/26/2026

Agent Capability Analysis

The kafka-producer-pattern skill by safdarayubpk is an open-source community AI agent skill for Claude Code and other IDE workflows, helping agents execute tasks with better context, repeatability, and domain-specific guidance. Optimized for async Kafka producer for FastAPI, install kafka-producer-pattern.

Ideal Agent Persona

Ideal for FastAPI Agents requiring scalable and secure data pipeline integration with Kafka producer capabilities.

Core Value

Empowers agents to build async Kafka producers with user isolation, utilizing libraries like aiokafka for robust data handling and secure data transmission over Kafka protocols.

Capabilities Granted for kafka-producer-pattern

Building scalable data pipelines with async Kafka producers
Implementing user isolation for secure data processing
Integrating Kafka with FastAPI for real-time data streaming

! Prerequisites & Limits

  • Requires aiokafka library
  • Kafka availability mandatory
  • Designed for FastAPI framework
Labs Demo

Browser Sandbox Environment

⚡️ Ready to unleash?

Experience this Agent in a zero-setup browser environment powered by WebContainers. No installation required.

Boot Container Sandbox

kafka-producer-pattern

Install kafka-producer-pattern, an AI agent skill for AI agent workflows and automation. Works with Claude Code, Cursor, and Windsurf with one-command setup.

SKILL.md
Readonly

Kafka Producer Pattern

Async Kafka producer for FastAPI with mandatory user isolation.

Setup

python
1# services/kafka_producer.py 2import os 3import json 4import logging 5from datetime import datetime, timezone 6from typing import Any 7from aiokafka import AIOKafkaProducer 8 9logger = logging.getLogger(__name__) 10 11_producer: AIOKafkaProducer | None = None 12 13async def get_producer() -> AIOKafkaProducer | None: 14 """Get or create singleton producer. Returns None if Kafka unavailable.""" 15 global _producer 16 if _producer is not None: 17 return _producer 18 19 bootstrap_servers = os.getenv("KAFKA_BOOTSTRAP_SERVERS") 20 if not bootstrap_servers: 21 logger.warning("KAFKA_BOOTSTRAP_SERVERS not set, events disabled") 22 return None 23 24 try: 25 _producer = AIOKafkaProducer( 26 bootstrap_servers=bootstrap_servers, 27 value_serializer=lambda v: json.dumps(v).encode("utf-8"), 28 ) 29 await _producer.start() 30 logger.info("Kafka producer started") 31 return _producer 32 except Exception as e: 33 logger.error(f"Failed to start Kafka producer: {e}") 34 return None 35 36async def close_producer(): 37 """Shutdown producer gracefully.""" 38 global _producer 39 if _producer: 40 await _producer.stop() 41 _producer = None

Event Producer Function

python
1# services/kafka_producer.py (continued) 2 3async def produce_event( 4 event_type: str, 5 user_id: int, 6 payload: dict[str, Any], 7 topic: str = "todo-events" 8) -> bool: 9 """ 10 Produce event with user isolation. Never crashes endpoint. 11 12 Args: 13 event_type: Event name (e.g., "task-created", "task-completed") 14 user_id: Current user's ID (required for isolation) 15 payload: Event-specific data 16 topic: Kafka topic (default: todo-events) 17 18 Returns: 19 True if sent, False if failed/disabled 20 """ 21 producer = await get_producer() 22 if not producer: 23 return False 24 25 event = { 26 "event_type": event_type, 27 "timestamp": datetime.now(timezone.utc).isoformat(), 28 "user_id": user_id, 29 "payload": payload, 30 } 31 32 try: 33 await producer.send_and_wait(topic, event) 34 logger.debug(f"Event produced: {event_type} for user {user_id}") 35 return True 36 except Exception as e: 37 logger.error(f"Failed to produce event: {e}") 38 return False

Endpoint Usage

python
1from services.kafka_producer import produce_event 2 3@router.post("/tasks", response_model=TaskResponse) 4async def create_task( 5 task_data: TaskCreate, 6 current_user: User = Depends(get_current_user) 7): 8 # Create task in database 9 task = await task_service.create(task_data, current_user.id) 10 11 # Produce event (fire-and-forget, won't crash if Kafka down) 12 await produce_event( 13 event_type="task-created", 14 user_id=current_user.id, 15 payload={"task_id": task.id, "title": task.title} 16 ) 17 18 return task

Lifespan Integration

python
1# main.py 2from contextlib import asynccontextmanager 3from services.kafka_producer import get_producer, close_producer 4 5@asynccontextmanager 6async def lifespan(app: FastAPI): 7 await get_producer() # Initialize on startup 8 yield 9 await close_producer() # Cleanup on shutdown 10 11app = FastAPI(lifespan=lifespan)

Event Schema

All events follow this structure:

json
1{ 2 "event_type": "task-created", 3 "timestamp": "2026-02-09T12:00:00+00:00", 4 "user_id": 123, 5 "payload": { 6 "task_id": 456, 7 "title": "Buy groceries" 8 } 9}

Common Event Types

EventPayload
task-created{task_id, title, priority?}
task-completed{task_id}
task-deleted{task_id}
task-updated{task_id, changes: {...}}

Requirements

aiokafka>=0.10.0

Environment

KAFKA_BOOTSTRAP_SERVERS=localhost:9092

FAQ & Installation Steps

These questions and steps mirror the structured data on this page for better search understanding.

? Frequently Asked Questions

What is kafka-producer-pattern?

Ideal for FastAPI Agents requiring scalable and secure data pipeline integration with Kafka producer capabilities. kafka-producer-pattern is an asynchronous Kafka producer implementation for FastAPI, ensuring mandatory user isolation and efficient data processing.

How do I install kafka-producer-pattern?

Run the command: npx killer-skills add safdarayubpk/flow/kafka-producer-pattern. It works with Cursor, Windsurf, VS Code, Claude Code, and 19+ other IDEs.

What are the use cases for kafka-producer-pattern?

Key use cases include: Building scalable data pipelines with async Kafka producers, Implementing user isolation for secure data processing, Integrating Kafka with FastAPI for real-time data streaming.

Which IDEs are compatible with kafka-producer-pattern?

This skill is compatible with Cursor, Windsurf, VS Code, Trae, Claude Code, OpenClaw, Aider, Codex, OpenCode, Goose, Cline, Roo Code, Kiro, Augment Code, Continue, GitHub Copilot, Sourcegraph Cody, and Amazon Q Developer. Use the Killer-Skills CLI for universal one-command installation.

Are there any limitations for kafka-producer-pattern?

Requires aiokafka library. Kafka availability mandatory. Designed for FastAPI framework.

How To Install

  1. 1. Open your terminal

    Open the terminal or command line in your project directory.

  2. 2. Run the install command

    Run: npx killer-skills add safdarayubpk/flow/kafka-producer-pattern. The CLI will automatically detect your IDE or AI agent and configure the skill.

  3. 3. Start using the skill

    The skill is now active. Your AI agent can use kafka-producer-pattern immediately in the current project.

Related Skills

Looking for an alternative to kafka-producer-pattern or another community skill for your workflow? Explore these related open-source skills.

View All

widget-generator

Logo of f
f

f.k.a. Awesome ChatGPT Prompts. Share, discover, and collect prompts from the community. Free and open source — self-host for your organization with complete privacy.

149.6k
0
AI

flags

Logo of vercel
vercel

flags is a Next.js feature management skill that enables developers to efficiently add or modify framework feature flags, streamlining React application development.

138.4k
0
Browser

zustand

Logo of lobehub
lobehub

The ultimate space for work and life — to find, build, and collaborate with agent teammates that grow with you. We are taking agent harness to the next level — enabling multi-agent collaboration, effortless agent team design, and introducing agents as the unit of work interaction.

72.8k
0
AI

data-fetching

Logo of lobehub
lobehub

The ultimate space for work and life — to find, build, and collaborate with agent teammates that grow with you. We are taking agent harness to the next level — enabling multi-agent collaboration, effortless agent team design, and introducing agents as the unit of work interaction.

72.8k
0
AI