Skip to main content

Full-Featured Pure-Python Kafka Client

Project description

https://travis-ci.org/Parsely/pykafka.svg?branch=master https://coveralls.io/repos/Parsely/pykafka/badge.svg?branch=master

PyKafka

http://i.imgur.com/ztYl4lG.jpg

PyKafka is a cluster-aware Kafka protocol client for python. It includes python implementations of Kafka producers and consumers, and runs under python 2.7.

PyKafka’s primary goal is to provide a similar level of abstraction to the JVM Kafka client using idioms familiar to python programmers and exposing the most pythonic API possible.

You can install PyKafka from PyPI with

$ pip install pykafka

Full documentation and usage examples for PyKafka can be found on readthedocs.

You can install PyKafka for local development and testing with

$ python setup.py develop

Getting Started

Assuming you have a Kafka instance running on localhost, you can use PyKafka to connect to it.

>>> from pykafka import KafkaClient
>>> client = KafkaClient(hosts="127.0.0.1:9092")

If the cluster you’ve connected to has any topics defined on it, you can list them with:

>>> client.topics
{'my.test': <pykafka.topic.Topic at 0x19bc8c0 (name=my.test)>}
>>> topic = client.topics['my.test']

Once you’ve got a Topic, you can create a Producer for it and start producing messages.

>>> with topic.get_producer() as producer:
...     for i in range(4):
...         producer.produce('test message ' + i ** 2)

You can also consume messages from this topic using a Consumer instance.

>>> consumer = topic.get_simple_consumer()
>>> for message in consumer:
    if message is not None:
        print message.offset, message.value
0 test message 0
1 test message 1
2 test message 4
3 test message 9

This SimpleConsumer doesn’t scale - if you have two SimpleConsumers consuming the same topic, they will receive duplicate messages. To get around this, you can use the BalancedConsumer.

>>> balanced_consumer = topic.get_balanced_consumer(
    consumer_group='testgroup',
    auto_commit_enable=True,
    zookeeper_connect='myZkClusterNode1.com:2181,myZkClusterNode2.com:2181/myZkChroot'
)

You can have as many BalancedConsumer instances consuming a topic as that topic has partitions. If they are all connected to the same zookeeper instance, they will communicate with it to automatically balance the partitions between themselves.

What happened to Samsa?

This project used to be called samsa. It has been renamed PyKafka and has been fully overhauled to support Kafka 0.8.2. We chose to target 0.8.2 because it’s currently the latest stable version, and the Offset Commit/Fetch API is stabilized.

The Samsa PyPI package will stay up for the foreseeable future and tags for previous versions will always be available in this repo.

Support

If you need help using PyKafka or have found a bug, please open a github issue or use the Google Group.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pykafka-2.0.0.tar.gz (61.7 kB view details)

Uploaded Source

Built Distributions

pykafka-2.0.0.linux-x86_64.tar.gz (138.3 kB view details)

Uploaded Source

pykafka-2.0.0-py2.py3-none-any.whl (80.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pykafka-2.0.0.tar.gz.

File metadata

  • Download URL: pykafka-2.0.0.tar.gz
  • Upload date:
  • Size: 61.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pykafka-2.0.0.tar.gz
Algorithm Hash digest
SHA256 8904fb491e5f6392588fe9ec858db6f6f60b252ee0b16dff64fcab99ac486d53
MD5 412e47756e31d5fbb96541cd3b519da7
BLAKE2b-256 c38a632962024dc6a41b13109a02a5e7e28080b7bf670b3181e77027d908425d

See more details on using hashes here.

File details

Details for the file pykafka-2.0.0.linux-x86_64.tar.gz.

File metadata

File hashes

Hashes for pykafka-2.0.0.linux-x86_64.tar.gz
Algorithm Hash digest
SHA256 aadc3048a2729144e65909b8c41994f2f2874bc370b500a349ed32329aa015f9
MD5 652f07dc5def3ac14d5d1daa8dacf70e
BLAKE2b-256 c6983444318bfc813f7595f7503ff0d842e0df9a55cff9419f57ba2e1dfb5f84

See more details on using hashes here.

File details

Details for the file pykafka-2.0.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pykafka-2.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 90fb6c25785728b2bc864b515f8964e156e99011ae6397d014a0e58659976415
MD5 b2bff6c914c814a0c9d50ffc27ff5a1c
BLAKE2b-256 bd64fe749debc52f2ade37676a1b29fccebe6d849dd90759a81c74ea191d351b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page