Go to file
David Arthur 1c5081e6b3 Update kafka-src to latest 0.8
Fix a broken test (100k was too much to send in one batch)
2013-04-02 20:20:32 -04:00
2013-04-02 20:20:32 -04:00
2013-04-02 20:20:32 -04:00
2013-04-02 20:20:32 -04:00
2013-04-02 20:19:30 -04:00
2012-11-16 11:57:59 -05:00
2013-04-02 20:20:32 -04:00
2013-04-02 20:19:30 -04:00

Kafka Python client

This module provides low-level protocol support Apache Kafka. It implements the five basic request types (and their responses): Produce, Fetch, MultiFetch, MultiProduce, and Offsets. Gzip and Snappy compression is also supported.

Compatible with Apache Kafka 0.7x. Tested against 0.8

http://incubator.apache.org/kafka/

License

Copyright 2013, David Arthur under Apache License, v2.0. See LICENSE

Status

Current version is 0.2-alpha. This version is under development, APIs are subject to change

Install

Install with your favorite package manager

Pip:

git clone https://github.com/mumrah/kafka-python
pip install ./kafka-python

Setuptools:

git clone https://github.com/mumrah/kafka-python
easy_install ./kafka-python

Using setup.py directly:

git clone https://github.com/mumrah/kafka-python
cd kafka-python
python setup.py install

Optional Snappy install

Download and build Snappy from http://code.google.com/p/snappy/downloads/list

wget http://snappy.googlecode.com/files/snappy-1.0.5.tar.gz
tar xzvf snappy-1.0.5.tar.gz
cd snappy-1.0.5
./configure
make
sudo make install

Install the python-snappy module

pip install python-snappy

Tests

Some of the tests will fail if Snappy is not installed. These tests will throw NotImplementedError. If you see other failures, they might be bugs - so please report them!

Run the unit tests

python -m test.unit

Run the integration tests

First, checkout the Kafka source

git submodule init
git submodule update
cd kafka-src
./sbt update
./sbt package

Then from the root directory, run the integration tests

python -m test.integration

Usage

High level

from kafka.client import KafkaClient

producer = SimpleProducer(kafka, "my-topic")
producer.send_messages("some message")
producer.send_messages("this method", "is variadic")

consumer = SimpleConsumer(kafka, "my-group", "my-topic")
for message in consumer:
    print(message)

kafka.close()

Low level

from kafka.client import KafkaClient
kafka = KafkaClient("localhost", 9092)
req = ProduceRequest(topic="my-topic", partition=1,
    messages=[KafkaProdocol.encode_message("some message")])
resps = kafka.send_produce_request(payloads=[req], fail_on_error=True)
kafka.close()

resps[0].topic      # "my-topic"
resps[0].partition  # 1
resps[0].error      # 0 (hopefully)
resps[0].offset     # offset of the first message sent in this request
Description
RETIRED, further work has moved to Debian project infrastructure
Readme 1.8 MiB
Languages
Python 99.7%
Shell 0.3%