kafka-python 2.0.3__tar.gz → 2.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {kafka-python-2.0.3 → kafka_python-2.0.4}/CHANGES.md +32 -0
- kafka_python-2.0.4/PKG-INFO +250 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/admin/client.py +340 -108
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/client_async.py +81 -37
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/cluster.py +1 -1
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/codec.py +9 -2
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/conn.py +36 -22
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/consumer/group.py +2 -2
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/coordinator/base.py +9 -0
- kafka_python-2.0.4/kafka/errors.py +1097 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/producer/kafka.py +3 -3
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/producer/sender.py +6 -6
- kafka_python-2.0.4/kafka/version.py +1 -0
- kafka_python-2.0.4/kafka_python.egg-info/PKG-INFO +250 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka_python.egg-info/SOURCES.txt +1 -1
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka_python.egg-info/requires.txt +5 -0
- kafka_python-2.0.4/pyproject.toml +54 -0
- kafka_python-2.0.4/setup.cfg +4 -0
- kafka_python-2.0.4/setup.py +4 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/test/test_client_async.py +12 -18
- {kafka-python-2.0.3 → kafka_python-2.0.4}/test/test_codec.py +2 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/test/test_conn.py +22 -2
- {kafka-python-2.0.3 → kafka_python-2.0.4}/test/test_consumer_integration.py +2 -0
- kafka-python-2.0.3/PKG-INFO +0 -244
- kafka-python-2.0.3/kafka/errors.py +0 -538
- kafka-python-2.0.3/kafka/version.py +0 -1
- kafka-python-2.0.3/kafka_python.egg-info/PKG-INFO +0 -244
- kafka-python-2.0.3/setup.cfg +0 -10
- kafka-python-2.0.3/setup.py +0 -78
- {kafka-python-2.0.3 → kafka_python-2.0.4}/AUTHORS.md +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/LICENSE +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/MANIFEST.in +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/README.rst +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/__init__.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/admin/__init__.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/admin/acl_resource.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/admin/config_resource.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/admin/new_partitions.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/admin/new_topic.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/consumer/__init__.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/consumer/fetcher.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/consumer/subscription_state.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/coordinator/__init__.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/coordinator/assignors/__init__.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/coordinator/assignors/abstract.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/coordinator/assignors/range.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/coordinator/assignors/roundrobin.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/coordinator/assignors/sticky/__init__.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/coordinator/assignors/sticky/partition_movements.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/coordinator/assignors/sticky/sorted_set.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/coordinator/assignors/sticky/sticky_assignor.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/coordinator/consumer.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/coordinator/heartbeat.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/coordinator/protocol.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/future.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/metrics/__init__.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/metrics/compound_stat.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/metrics/dict_reporter.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/metrics/kafka_metric.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/metrics/measurable.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/metrics/measurable_stat.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/metrics/metric_config.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/metrics/metric_name.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/metrics/metrics.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/metrics/metrics_reporter.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/metrics/quota.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/metrics/stat.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/metrics/stats/__init__.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/metrics/stats/avg.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/metrics/stats/count.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/metrics/stats/histogram.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/metrics/stats/max_stat.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/metrics/stats/min_stat.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/metrics/stats/percentile.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/metrics/stats/percentiles.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/metrics/stats/rate.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/metrics/stats/sampled_stat.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/metrics/stats/sensor.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/metrics/stats/total.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/oauth/__init__.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/oauth/abstract.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/partitioner/__init__.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/partitioner/default.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/producer/__init__.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/producer/buffer.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/producer/future.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/producer/record_accumulator.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/protocol/__init__.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/protocol/abstract.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/protocol/admin.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/protocol/api.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/protocol/commit.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/protocol/fetch.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/protocol/frame.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/protocol/group.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/protocol/message.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/protocol/metadata.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/protocol/offset.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/protocol/parser.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/protocol/pickle.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/protocol/produce.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/protocol/struct.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/protocol/types.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/record/__init__.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/record/_crc32c.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/record/abc.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/record/default_records.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/record/legacy_records.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/record/memory_records.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/record/util.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/scram.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/serializer/__init__.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/serializer/abstract.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/structs.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/util.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/vendor/__init__.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/vendor/enum34.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/vendor/selectors34.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/vendor/six.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka/vendor/socketpair.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka_python.egg-info/dependency_links.txt +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/kafka_python.egg-info/top_level.txt +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/test/test_acl_comparisons.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/test/test_admin.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/test/test_admin_integration.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/test/test_api_object_implementation.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/test/test_assignors.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/test/test_cluster.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/test/test_consumer.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/test/test_consumer_group.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/test/test_coordinator.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/test/test_fetcher.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/test/test_metrics.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/test/test_object_conversion.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/test/test_package.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/test/test_partition_movements.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/test/test_partitioner.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/test/test_producer.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/test/test_protocol.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/test/test_sasl_integration.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/test/test_sender.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/test/test_subscription_state.py +0 -0
- {kafka-python-2.0.3 → kafka_python-2.0.4}/test/testutil.py +0 -0
|
@@ -1,3 +1,35 @@
|
|
|
1
|
+
# 2.0.4 (Feb 21, 2025)
|
|
2
|
+
|
|
3
|
+
Networking
|
|
4
|
+
* Check for wakeup socket errors on read and close and reinit to reset (#2482)
|
|
5
|
+
* Improve client networking backoff / retry (#2480)
|
|
6
|
+
* Check for socket and unresolved futures before creating selector in conn.check_version (#2477)
|
|
7
|
+
* Handle socket init errors, e.g., when IPv6 is disabled (#2476)
|
|
8
|
+
|
|
9
|
+
Fixes
|
|
10
|
+
* Avoid self-join in heartbeat thread close (#2488)
|
|
11
|
+
|
|
12
|
+
Error Handling
|
|
13
|
+
* Always log broker errors in producer.send (#2478)
|
|
14
|
+
* Retain unrecognized broker response error codes with dynamic error class (#2481)
|
|
15
|
+
* Update kafka.errors with latest types (#2485)
|
|
16
|
+
|
|
17
|
+
Compatibility
|
|
18
|
+
* Do not validate snappy xerial header version and compat fields (for redpanda) (#2483)
|
|
19
|
+
|
|
20
|
+
Documentation
|
|
21
|
+
* Added missing docstrings in admin/client.py (#2487)
|
|
22
|
+
|
|
23
|
+
Testing
|
|
24
|
+
* Update kafka broker test matrix; test against 3.9.0 (#2486)
|
|
25
|
+
* Add default resources for new kafka server fixtures (#2484)
|
|
26
|
+
* Drop make test-local; add PYTESTS configuration var
|
|
27
|
+
* Fix pytest runs when KAFKA_VERSION is not set
|
|
28
|
+
|
|
29
|
+
Project Maintenance
|
|
30
|
+
* Migrate to pyproject.toml / PEP-621
|
|
31
|
+
* Remove old travis files; update compatibility tests link to gha
|
|
32
|
+
|
|
1
33
|
# 2.0.3 (Feb 12, 2025)
|
|
2
34
|
|
|
3
35
|
Improvements
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: kafka-python
|
|
3
|
+
Version: 2.0.4
|
|
4
|
+
Summary: Pure Python client for Apache Kafka
|
|
5
|
+
Author-email: Dana Powers <dana.powers@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/dpkp/kafka-python
|
|
7
|
+
Keywords: apache kafka,kafka
|
|
8
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
11
|
+
Classifier: Programming Language :: Python
|
|
12
|
+
Classifier: Programming Language :: Python :: 2
|
|
13
|
+
Classifier: Programming Language :: Python :: 2.7
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.4
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.5
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
25
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
26
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
27
|
+
Description-Content-Type: text/x-rst
|
|
28
|
+
Provides-Extra: crc32c
|
|
29
|
+
Requires-Dist: crc32c; extra == "crc32c"
|
|
30
|
+
Provides-Extra: lz4
|
|
31
|
+
Requires-Dist: lz4; extra == "lz4"
|
|
32
|
+
Provides-Extra: snappy
|
|
33
|
+
Requires-Dist: python-snappy; extra == "snappy"
|
|
34
|
+
Provides-Extra: zstd
|
|
35
|
+
Requires-Dist: zstandard; extra == "zstd"
|
|
36
|
+
Provides-Extra: testing
|
|
37
|
+
Requires-Dist: pytest; extra == "testing"
|
|
38
|
+
Requires-Dist: mock; extra == "testing"
|
|
39
|
+
Requires-Dist: pytest-mock; extra == "testing"
|
|
40
|
+
|
|
41
|
+
Kafka Python client
|
|
42
|
+
------------------------
|
|
43
|
+
|
|
44
|
+
.. image:: https://img.shields.io/badge/kafka-2.6%2C%202.5%2C%202.4%2C%202.3%2C%202.2%2C%202.1%2C%202.0%2C%201.1%2C%201.0%2C%200.11%2C%200.10%2C%200.9%2C%200.8-brightgreen.svg
|
|
45
|
+
:target: https://kafka-python.readthedocs.io/en/master/compatibility.html
|
|
46
|
+
.. image:: https://img.shields.io/pypi/pyversions/kafka-python.svg
|
|
47
|
+
:target: https://pypi.python.org/pypi/kafka-python
|
|
48
|
+
.. image:: https://coveralls.io/repos/dpkp/kafka-python/badge.svg?branch=master&service=github
|
|
49
|
+
:target: https://coveralls.io/github/dpkp/kafka-python?branch=master
|
|
50
|
+
.. image:: https://img.shields.io/badge/license-Apache%202-blue.svg
|
|
51
|
+
:target: https://github.com/dpkp/kafka-python/blob/master/LICENSE
|
|
52
|
+
.. image:: https://img.shields.io/pypi/dw/kafka-python.svg
|
|
53
|
+
:target: https://pypistats.org/packages/kafka-python
|
|
54
|
+
.. image:: https://img.shields.io/pypi/v/kafka-python.svg
|
|
55
|
+
:target: https://pypi.org/project/kafka-python
|
|
56
|
+
.. image:: https://img.shields.io/pypi/implementation/kafka-python
|
|
57
|
+
:target: https://github.com/dpkp/kafka-python/blob/master/setup.py
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
Python client for the Apache Kafka distributed stream processing system.
|
|
62
|
+
kafka-python is designed to function much like the official java client, with a
|
|
63
|
+
sprinkling of pythonic interfaces (e.g., consumer iterators).
|
|
64
|
+
|
|
65
|
+
kafka-python is best used with newer brokers (0.9+), but is backwards-compatible with
|
|
66
|
+
older versions (to 0.8.0). Some features will only be enabled on newer brokers.
|
|
67
|
+
For example, fully coordinated consumer groups -- i.e., dynamic partition
|
|
68
|
+
assignment to multiple consumers in the same group -- requires use of 0.9+ kafka
|
|
69
|
+
brokers. Supporting this feature for earlier broker releases would require
|
|
70
|
+
writing and maintaining custom leadership election and membership / health
|
|
71
|
+
check code (perhaps using zookeeper or consul). For older brokers, you can
|
|
72
|
+
achieve something similar by manually assigning different partitions to each
|
|
73
|
+
consumer instance with config management tools like chef, ansible, etc. This
|
|
74
|
+
approach will work fine, though it does not support rebalancing on failures.
|
|
75
|
+
See https://kafka-python.readthedocs.io/en/master/compatibility.html
|
|
76
|
+
for more details.
|
|
77
|
+
|
|
78
|
+
Please note that the master branch may contain unreleased features. For release
|
|
79
|
+
documentation, please see readthedocs and/or python's inline help.
|
|
80
|
+
|
|
81
|
+
.. code-block:: bash
|
|
82
|
+
|
|
83
|
+
$ pip install kafka-python
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
KafkaConsumer
|
|
87
|
+
*************
|
|
88
|
+
|
|
89
|
+
KafkaConsumer is a high-level message consumer, intended to operate as similarly
|
|
90
|
+
as possible to the official java client. Full support for coordinated
|
|
91
|
+
consumer groups requires use of kafka brokers that support the Group APIs: kafka v0.9+.
|
|
92
|
+
|
|
93
|
+
See https://kafka-python.readthedocs.io/en/master/apidoc/KafkaConsumer.html
|
|
94
|
+
for API and configuration details.
|
|
95
|
+
|
|
96
|
+
The consumer iterator returns ConsumerRecords, which are simple namedtuples
|
|
97
|
+
that expose basic message attributes: topic, partition, offset, key, and value:
|
|
98
|
+
|
|
99
|
+
.. code-block:: python
|
|
100
|
+
|
|
101
|
+
from kafka import KafkaConsumer
|
|
102
|
+
consumer = KafkaConsumer('my_favorite_topic')
|
|
103
|
+
for msg in consumer:
|
|
104
|
+
print (msg)
|
|
105
|
+
|
|
106
|
+
.. code-block:: python
|
|
107
|
+
|
|
108
|
+
# join a consumer group for dynamic partition assignment and offset commits
|
|
109
|
+
from kafka import KafkaConsumer
|
|
110
|
+
consumer = KafkaConsumer('my_favorite_topic', group_id='my_favorite_group')
|
|
111
|
+
for msg in consumer:
|
|
112
|
+
print (msg)
|
|
113
|
+
|
|
114
|
+
.. code-block:: python
|
|
115
|
+
|
|
116
|
+
# manually assign the partition list for the consumer
|
|
117
|
+
from kafka import TopicPartition
|
|
118
|
+
consumer = KafkaConsumer(bootstrap_servers='localhost:1234')
|
|
119
|
+
consumer.assign([TopicPartition('foobar', 2)])
|
|
120
|
+
msg = next(consumer)
|
|
121
|
+
|
|
122
|
+
.. code-block:: python
|
|
123
|
+
|
|
124
|
+
# Deserialize msgpack-encoded values
|
|
125
|
+
consumer = KafkaConsumer(value_deserializer=msgpack.loads)
|
|
126
|
+
consumer.subscribe(['msgpackfoo'])
|
|
127
|
+
for msg in consumer:
|
|
128
|
+
assert isinstance(msg.value, dict)
|
|
129
|
+
|
|
130
|
+
.. code-block:: python
|
|
131
|
+
|
|
132
|
+
# Access record headers. The returned value is a list of tuples
|
|
133
|
+
# with str, bytes for key and value
|
|
134
|
+
for msg in consumer:
|
|
135
|
+
print (msg.headers)
|
|
136
|
+
|
|
137
|
+
.. code-block:: python
|
|
138
|
+
|
|
139
|
+
# Get consumer metrics
|
|
140
|
+
metrics = consumer.metrics()
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
KafkaProducer
|
|
144
|
+
*************
|
|
145
|
+
|
|
146
|
+
KafkaProducer is a high-level, asynchronous message producer. The class is
|
|
147
|
+
intended to operate as similarly as possible to the official java client.
|
|
148
|
+
See https://kafka-python.readthedocs.io/en/master/apidoc/KafkaProducer.html
|
|
149
|
+
for more details.
|
|
150
|
+
|
|
151
|
+
.. code-block:: python
|
|
152
|
+
|
|
153
|
+
from kafka import KafkaProducer
|
|
154
|
+
producer = KafkaProducer(bootstrap_servers='localhost:1234')
|
|
155
|
+
for _ in range(100):
|
|
156
|
+
producer.send('foobar', b'some_message_bytes')
|
|
157
|
+
|
|
158
|
+
.. code-block:: python
|
|
159
|
+
|
|
160
|
+
# Block until a single message is sent (or timeout)
|
|
161
|
+
future = producer.send('foobar', b'another_message')
|
|
162
|
+
result = future.get(timeout=60)
|
|
163
|
+
|
|
164
|
+
.. code-block:: python
|
|
165
|
+
|
|
166
|
+
# Block until all pending messages are at least put on the network
|
|
167
|
+
# NOTE: This does not guarantee delivery or success! It is really
|
|
168
|
+
# only useful if you configure internal batching using linger_ms
|
|
169
|
+
producer.flush()
|
|
170
|
+
|
|
171
|
+
.. code-block:: python
|
|
172
|
+
|
|
173
|
+
# Use a key for hashed-partitioning
|
|
174
|
+
producer.send('foobar', key=b'foo', value=b'bar')
|
|
175
|
+
|
|
176
|
+
.. code-block:: python
|
|
177
|
+
|
|
178
|
+
# Serialize json messages
|
|
179
|
+
import json
|
|
180
|
+
producer = KafkaProducer(value_serializer=lambda v: json.dumps(v).encode('utf-8'))
|
|
181
|
+
producer.send('fizzbuzz', {'foo': 'bar'})
|
|
182
|
+
|
|
183
|
+
.. code-block:: python
|
|
184
|
+
|
|
185
|
+
# Serialize string keys
|
|
186
|
+
producer = KafkaProducer(key_serializer=str.encode)
|
|
187
|
+
producer.send('flipflap', key='ping', value=b'1234')
|
|
188
|
+
|
|
189
|
+
.. code-block:: python
|
|
190
|
+
|
|
191
|
+
# Compress messages
|
|
192
|
+
producer = KafkaProducer(compression_type='gzip')
|
|
193
|
+
for i in range(1000):
|
|
194
|
+
producer.send('foobar', b'msg %d' % i)
|
|
195
|
+
|
|
196
|
+
.. code-block:: python
|
|
197
|
+
|
|
198
|
+
# Include record headers. The format is list of tuples with string key
|
|
199
|
+
# and bytes value.
|
|
200
|
+
producer.send('foobar', value=b'c29tZSB2YWx1ZQ==', headers=[('content-encoding', b'base64')])
|
|
201
|
+
|
|
202
|
+
.. code-block:: python
|
|
203
|
+
|
|
204
|
+
# Get producer performance metrics
|
|
205
|
+
metrics = producer.metrics()
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
Thread safety
|
|
209
|
+
*************
|
|
210
|
+
|
|
211
|
+
The KafkaProducer can be used across threads without issue, unlike the
|
|
212
|
+
KafkaConsumer which cannot.
|
|
213
|
+
|
|
214
|
+
While it is possible to use the KafkaConsumer in a thread-local manner,
|
|
215
|
+
multiprocessing is recommended.
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
Compression
|
|
219
|
+
***********
|
|
220
|
+
|
|
221
|
+
kafka-python supports the following compression formats:
|
|
222
|
+
|
|
223
|
+
- gzip
|
|
224
|
+
- LZ4
|
|
225
|
+
- Snappy
|
|
226
|
+
- Zstandard (zstd)
|
|
227
|
+
|
|
228
|
+
gzip is supported natively, the others require installing additional libraries.
|
|
229
|
+
See https://kafka-python.readthedocs.io/en/master/install.html for more information.
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
Optimized CRC32 Validation
|
|
233
|
+
**************************
|
|
234
|
+
|
|
235
|
+
Kafka uses CRC32 checksums to validate messages. kafka-python includes a pure
|
|
236
|
+
python implementation for compatibility. To improve performance for high-throughput
|
|
237
|
+
applications, kafka-python will use `crc32c` for optimized native code if installed.
|
|
238
|
+
See https://kafka-python.readthedocs.io/en/master/install.html for installation instructions.
|
|
239
|
+
See https://pypi.org/project/crc32c/ for details on the underlying crc32c lib.
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
Protocol
|
|
243
|
+
********
|
|
244
|
+
|
|
245
|
+
A secondary goal of kafka-python is to provide an easy-to-use protocol layer
|
|
246
|
+
for interacting with kafka brokers via the python repl. This is useful for
|
|
247
|
+
testing, probing, and general experimentation. The protocol support is
|
|
248
|
+
leveraged to enable a KafkaClient.check_version() method that
|
|
249
|
+
probes a kafka broker and attempts to identify which version it is running
|
|
250
|
+
(0.8.0 to 2.6+).
|