|
1 | 1 | Confluent's Apache Kafka client for Python |
2 | 2 | ========================================== |
3 | 3 |
|
| 4 | +Confluent's Kafka client for Python wraps the librdkafka C library, providing |
| 5 | +full Kafka protocol support with great performance and reliability. |
4 | 6 |
|
5 | | -Prerequisites |
6 | | -=============== |
| 7 | +The Python bindings provides a high-level Producer and Consumer with support |
| 8 | +for the balanced consumer groups of Apache Kafka 0.9. |
7 | 9 |
|
8 | | - librdkafka >=0.9.1 (or master>=2016-04-13) |
9 | | - py.test (pip install pytest) |
| 10 | +See the [API documentation](http://docs.confluent.io/current/clients/confluent-kafka-python/index.html) for more info. |
10 | 11 |
|
| 12 | +**License**: [Apache License v2.0](http://www.apache.org/licenses/LICENSE-2.0) |
11 | 13 |
|
12 | | -Build |
| 14 | + |
| 15 | +Usage |
13 | 16 | ===== |
14 | 17 |
|
15 | | - python setup.py build |
| 18 | +**Producer:** |
| 19 | + |
| 20 | +```python |
| 21 | +from confluent_kafka import Producer |
| 22 | + |
| 23 | +p = Producer({'bootstrap.servers': 'mybroker,mybroker2'}) |
| 24 | +for data in some_data_source: |
| 25 | + p.produce('mytopic', data.encode('utf-8')) |
| 26 | +p.flush() |
| 27 | +``` |
| 28 | + |
| 29 | + |
| 30 | +**High-level Consumer:** |
| 31 | + |
| 32 | +```python |
| 33 | +from confluent_kafka import Consumer |
| 34 | + |
| 35 | +c = Consumer({'bootstrap.servers': 'mybroker', 'group.id': 'mygroup', |
| 36 | + 'default.topic.config': {'auto.offset.reset': 'smallest'}}) |
| 37 | +c.subscribe(['mytopic']) |
| 38 | +while running: |
| 39 | + msg = c.poll() |
| 40 | + if not msg.error(): |
| 41 | + print('Received message: %s' % msg.value().decode('utf-8')) |
| 42 | +c.close() |
| 43 | +``` |
16 | 44 |
|
| 45 | +See [examples](examples) for more examples. |
| 46 | + |
| 47 | + |
| 48 | +Prerequisites |
| 49 | +============= |
| 50 | + |
| 51 | + * Python >= 2.7 or Python 3.x |
| 52 | + * [librdkafka](https://github.com/edenhill/librdkafka) >= 0.9.1 |
17 | 53 |
|
18 | 54 |
|
19 | 55 | Install |
20 | 56 | ======= |
21 | | -Preferably in a virtualenv: |
22 | 57 |
|
23 | | - pip install . |
| 58 | +**Install from PyPi:** |
| 59 | + |
| 60 | + $ pip install confluent-kafka |
| 61 | + |
| 62 | + |
| 63 | +**Install from source / tarball:** |
| 64 | + |
| 65 | + $ pip install . |
24 | 66 |
|
25 | 67 |
|
26 | | -Run unit-tests |
27 | | -============== |
| 68 | +Build |
| 69 | +===== |
| 70 | + |
| 71 | + $ python setup.by build |
| 72 | + |
| 73 | +If librdkafka is installed in a non-standard location provide the include and library directories with: |
| 74 | + |
| 75 | + $ CPLUS_INCLUDE_PATH=/path/to/include LIBRARY_PATH=/path/to/lib python setup.py ... |
| 76 | + |
| 77 | + |
| 78 | +Tests |
| 79 | +===== |
| 80 | + |
28 | 81 |
|
29 | | - py.test |
| 82 | +**Run unit-tests:** |
30 | 83 |
|
| 84 | + $ py.test |
| 85 | + |
| 86 | +**NOTE**: Requires `py.test`, install by `pip install pytest` |
| 87 | + |
| 88 | + |
| 89 | +**Run integration tests:** |
| 90 | + |
| 91 | + $ examples/integration_test.py <kafka-broker> |
31 | 92 |
|
32 | | -Run integration tests |
33 | | -===================== |
34 | 93 | **WARNING**: These tests require an active Kafka cluster and will make use of a topic named 'test'. |
35 | 94 |
|
36 | | - examples/integration_test.py <kafka-broker> |
37 | 95 |
|
38 | 96 |
|
39 | 97 |
|
40 | 98 | Generate documentation |
41 | 99 | ====================== |
42 | 100 | Install sphinx and sphinx_rtd_theme packages and then: |
43 | 101 |
|
44 | | - make docs |
| 102 | + $ make docs |
45 | 103 |
|
46 | 104 | or: |
47 | 105 |
|
48 | | - python setup.py build_sphinx |
49 | | - |
50 | | - |
51 | | -Documentation will be generated in `docs/_build/` |
52 | | - |
53 | | - |
54 | | -Examples |
55 | | -======== |
| 106 | + $ python setup.by build_sphinx |
56 | 107 |
|
57 | | -See [examples](examples) |
| 108 | +Documentation will be generated in `docs/_build/`. |
0 commit comments