13

I have used Kafka Streams in Java. I could not find similar API in python. Do Apache Kafka support stream processing in python?

OneCricketeer
  • 126,858
  • 14
  • 92
  • 185
user3126637
  • 133
  • 1
  • 1
  • 5

2 Answers2

17

Kafka Streams is only available as a JVM library, but there are at least two Python implementations of it

In theory, you could try playing with Jython or Py4j to support it the JVM implementation, but otherwise you're stuck with consumer/producer or invoking the KSQL REST interface.

Outside of those options, you can also try Apache Beam, Flink or Spark, but they each require an external cluster scheduler to scale out.

OneCricketeer
  • 126,858
  • 14
  • 92
  • 185
1

If you are using Apache Spark, you can use Kafka as producer and Spark Structured Streaming as consumer. No need to rely on 3rd part libraries like Faust.

To consume Kafka data streams in Spark, use the Structured Streaming + Kafka Integration Guide.

Keep in mind that you will have to append spark-sql-kafka package when using spark-submit:

spark-submit --packages org.apache.spark:spark-sql-kafka-0-10_2.12:3.0.1 StructuredStreaming.py

This solution has been tested with Spark 3.0.1 and Kafka 2.7.0 with PySpark.

This resource can also be useful.