Skip to main content
Confluent's Apache Kafka client for Python
==========================================

Confluent's Kafka client for Python wraps the librdkafka C library, providing
full Kafka protocol support with great performance and reliability.

The Python bindings provides a high-level Producer and Consumer with support
for the balanced consumer groups of Apache Kafka 0.9.

See the [API documentation](http://docs.confluent.io/current/clients/confluent-kafka-python/index.html) for more info.

**License**: [Apache License v2.0](http://www.apache.org/licenses/LICENSE-2.0)


Usage
=====

**Producer:**

```python
from confluent_kafka import Producer

p = Producer({'bootstrap.servers': 'mybroker,mybroker2'})
for data in some_data_source:
p.produce('mytopic', data.encode('utf-8'))
p.flush()
```


**High-level Consumer:**

```python
from confluent_kafka import Consumer, KafkaError

c = Consumer({'bootstrap.servers': 'mybroker', 'group.id': 'mygroup',
'default.topic.config': {'auto.offset.reset': 'smallest'}})
c.subscribe(['mytopic'])
running = True
while running:
msg = c.poll()
if not msg.error():
print('Received message: %s' % msg.value().decode('utf-8'))
elif msg.error().code() != KafkaError._PARTITION_EOF:
print(msg.error())
running = False
c.close()
```

See [examples](examples) for more examples.


Broker compatibility
====================
The Python client (as well as the underlying C library librdkafka) supports
all broker versions >= 0.8.
But due to the nature of the Kafka protocol in broker versions 0.8 and 0.9 it
is not safe for a client to assume what protocol version is actually supported
by the broker, thus you will need to hint the Python client what protocol
version it may use. This is done through two configuration settings:

* `broker.version.fallback=YOUR_BROKER_VERSION` (default 0.9.0.1)
* `api.version.request=true|false` (default false)

When using a Kafka 0.10 broker or later you only need to set
`api.version.request=true`.
If you use Kafka broker 0.9 or 0.8 you should leave
`api.version.request=false` (default) and set
`broker.version.fallback` to your broker version,
e.g `broker.version.fallback=0.9.0.1`.

More info here:
https://github.com/edenhill/librdkafka/wiki/Broker-version-compatibility


Prerequisites
=============

* Python >= 2.7 or Python 3.x
* [librdkafka](https://github.com/edenhill/librdkafka) >= 0.9.1


Install
=======

**Install from PyPi:**

$ pip install confluent-kafka


**Install from source / tarball:**

$ pip install .


Build
=====

$ python setup.py build

If librdkafka is installed in a non-standard location provide the include and library directories with:

$ C_INCLUDE_PATH=/path/to/include LIBRARY_PATH=/path/to/lib python setup.py ...


Tests
=====


**Run unit-tests:**

$ py.test

**NOTE**: Requires `py.test`, install by `pip install pytest`


**Run integration tests:**

$ examples/integration_test.py <kafka-broker>

**WARNING**: These tests require an active Kafka cluster and will make use of a topic named 'test'.




Generate documentation
======================
Install sphinx and sphinx_rtd_theme packages and then:

$ make docs

or:

$ python setup.py build_sphinx

Documentation will be generated in `docs/_build/`.

Release files for confluent-kafka 0.9.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for confluent-kafka 0.9.2
File Size Uploaded
confluent-kafka-0.9.2.tar.gz 29.2 kB Details

Release files / confluent-kafka-0.9.2.tar.gz

Download URL confluent-kafka-0.9.2.tar.gz
Size 29.2 kB
Tags Source
SHA-256 checksum
How to use checksums
cb366b2e66e880bf458218173f1c4062d7f7c7ae871bd5571f2c166b2f392720
BLAKE2b-256 checksum
How to use checksums
922378acb04c6660f32fbb8f789252e202898c0b3e0cea2ec4ac0913b7970188
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

2.9.0

36 release files

2.8.1

36 release files

2.7.0

35 release files

2.6.1

35 release files

2.6.0

39 release files

2.5.0

34 release files

2.3.0

34 release files

2.2.0

29 release files

2.0.2

29 release files

1.9.0

21 release files

1.7.0

20 release files

1.6.1

20 release files

1.5.0

26 release files

1.4.2

26 release files

1.4.1

26 release files

1.3.0

32 release files

1.2.0

26 release files

1.1.0

26 release files

1.0.1

26 release files

0.11.0

1 release file

0.9.4

1 release file

This release

0.9.2 This release

1 release file

0.9.1.1

1 release file

0.9.1

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page