edX Event Bus Kafka

raw JSON →
6.1.0 verified Mon Apr 27 auth: no python

Kafka implementation for Open edX event bus. Provides Kafka producer/consumer for publishing and consuming Open edX events. Current version 6.1.0 (supports Django 5.2, Python >=3.8). Release cadence: irregular, ~5-10 releases per year.

pip install edx-event-bus-kafka
error ModuleNotFoundError: No module named 'edx_event_bus_kafka'
cause Library not installed or installed in wrong environment.
fix
Run: pip install edx-event-bus-kafka
error ImportError: cannot import name 'KafkaEventProducer' from 'edx_event_bus_kafka'
cause Wrong import path; older versions used different names.
fix
Use: from edx_event_bus_kafka import KafkaEventProducer
error TypeError: 'Consumer' object is not iterable
cause Using an older version or incorrect consumer instantiation.
fix
Use create_consumer() or KafkaEventConsumer() which returns an iterable.
error kafka.errors.NoBrokersAvailable
cause Kafka broker not reachable; check bootstrap servers configuration.
fix
Set KAFKA_BOOTSTRAP_SERVERS environment variable or configure in Django settings as EVENT_BUS_KAFKA_BOOTSTRAP_SERVERS.
breaking Version 6.0.0 dropped Python 3.8 support. Upgrade to Python 3.9+.
fix Use Python 3.9, 3.10, 3.11, or 3.12 (3.12 supported since v6.0.0).
deprecated The module 'edx_event_bus_kafka.internal' is private and should not be imported directly. Breaking changes may occur without notice.
fix Use public API: KafkaEventProducer, KafkaEventConsumer, get_producer, create_consumer.
gotcha Consumer must be iterated (for message in consumer:) or it will not poll. Calling consumer.poll() manually is not supported in the current API.
fix Use iteration pattern: for message in consumer: ...
gotcha Topic names often require a specific prefix (e.g., 'edx.') depending on the Open edX deployment. Check your platform's configuration.
fix Consult your Open edX instance's event bus configuration for topic naming conventions.
deprecated The setting EVENT_BUS_KAFKA_ENABLED is being phased out; configuration now uses SERVICE_VARIANT and other Django settings.
fix Configure via EVENT_BUS_PRODUCER_CONFIG and EVENT_BUS_CONSUMER_CONFIG in Django settings.

Basic produce and consume example.

from edx_event_bus_kafka import get_producer, create_consumer

# Producer example
producer = get_producer(
    topic='my-topic',
    event_type='org.openedx.learning.course.enrollment.completed.v1',
)
producer.send({
    'user_id': 123,
    'course_key': 'course-v1:edX+DemoX+Demo_Course',
})

# Consumer example
consumer = create_consumer(
    topic='my-topic',
    group_id='my-group',
)
for message in consumer:
    print(message.value)