图片解析应用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

190 lines
7.6 KiB

  1. Metadata-Version: 2.1
  2. Name: kafka-python
  3. Version: 2.0.2
  4. Summary: Pure Python client for Apache Kafka
  5. Home-page: https://github.com/dpkp/kafka-python
  6. Author: Dana Powers
  7. Author-email: dana.powers@gmail.com
  8. License: Apache License 2.0
  9. Keywords: apache kafka
  10. Platform: UNKNOWN
  11. Classifier: Development Status :: 5 - Production/Stable
  12. Classifier: Intended Audience :: Developers
  13. Classifier: License :: OSI Approved :: Apache Software License
  14. Classifier: Programming Language :: Python
  15. Classifier: Programming Language :: Python :: 2
  16. Classifier: Programming Language :: Python :: 2.7
  17. Classifier: Programming Language :: Python :: 3
  18. Classifier: Programming Language :: Python :: 3.4
  19. Classifier: Programming Language :: Python :: 3.5
  20. Classifier: Programming Language :: Python :: 3.6
  21. Classifier: Programming Language :: Python :: 3.7
  22. Classifier: Programming Language :: Python :: 3.8
  23. Classifier: Programming Language :: Python :: Implementation :: PyPy
  24. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  25. Provides-Extra: crc32c
  26. Requires-Dist: crc32c ; extra == 'crc32c'
  27. Kafka Python client
  28. ------------------------
  29. .. image:: https://img.shields.io/badge/kafka-2.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
  30. :target: https://kafka-python.readthedocs.io/en/master/compatibility.html
  31. .. image:: https://img.shields.io/pypi/pyversions/kafka-python.svg
  32. :target: https://pypi.python.org/pypi/kafka-python
  33. .. image:: https://coveralls.io/repos/dpkp/kafka-python/badge.svg?branch=master&service=github
  34. :target: https://coveralls.io/github/dpkp/kafka-python?branch=master
  35. .. image:: https://travis-ci.org/dpkp/kafka-python.svg?branch=master
  36. :target: https://travis-ci.org/dpkp/kafka-python
  37. .. image:: https://img.shields.io/badge/license-Apache%202-blue.svg
  38. :target: https://github.com/dpkp/kafka-python/blob/master/LICENSE
  39. Python client for the Apache Kafka distributed stream processing system.
  40. kafka-python is designed to function much like the official java client, with a
  41. sprinkling of pythonic interfaces (e.g., consumer iterators).
  42. kafka-python is best used with newer brokers (0.9+), but is backwards-compatible with
  43. older versions (to 0.8.0). Some features will only be enabled on newer brokers.
  44. For example, fully coordinated consumer groups -- i.e., dynamic partition
  45. assignment to multiple consumers in the same group -- requires use of 0.9+ kafka
  46. brokers. Supporting this feature for earlier broker releases would require
  47. writing and maintaining custom leadership election and membership / health
  48. check code (perhaps using zookeeper or consul). For older brokers, you can
  49. achieve something similar by manually assigning different partitions to each
  50. consumer instance with config management tools like chef, ansible, etc. This
  51. approach will work fine, though it does not support rebalancing on failures.
  52. See <https://kafka-python.readthedocs.io/en/master/compatibility.html>
  53. for more details.
  54. Please note that the master branch may contain unreleased features. For release
  55. documentation, please see readthedocs and/or python's inline help.
  56. >>> pip install kafka-python
  57. KafkaConsumer
  58. *************
  59. KafkaConsumer is a high-level message consumer, intended to operate as similarly
  60. as possible to the official java client. Full support for coordinated
  61. consumer groups requires use of kafka brokers that support the Group APIs: kafka v0.9+.
  62. See <https://kafka-python.readthedocs.io/en/master/apidoc/KafkaConsumer.html>
  63. for API and configuration details.
  64. The consumer iterator returns ConsumerRecords, which are simple namedtuples
  65. that expose basic message attributes: topic, partition, offset, key, and value:
  66. >>> from kafka import KafkaConsumer
  67. >>> consumer = KafkaConsumer('my_favorite_topic')
  68. >>> for msg in consumer:
  69. ... print (msg)
  70. >>> # join a consumer group for dynamic partition assignment and offset commits
  71. >>> from kafka import KafkaConsumer
  72. >>> consumer = KafkaConsumer('my_favorite_topic', group_id='my_favorite_group')
  73. >>> for msg in consumer:
  74. ... print (msg)
  75. >>> # manually assign the partition list for the consumer
  76. >>> from kafka import TopicPartition
  77. >>> consumer = KafkaConsumer(bootstrap_servers='localhost:1234')
  78. >>> consumer.assign([TopicPartition('foobar', 2)])
  79. >>> msg = next(consumer)
  80. >>> # Deserialize msgpack-encoded values
  81. >>> consumer = KafkaConsumer(value_deserializer=msgpack.loads)
  82. >>> consumer.subscribe(['msgpackfoo'])
  83. >>> for msg in consumer:
  84. ... assert isinstance(msg.value, dict)
  85. >>> # Access record headers. The returned value is a list of tuples
  86. >>> # with str, bytes for key and value
  87. >>> for msg in consumer:
  88. ... print (msg.headers)
  89. >>> # Get consumer metrics
  90. >>> metrics = consumer.metrics()
  91. KafkaProducer
  92. *************
  93. KafkaProducer is a high-level, asynchronous message producer. The class is
  94. intended to operate as similarly as possible to the official java client.
  95. See <https://kafka-python.readthedocs.io/en/master/apidoc/KafkaProducer.html>
  96. for more details.
  97. >>> from kafka import KafkaProducer
  98. >>> producer = KafkaProducer(bootstrap_servers='localhost:1234')
  99. >>> for _ in range(100):
  100. ... producer.send('foobar', b'some_message_bytes')
  101. >>> # Block until a single message is sent (or timeout)
  102. >>> future = producer.send('foobar', b'another_message')
  103. >>> result = future.get(timeout=60)
  104. >>> # Block until all pending messages are at least put on the network
  105. >>> # NOTE: This does not guarantee delivery or success! It is really
  106. >>> # only useful if you configure internal batching using linger_ms
  107. >>> producer.flush()
  108. >>> # Use a key for hashed-partitioning
  109. >>> producer.send('foobar', key=b'foo', value=b'bar')
  110. >>> # Serialize json messages
  111. >>> import json
  112. >>> producer = KafkaProducer(value_serializer=lambda v: json.dumps(v).encode('utf-8'))
  113. >>> producer.send('fizzbuzz', {'foo': 'bar'})
  114. >>> # Serialize string keys
  115. >>> producer = KafkaProducer(key_serializer=str.encode)
  116. >>> producer.send('flipflap', key='ping', value=b'1234')
  117. >>> # Compress messages
  118. >>> producer = KafkaProducer(compression_type='gzip')
  119. >>> for i in range(1000):
  120. ... producer.send('foobar', b'msg %d' % i)
  121. >>> # Include record headers. The format is list of tuples with string key
  122. >>> # and bytes value.
  123. >>> producer.send('foobar', value=b'c29tZSB2YWx1ZQ==', headers=[('content-encoding', b'base64')])
  124. >>> # Get producer performance metrics
  125. >>> metrics = producer.metrics()
  126. Thread safety
  127. *************
  128. The KafkaProducer can be used across threads without issue, unlike the
  129. KafkaConsumer which cannot.
  130. While it is possible to use the KafkaConsumer in a thread-local manner,
  131. multiprocessing is recommended.
  132. Compression
  133. ***********
  134. kafka-python supports gzip compression/decompression natively. To produce or consume lz4
  135. compressed messages, you should install python-lz4 (pip install lz4).
  136. To enable snappy compression/decompression install python-snappy (also requires snappy library).
  137. See <https://kafka-python.readthedocs.io/en/master/install.html#optional-snappy-install>
  138. for more information.
  139. Optimized CRC32 Validation
  140. **************************
  141. Kafka uses CRC32 checksums to validate messages. kafka-python includes a pure
  142. python implementation for compatibility. To improve performance for high-throughput
  143. applications, kafka-python will use `crc32c` for optimized native code if installed.
  144. See https://pypi.org/project/crc32c/
  145. Protocol
  146. ********
  147. A secondary goal of kafka-python is to provide an easy-to-use protocol layer
  148. for interacting with kafka brokers via the python repl. This is useful for
  149. testing, probing, and general experimentation. The protocol support is
  150. leveraged to enable a KafkaClient.check_version() method that
  151. probes a kafka broker and attempts to identify which version it is running
  152. (0.8.0 to 2.4+).