kafka-python 3.0.0__py3-none-any.whl

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.
Files changed (373) hide show
  1. kafka/__init__.py +34 -0
  2. kafka/__main__.py +5 -0
  3. kafka/admin/__init__.py +29 -0
  4. kafka/admin/__main__.py +5 -0
  5. kafka/admin/_acls.py +355 -0
  6. kafka/admin/_cluster.py +359 -0
  7. kafka/admin/_configs.py +479 -0
  8. kafka/admin/_groups.py +754 -0
  9. kafka/admin/_partitions.py +595 -0
  10. kafka/admin/_topics.py +281 -0
  11. kafka/admin/_transactions.py +450 -0
  12. kafka/admin/_users.py +194 -0
  13. kafka/admin/client.py +373 -0
  14. kafka/benchmarks/__init__.py +0 -0
  15. kafka/benchmarks/consumer_performance.py +138 -0
  16. kafka/benchmarks/load_example.py +109 -0
  17. kafka/benchmarks/producer_encode_path.py +201 -0
  18. kafka/benchmarks/producer_performance.py +161 -0
  19. kafka/benchmarks/profile_protocol.py +138 -0
  20. kafka/benchmarks/protocol_old_vs_new.py +447 -0
  21. kafka/benchmarks/record_batch_compose.py +77 -0
  22. kafka/benchmarks/record_batch_read.py +82 -0
  23. kafka/benchmarks/varint_speed.py +426 -0
  24. kafka/cli/__init__.py +36 -0
  25. kafka/cli/admin/__init__.py +117 -0
  26. kafka/cli/admin/acls/__init__.py +9 -0
  27. kafka/cli/admin/acls/common.py +76 -0
  28. kafka/cli/admin/acls/create.py +19 -0
  29. kafka/cli/admin/acls/delete.py +23 -0
  30. kafka/cli/admin/acls/describe.py +16 -0
  31. kafka/cli/admin/cluster/__init__.py +14 -0
  32. kafka/cli/admin/cluster/describe.py +11 -0
  33. kafka/cli/admin/cluster/describe_quorum.py +11 -0
  34. kafka/cli/admin/cluster/features.py +52 -0
  35. kafka/cli/admin/cluster/log_dirs.py +43 -0
  36. kafka/cli/admin/cluster/versions.py +33 -0
  37. kafka/cli/admin/configs/__init__.py +10 -0
  38. kafka/cli/admin/configs/alter.py +43 -0
  39. kafka/cli/admin/configs/common.py +17 -0
  40. kafka/cli/admin/configs/describe.py +30 -0
  41. kafka/cli/admin/configs/list.py +16 -0
  42. kafka/cli/admin/configs/reset.py +20 -0
  43. kafka/cli/admin/groups/__init__.py +16 -0
  44. kafka/cli/admin/groups/alter_offsets.py +30 -0
  45. kafka/cli/admin/groups/delete.py +11 -0
  46. kafka/cli/admin/groups/delete_offsets.py +29 -0
  47. kafka/cli/admin/groups/describe.py +11 -0
  48. kafka/cli/admin/groups/list.py +28 -0
  49. kafka/cli/admin/groups/list_offsets.py +29 -0
  50. kafka/cli/admin/groups/remove_members.py +40 -0
  51. kafka/cli/admin/groups/reset_offsets.py +139 -0
  52. kafka/cli/admin/partitions/__init__.py +21 -0
  53. kafka/cli/admin/partitions/alter_reassignments.py +37 -0
  54. kafka/cli/admin/partitions/create.py +27 -0
  55. kafka/cli/admin/partitions/delete_records.py +31 -0
  56. kafka/cli/admin/partitions/describe.py +36 -0
  57. kafka/cli/admin/partitions/elect_leaders.py +53 -0
  58. kafka/cli/admin/partitions/list_offsets.py +88 -0
  59. kafka/cli/admin/partitions/list_reassignments.py +35 -0
  60. kafka/cli/admin/topics/__init__.py +10 -0
  61. kafka/cli/admin/topics/create.py +13 -0
  62. kafka/cli/admin/topics/delete.py +19 -0
  63. kafka/cli/admin/topics/describe.py +18 -0
  64. kafka/cli/admin/topics/list.py +11 -0
  65. kafka/cli/admin/transactions/__init__.py +17 -0
  66. kafka/cli/admin/transactions/abort.py +38 -0
  67. kafka/cli/admin/transactions/describe.py +24 -0
  68. kafka/cli/admin/transactions/describe_producers.py +29 -0
  69. kafka/cli/admin/transactions/find_hanging.py +26 -0
  70. kafka/cli/admin/transactions/list.py +37 -0
  71. kafka/cli/admin/users/__init__.py +8 -0
  72. kafka/cli/admin/users/alter_user_scram_credentials.py +34 -0
  73. kafka/cli/admin/users/describe_user_scram_credentials.py +15 -0
  74. kafka/cli/common.py +95 -0
  75. kafka/cli/consumer/__init__.py +63 -0
  76. kafka/cli/producer/__init__.py +57 -0
  77. kafka/cluster.py +824 -0
  78. kafka/codec.py +325 -0
  79. kafka/consumer/__init__.py +5 -0
  80. kafka/consumer/__main__.py +5 -0
  81. kafka/consumer/fetcher.py +2012 -0
  82. kafka/consumer/group.py +1347 -0
  83. kafka/consumer/subscription_state.py +897 -0
  84. kafka/coordinator/__init__.py +0 -0
  85. kafka/coordinator/assignors/__init__.py +0 -0
  86. kafka/coordinator/assignors/abstract.py +90 -0
  87. kafka/coordinator/assignors/cooperative_sticky.py +167 -0
  88. kafka/coordinator/assignors/range.py +81 -0
  89. kafka/coordinator/assignors/roundrobin.py +101 -0
  90. kafka/coordinator/assignors/sticky/StickyAssignorUserData.json +37 -0
  91. kafka/coordinator/assignors/sticky/__init__.py +0 -0
  92. kafka/coordinator/assignors/sticky/partition_movements.py +149 -0
  93. kafka/coordinator/assignors/sticky/sorted_set.py +63 -0
  94. kafka/coordinator/assignors/sticky/sticky_assignor.py +665 -0
  95. kafka/coordinator/assignors/sticky/user_data.py +8 -0
  96. kafka/coordinator/base.py +1215 -0
  97. kafka/coordinator/consumer.py +1224 -0
  98. kafka/coordinator/heartbeat.py +82 -0
  99. kafka/coordinator/subscription.py +34 -0
  100. kafka/errors.py +1004 -0
  101. kafka/future.py +166 -0
  102. kafka/metrics/__init__.py +13 -0
  103. kafka/metrics/compound_stat.py +33 -0
  104. kafka/metrics/dict_reporter.py +81 -0
  105. kafka/metrics/kafka_metric.py +36 -0
  106. kafka/metrics/measurable.py +27 -0
  107. kafka/metrics/measurable_stat.py +13 -0
  108. kafka/metrics/metric_config.py +33 -0
  109. kafka/metrics/metric_name.py +105 -0
  110. kafka/metrics/metrics.py +261 -0
  111. kafka/metrics/metrics_reporter.py +53 -0
  112. kafka/metrics/quota.py +41 -0
  113. kafka/metrics/stat.py +19 -0
  114. kafka/metrics/stats/__init__.py +15 -0
  115. kafka/metrics/stats/avg.py +24 -0
  116. kafka/metrics/stats/count.py +17 -0
  117. kafka/metrics/stats/histogram.py +99 -0
  118. kafka/metrics/stats/max_stat.py +17 -0
  119. kafka/metrics/stats/min_stat.py +19 -0
  120. kafka/metrics/stats/percentile.py +14 -0
  121. kafka/metrics/stats/percentiles.py +75 -0
  122. kafka/metrics/stats/rate.py +118 -0
  123. kafka/metrics/stats/sampled_stat.py +99 -0
  124. kafka/metrics/stats/sensor.py +136 -0
  125. kafka/metrics/stats/total.py +15 -0
  126. kafka/net/__init__.py +19 -0
  127. kafka/net/compat.py +165 -0
  128. kafka/net/connection.py +593 -0
  129. kafka/net/http_connect.py +144 -0
  130. kafka/net/inet.py +122 -0
  131. kafka/net/manager.py +451 -0
  132. kafka/net/metrics.py +149 -0
  133. kafka/net/sasl/__init__.py +32 -0
  134. kafka/net/sasl/abc.py +28 -0
  135. kafka/net/sasl/gssapi.py +95 -0
  136. kafka/net/sasl/msk.py +245 -0
  137. kafka/net/sasl/oauth.py +98 -0
  138. kafka/net/sasl/plain.py +42 -0
  139. kafka/net/sasl/scram.py +135 -0
  140. kafka/net/sasl/sspi.py +111 -0
  141. kafka/net/selector.py +644 -0
  142. kafka/net/socks5.py +262 -0
  143. kafka/net/transport.py +415 -0
  144. kafka/net/wakeup_notifier.py +72 -0
  145. kafka/partitioner/__init__.py +8 -0
  146. kafka/partitioner/abc.py +8 -0
  147. kafka/partitioner/default.py +89 -0
  148. kafka/partitioner/sticky.py +109 -0
  149. kafka/producer/__init__.py +5 -0
  150. kafka/producer/__main__.py +5 -0
  151. kafka/producer/future.py +101 -0
  152. kafka/producer/kafka.py +1123 -0
  153. kafka/producer/producer_batch.py +192 -0
  154. kafka/producer/record_accumulator.py +647 -0
  155. kafka/producer/sender.py +884 -0
  156. kafka/producer/transaction_manager.py +1326 -0
  157. kafka/protocol/__init__.py +0 -0
  158. kafka/protocol/admin/__init__.py +29 -0
  159. kafka/protocol/admin/acl.py +83 -0
  160. kafka/protocol/admin/acl.pyi +375 -0
  161. kafka/protocol/admin/client_quotas.py +14 -0
  162. kafka/protocol/admin/client_quotas.pyi +265 -0
  163. kafka/protocol/admin/cluster.py +31 -0
  164. kafka/protocol/admin/cluster.pyi +620 -0
  165. kafka/protocol/admin/configs.py +22 -0
  166. kafka/protocol/admin/configs.pyi +437 -0
  167. kafka/protocol/admin/groups.py +24 -0
  168. kafka/protocol/admin/groups.pyi +261 -0
  169. kafka/protocol/admin/topics.py +53 -0
  170. kafka/protocol/admin/topics.pyi +982 -0
  171. kafka/protocol/admin/transactions.py +18 -0
  172. kafka/protocol/admin/transactions.pyi +311 -0
  173. kafka/protocol/admin/users.py +14 -0
  174. kafka/protocol/admin/users.pyi +223 -0
  175. kafka/protocol/api_data.py +125 -0
  176. kafka/protocol/api_header.py +55 -0
  177. kafka/protocol/api_key.py +97 -0
  178. kafka/protocol/api_message.py +277 -0
  179. kafka/protocol/broker_version_data.py +246 -0
  180. kafka/protocol/consumer/__init__.py +13 -0
  181. kafka/protocol/consumer/fetch.py +16 -0
  182. kafka/protocol/consumer/fetch.pyi +298 -0
  183. kafka/protocol/consumer/group.py +38 -0
  184. kafka/protocol/consumer/group.pyi +824 -0
  185. kafka/protocol/consumer/metadata.py +30 -0
  186. kafka/protocol/consumer/metadata.pyi +89 -0
  187. kafka/protocol/consumer/offsets.py +75 -0
  188. kafka/protocol/consumer/offsets.pyi +288 -0
  189. kafka/protocol/data_container.py +166 -0
  190. kafka/protocol/frame.py +30 -0
  191. kafka/protocol/generate_stubs.py +468 -0
  192. kafka/protocol/metadata/__init__.py +10 -0
  193. kafka/protocol/metadata/api_versions.py +41 -0
  194. kafka/protocol/metadata/api_versions.pyi +128 -0
  195. kafka/protocol/metadata/find_coordinator.py +19 -0
  196. kafka/protocol/metadata/find_coordinator.pyi +105 -0
  197. kafka/protocol/metadata/metadata.py +34 -0
  198. kafka/protocol/metadata/metadata.pyi +160 -0
  199. kafka/protocol/old/__init__.py +0 -0
  200. kafka/protocol/old/abstract.py +17 -0
  201. kafka/protocol/old/add_offsets_to_txn.py +54 -0
  202. kafka/protocol/old/add_partitions_to_txn.py +71 -0
  203. kafka/protocol/old/admin.py +1086 -0
  204. kafka/protocol/old/api.py +205 -0
  205. kafka/protocol/old/api_versions.py +133 -0
  206. kafka/protocol/old/commit.py +355 -0
  207. kafka/protocol/old/consumer_protocol.py +36 -0
  208. kafka/protocol/old/end_txn.py +53 -0
  209. kafka/protocol/old/fetch.py +408 -0
  210. kafka/protocol/old/find_coordinator.py +72 -0
  211. kafka/protocol/old/group.py +451 -0
  212. kafka/protocol/old/init_producer_id.py +42 -0
  213. kafka/protocol/old/list_offsets.py +186 -0
  214. kafka/protocol/old/metadata.py +290 -0
  215. kafka/protocol/old/offset_for_leader_epoch.py +133 -0
  216. kafka/protocol/old/produce.py +247 -0
  217. kafka/protocol/old/sasl_authenticate.py +38 -0
  218. kafka/protocol/old/sasl_handshake.py +39 -0
  219. kafka/protocol/old/struct.py +87 -0
  220. kafka/protocol/old/txn_offset_commit.py +73 -0
  221. kafka/protocol/old/types.py +440 -0
  222. kafka/protocol/parser.py +191 -0
  223. kafka/protocol/producer/__init__.py +7 -0
  224. kafka/protocol/producer/produce.py +17 -0
  225. kafka/protocol/producer/produce.pyi +197 -0
  226. kafka/protocol/producer/transaction.py +30 -0
  227. kafka/protocol/producer/transaction.pyi +663 -0
  228. kafka/protocol/sasl.py +52 -0
  229. kafka/protocol/sasl.pyi +126 -0
  230. kafka/protocol/schemas/__init__.py +7 -0
  231. kafka/protocol/schemas/fields/__init__.py +7 -0
  232. kafka/protocol/schemas/fields/array.py +127 -0
  233. kafka/protocol/schemas/fields/base.py +156 -0
  234. kafka/protocol/schemas/fields/codecs/__init__.py +12 -0
  235. kafka/protocol/schemas/fields/codecs/encode_buffer.py +82 -0
  236. kafka/protocol/schemas/fields/codecs/tagged_fields.py +109 -0
  237. kafka/protocol/schemas/fields/codecs/types.py +505 -0
  238. kafka/protocol/schemas/fields/codegen.py +40 -0
  239. kafka/protocol/schemas/fields/simple.py +127 -0
  240. kafka/protocol/schemas/fields/struct.py +357 -0
  241. kafka/protocol/schemas/fields/struct_array.py +142 -0
  242. kafka/protocol/schemas/load_json.py +42 -0
  243. kafka/protocol/schemas/resources/AddOffsetsToTxnRequest.json +40 -0
  244. kafka/protocol/schemas/resources/AddOffsetsToTxnResponse.json +35 -0
  245. kafka/protocol/schemas/resources/AddPartitionsToTxnRequest.json +65 -0
  246. kafka/protocol/schemas/resources/AddPartitionsToTxnResponse.json +60 -0
  247. kafka/protocol/schemas/resources/AlterClientQuotasRequest.json +47 -0
  248. kafka/protocol/schemas/resources/AlterClientQuotasResponse.json +41 -0
  249. kafka/protocol/schemas/resources/AlterConfigsRequest.json +43 -0
  250. kafka/protocol/schemas/resources/AlterConfigsResponse.json +39 -0
  251. kafka/protocol/schemas/resources/AlterPartitionReassignmentsRequest.json +42 -0
  252. kafka/protocol/schemas/resources/AlterPartitionReassignmentsResponse.json +47 -0
  253. kafka/protocol/schemas/resources/AlterReplicaLogDirsRequest.json +41 -0
  254. kafka/protocol/schemas/resources/AlterReplicaLogDirsResponse.json +41 -0
  255. kafka/protocol/schemas/resources/AlterUserScramCredentialsRequest.json +45 -0
  256. kafka/protocol/schemas/resources/AlterUserScramCredentialsResponse.json +35 -0
  257. kafka/protocol/schemas/resources/ApiVersionsRequest.json +34 -0
  258. kafka/protocol/schemas/resources/ApiVersionsResponse.json +79 -0
  259. kafka/protocol/schemas/resources/ConsumerProtocolAssignment.json +42 -0
  260. kafka/protocol/schemas/resources/ConsumerProtocolSubscription.json +49 -0
  261. kafka/protocol/schemas/resources/CreateAclsRequest.json +46 -0
  262. kafka/protocol/schemas/resources/CreateAclsResponse.json +37 -0
  263. kafka/protocol/schemas/resources/CreatePartitionsRequest.json +47 -0
  264. kafka/protocol/schemas/resources/CreatePartitionsResponse.json +41 -0
  265. kafka/protocol/schemas/resources/CreateTopicsRequest.json +65 -0
  266. kafka/protocol/schemas/resources/CreateTopicsResponse.json +72 -0
  267. kafka/protocol/schemas/resources/DeleteAclsRequest.json +46 -0
  268. kafka/protocol/schemas/resources/DeleteAclsResponse.json +59 -0
  269. kafka/protocol/schemas/resources/DeleteGroupsRequest.json +30 -0
  270. kafka/protocol/schemas/resources/DeleteGroupsResponse.json +36 -0
  271. kafka/protocol/schemas/resources/DeleteRecordsRequest.json +42 -0
  272. kafka/protocol/schemas/resources/DeleteRecordsResponse.json +43 -0
  273. kafka/protocol/schemas/resources/DeleteTopicsRequest.json +43 -0
  274. kafka/protocol/schemas/resources/DeleteTopicsResponse.json +52 -0
  275. kafka/protocol/schemas/resources/DescribeAclsRequest.json +43 -0
  276. kafka/protocol/schemas/resources/DescribeAclsResponse.json +55 -0
  277. kafka/protocol/schemas/resources/DescribeClientQuotasRequest.json +37 -0
  278. kafka/protocol/schemas/resources/DescribeClientQuotasResponse.json +47 -0
  279. kafka/protocol/schemas/resources/DescribeClusterRequest.json +35 -0
  280. kafka/protocol/schemas/resources/DescribeClusterResponse.json +56 -0
  281. kafka/protocol/schemas/resources/DescribeConfigsRequest.json +42 -0
  282. kafka/protocol/schemas/resources/DescribeConfigsResponse.json +69 -0
  283. kafka/protocol/schemas/resources/DescribeGroupsRequest.json +38 -0
  284. kafka/protocol/schemas/resources/DescribeGroupsResponse.json +74 -0
  285. kafka/protocol/schemas/resources/DescribeLogDirsRequest.json +38 -0
  286. kafka/protocol/schemas/resources/DescribeLogDirsResponse.json +65 -0
  287. kafka/protocol/schemas/resources/DescribeProducersRequest.json +32 -0
  288. kafka/protocol/schemas/resources/DescribeProducersResponse.json +55 -0
  289. kafka/protocol/schemas/resources/DescribeQuorumRequest.json +39 -0
  290. kafka/protocol/schemas/resources/DescribeQuorumResponse.json +82 -0
  291. kafka/protocol/schemas/resources/DescribeTopicPartitionsRequest.json +40 -0
  292. kafka/protocol/schemas/resources/DescribeTopicPartitionsResponse.json +66 -0
  293. kafka/protocol/schemas/resources/DescribeTransactionsRequest.json +27 -0
  294. kafka/protocol/schemas/resources/DescribeTransactionsResponse.json +52 -0
  295. kafka/protocol/schemas/resources/DescribeUserScramCredentialsRequest.json +30 -0
  296. kafka/protocol/schemas/resources/DescribeUserScramCredentialsResponse.json +45 -0
  297. kafka/protocol/schemas/resources/ElectLeadersRequest.json +41 -0
  298. kafka/protocol/schemas/resources/ElectLeadersResponse.json +45 -0
  299. kafka/protocol/schemas/resources/EndTxnRequest.json +43 -0
  300. kafka/protocol/schemas/resources/EndTxnResponse.json +41 -0
  301. kafka/protocol/schemas/resources/FetchRequest.json +125 -0
  302. kafka/protocol/schemas/resources/FetchResponse.json +124 -0
  303. kafka/protocol/schemas/resources/FindCoordinatorRequest.json +43 -0
  304. kafka/protocol/schemas/resources/FindCoordinatorResponse.json +58 -0
  305. kafka/protocol/schemas/resources/HeartbeatRequest.json +39 -0
  306. kafka/protocol/schemas/resources/HeartbeatResponse.json +35 -0
  307. kafka/protocol/schemas/resources/IncrementalAlterConfigsRequest.json +44 -0
  308. kafka/protocol/schemas/resources/IncrementalAlterConfigsResponse.json +38 -0
  309. kafka/protocol/schemas/resources/InitProducerIdRequest.json +50 -0
  310. kafka/protocol/schemas/resources/InitProducerIdResponse.json +47 -0
  311. kafka/protocol/schemas/resources/JoinGroupRequest.json +63 -0
  312. kafka/protocol/schemas/resources/JoinGroupResponse.json +69 -0
  313. kafka/protocol/schemas/resources/LeaveGroupRequest.json +47 -0
  314. kafka/protocol/schemas/resources/LeaveGroupResponse.json +47 -0
  315. kafka/protocol/schemas/resources/ListConfigResourcesRequest.json +31 -0
  316. kafka/protocol/schemas/resources/ListConfigResourcesResponse.json +37 -0
  317. kafka/protocol/schemas/resources/ListGroupsRequest.json +36 -0
  318. kafka/protocol/schemas/resources/ListGroupsResponse.json +49 -0
  319. kafka/protocol/schemas/resources/ListOffsetsRequest.json +72 -0
  320. kafka/protocol/schemas/resources/ListOffsetsResponse.json +71 -0
  321. kafka/protocol/schemas/resources/ListPartitionReassignmentsRequest.json +34 -0
  322. kafka/protocol/schemas/resources/ListPartitionReassignmentsResponse.json +46 -0
  323. kafka/protocol/schemas/resources/ListTransactionsRequest.json +40 -0
  324. kafka/protocol/schemas/resources/ListTransactionsResponse.json +42 -0
  325. kafka/protocol/schemas/resources/MetadataRequest.json +56 -0
  326. kafka/protocol/schemas/resources/MetadataResponse.json +101 -0
  327. kafka/protocol/schemas/resources/OffsetCommitRequest.json +76 -0
  328. kafka/protocol/schemas/resources/OffsetCommitResponse.json +71 -0
  329. kafka/protocol/schemas/resources/OffsetDeleteRequest.json +39 -0
  330. kafka/protocol/schemas/resources/OffsetDeleteResponse.json +42 -0
  331. kafka/protocol/schemas/resources/OffsetFetchRequest.json +76 -0
  332. kafka/protocol/schemas/resources/OffsetFetchResponse.json +107 -0
  333. kafka/protocol/schemas/resources/OffsetForLeaderEpochRequest.json +52 -0
  334. kafka/protocol/schemas/resources/OffsetForLeaderEpochResponse.json +51 -0
  335. kafka/protocol/schemas/resources/ProduceRequest.json +73 -0
  336. kafka/protocol/schemas/resources/ProduceResponse.json +96 -0
  337. kafka/protocol/schemas/resources/RequestHeader.json +44 -0
  338. kafka/protocol/schemas/resources/ResponseHeader.json +26 -0
  339. kafka/protocol/schemas/resources/SaslAuthenticateRequest.json +29 -0
  340. kafka/protocol/schemas/resources/SaslAuthenticateResponse.json +34 -0
  341. kafka/protocol/schemas/resources/SaslHandshakeRequest.json +31 -0
  342. kafka/protocol/schemas/resources/SaslHandshakeResponse.json +32 -0
  343. kafka/protocol/schemas/resources/SyncGroupRequest.json +56 -0
  344. kafka/protocol/schemas/resources/SyncGroupResponse.json +46 -0
  345. kafka/protocol/schemas/resources/TxnOffsetCommitRequest.json +68 -0
  346. kafka/protocol/schemas/resources/TxnOffsetCommitResponse.json +47 -0
  347. kafka/protocol/schemas/resources/UpdateFeaturesRequest.json +43 -0
  348. kafka/protocol/schemas/resources/UpdateFeaturesResponse.json +39 -0
  349. kafka/protocol/schemas/resources/WriteTxnMarkersRequest.json +49 -0
  350. kafka/protocol/schemas/resources/WriteTxnMarkersResponse.json +45 -0
  351. kafka/protocol/schemas/resources/__init__.py +0 -0
  352. kafka/record/__init__.py +3 -0
  353. kafka/record/_crc32c.py +161 -0
  354. kafka/record/abc.py +144 -0
  355. kafka/record/default_records.py +782 -0
  356. kafka/record/legacy_records.py +587 -0
  357. kafka/record/memory_records.py +255 -0
  358. kafka/record/util.py +135 -0
  359. kafka/serializer/__init__.py +4 -0
  360. kafka/serializer/abstract.py +20 -0
  361. kafka/serializer/default.py +16 -0
  362. kafka/serializer/json.py +17 -0
  363. kafka/serializer/wrapper.py +21 -0
  364. kafka/structs.py +69 -0
  365. kafka/util.py +159 -0
  366. kafka/vendor/__init__.py +0 -0
  367. kafka/version.py +1 -0
  368. kafka_python-3.0.0.dist-info/METADATA +319 -0
  369. kafka_python-3.0.0.dist-info/RECORD +373 -0
  370. kafka_python-3.0.0.dist-info/WHEEL +5 -0
  371. kafka_python-3.0.0.dist-info/entry_points.txt +2 -0
  372. kafka_python-3.0.0.dist-info/licenses/LICENSE +202 -0
  373. kafka_python-3.0.0.dist-info/top_level.txt +1 -0
kafka/util.py ADDED
@@ -0,0 +1,159 @@
1
+ import binascii
2
+ import functools
3
+ import re
4
+ import time
5
+ import weakref
6
+
7
+ from kafka.errors import KafkaTimeoutError
8
+
9
+
10
+ class Timer:
11
+ __slots__ = ('_start_at', '_expire_at', '_timeout_ms', '_error_message')
12
+
13
+ def __init__(self, timeout_ms, error_message=None, start_at=None):
14
+ self._timeout_ms = timeout_ms
15
+ self._start_at = start_at or time.monotonic()
16
+ if timeout_ms is not None:
17
+ self._expire_at = self._start_at + timeout_ms / 1000
18
+ else:
19
+ self._expire_at = float('inf')
20
+ self._error_message = error_message
21
+
22
+ @property
23
+ def expired(self):
24
+ return time.monotonic() >= self._expire_at
25
+
26
+ @property
27
+ def timeout_ms(self):
28
+ if self._timeout_ms is None:
29
+ return None
30
+ elif self._expire_at == float('inf'):
31
+ return float('inf')
32
+ remaining = self._expire_at - time.monotonic()
33
+ if remaining < 0:
34
+ return 0
35
+ else:
36
+ return int(remaining * 1000)
37
+
38
+ @property
39
+ def timeout_secs(self):
40
+ timeout_ms = self.timeout_ms
41
+ return timeout_ms / 1000 if timeout_ms is not None else None
42
+
43
+ @property
44
+ def elapsed_ms(self):
45
+ return int(1000 * (time.monotonic() - self._start_at))
46
+
47
+ def maybe_raise(self):
48
+ if self.expired:
49
+ raise KafkaTimeoutError(self._error_message)
50
+
51
+ def __str__(self):
52
+ return "Timer(%s ms remaining)" % (self.timeout_ms)
53
+
54
+ # Taken from: https://github.com/apache/kafka/blob/39eb31feaeebfb184d98cc5d94da9148c2319d81/clients/src/main/java/org/apache/kafka/common/internals/Topic.java#L29
55
+ TOPIC_MAX_LENGTH = 249
56
+ TOPIC_LEGAL_CHARS = re.compile('^[a-zA-Z0-9._-]+$')
57
+
58
+ def ensure_valid_topic_name(topic):
59
+ """ Ensures that the topic name is valid according to the kafka source. """
60
+
61
+ # See Kafka Source:
62
+ # https://github.com/apache/kafka/blob/39eb31feaeebfb184d98cc5d94da9148c2319d81/clients/src/main/java/org/apache/kafka/common/internals/Topic.java
63
+ if topic is None:
64
+ raise TypeError('All topics must not be None')
65
+ if not isinstance(topic, str):
66
+ raise TypeError('All topics must be strings')
67
+ if len(topic) == 0:
68
+ raise ValueError('All topics must be non-empty strings')
69
+ if topic == '.' or topic == '..':
70
+ raise ValueError('Topic name cannot be "." or ".."')
71
+ if len(topic) > TOPIC_MAX_LENGTH:
72
+ raise ValueError('Topic name is illegal, it can\'t be longer than {0} characters, topic: "{1}"'.format(TOPIC_MAX_LENGTH, topic))
73
+ if not TOPIC_LEGAL_CHARS.match(topic):
74
+ raise ValueError('Topic name "{0}" is illegal, it contains a character other than ASCII alphanumerics, ".", "_" and "-"'.format(topic))
75
+
76
+
77
+ class WeakMethod:
78
+ """
79
+ Callable that weakly references a method and the object it is bound to. It
80
+ is based on https://stackoverflow.com/a/24287465.
81
+
82
+ Arguments:
83
+
84
+ object_dot_method: A bound instance method (i.e. 'object.method').
85
+ """
86
+ def __init__(self, object_dot_method):
87
+ try:
88
+ self.target = weakref.ref(object_dot_method.__self__)
89
+ except AttributeError:
90
+ self.target = weakref.ref(object_dot_method.im_self)
91
+ self._target_id = id(self.target())
92
+ try:
93
+ self.method = weakref.ref(object_dot_method.__func__)
94
+ except AttributeError:
95
+ self.method = weakref.ref(object_dot_method.im_func)
96
+ self._method_id = id(self.method())
97
+
98
+ def __call__(self, *args, **kwargs):
99
+ """
100
+ Calls the method on target with args and kwargs.
101
+ """
102
+ return self.method()(self.target(), *args, **kwargs)
103
+
104
+ def __hash__(self):
105
+ return hash(self.target) ^ hash(self.method)
106
+
107
+ def __eq__(self, other):
108
+ if not isinstance(other, WeakMethod):
109
+ return False
110
+ return self._target_id == other._target_id and self._method_id == other._method_id
111
+
112
+
113
+ class Dict(dict):
114
+ """Utility class to support passing weakrefs to dicts
115
+
116
+ See: https://docs.python.org/2/library/weakref.html
117
+ """
118
+ pass
119
+
120
+
121
+ def synchronized(func):
122
+ def wrapper(self, *args, **kwargs):
123
+ with self._lock:
124
+ return func(self, *args, **kwargs)
125
+ functools.update_wrapper(wrapper, func)
126
+ return wrapper
127
+
128
+
129
+ class classproperty:
130
+ def __init__(self, f):
131
+ self.f = f
132
+ def __get__(self, obj, owner):
133
+ return self.f(owner)
134
+
135
+
136
+ class EnumHelper:
137
+ @classmethod
138
+ def build_from(cls, val):
139
+ if isinstance(val, cls):
140
+ return val
141
+ try:
142
+ return cls(val)
143
+ except ValueError:
144
+ pass
145
+ try:
146
+ return cls[str(val).strip().upper().replace('-', '_')] # pylint: disable=E1136
147
+ except KeyError:
148
+ raise ValueError(f'Unrecognized {cls.__name__}: {val}') from None
149
+
150
+ @classmethod
151
+ def value_for(cls, val):
152
+ if isinstance(val, cls):
153
+ return val.value
154
+ if isinstance(val, int):
155
+ return cls(val).value # pylint: disable=E1101
156
+ try:
157
+ return cls[str(val).upper().replace('-', '_')].value # pylint: disable=E1136
158
+ except KeyError:
159
+ raise ValueError(f'Unrecognized {cls.__name__}: {val}') from None
File without changes
kafka/version.py ADDED
@@ -0,0 +1 @@
1
+ __version__ = '3.0.0'
@@ -0,0 +1,319 @@
1
+ Metadata-Version: 2.4
2
+ Name: kafka-python
3
+ Version: 3.0.0
4
+ Summary: Pure Python client for Apache Kafka
5
+ Author-email: Dana Powers <dana.powers@gmail.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/dpkp/kafka-python
8
+ Project-URL: Documentation, https://kafka-python.readthedocs.io
9
+ Project-URL: Repository, https://github.com/dpkp/kafka-python
10
+ Project-URL: Issues, https://github.com/dpkp/kafka-python/issues
11
+ Project-URL: Changelog, https://github.com/dpkp/kafka-python/blob/master/CHANGES.md
12
+ Keywords: apache kafka,kafka
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Programming Language :: Python
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Programming Language :: Python :: 3.14
24
+ Classifier: Programming Language :: Python :: Implementation :: CPython
25
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
26
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
27
+ Requires-Python: >=3.8
28
+ Description-Content-Type: text/x-rst
29
+ License-File: LICENSE
30
+ Provides-Extra: crc32c
31
+ Requires-Dist: crc32c; extra == "crc32c"
32
+ Provides-Extra: lz4
33
+ Requires-Dist: lz4; extra == "lz4"
34
+ Provides-Extra: snappy
35
+ Requires-Dist: python-snappy; extra == "snappy"
36
+ Provides-Extra: zstd
37
+ Requires-Dist: zstandard; extra == "zstd"
38
+ Provides-Extra: testing
39
+ Requires-Dist: pytest; extra == "testing"
40
+ Requires-Dist: pytest-mock; extra == "testing"
41
+ Requires-Dist: pytest-timeout; extra == "testing"
42
+ Provides-Extra: benchmarks
43
+ Requires-Dist: pyperf; extra == "benchmarks"
44
+ Dynamic: license-file
45
+
46
+ kafka-python
47
+ ############
48
+
49
+ .. image:: https://img.shields.io/pypi/v/kafka-python.svg
50
+ :target: https://pypi.org/project/kafka-python
51
+ .. image:: https://img.shields.io/badge/kafka-4.3--0.8-brightgreen.svg
52
+ :target: https://kafka-python.readthedocs.io/en/master/compatibility.html
53
+
54
+ .. image:: https://img.shields.io/badge/license-Apache%202-blue.svg
55
+ :target: https://github.com/dpkp/kafka-python/blob/master/LICENSE
56
+ .. image:: https://img.shields.io/pypi/pyversions/kafka-python.svg
57
+ :target: https://pypi.python.org/pypi/kafka-python
58
+
59
+
60
+ kafka-python is a pure-python client library for Apache Kafka, the distributed
61
+ stream processing engine. It has no external dependencies and no Cython/C/rust
62
+ core, making installation across a wide variety of environments simple and easy
63
+ to manage. It provides high-level class components for consumer, producer, and
64
+ admin clients, as well as CLI scripts for quick interactive tasks.
65
+
66
+ ``kafka-python admin`` serves as a simple alternative to the apache kafka bin/
67
+ scripts, particularly if/when you do not have easy access to an
68
+ installed/compatible jvm. The CLI interface for admin commands is provided as
69
+ ``kafka-python admin`` and ``python -m kafka.admin``.
70
+
71
+ Users looking to add more raw throughput can ``pip install crc32c`` as
72
+ an optional dependency, offloading one of the most CPU intensive subsystems
73
+ to an optimized C library.
74
+
75
+
76
+ .. code-block:: bash
77
+
78
+ pip install kafka-python
79
+
80
+ # callable as module or as cli-script
81
+ kafka-python admin -b localhost:9092 cluster describe
82
+
83
+ # Create a topic with the admin cli
84
+ python -m kafka.admin -b localhost:9092 topics create -t foo-topic
85
+
86
+ # Produce messages
87
+ echo "foo message" | python -m kafka.producer -b localhost:9092 -t foo-topic
88
+
89
+ # Consume messages
90
+ python -m kafka.consumer -b localhost:9092 -C auto_offset_reset=earliest -C consumer_timeout_ms=1000 -g foo-group -t foo-topic
91
+
92
+
93
+ What's New in 3.0
94
+ *****************
95
+
96
+ - Protocol Stack dynamically generated from Apache Kafka json message schemas.
97
+ - Encode/decode performance optimizations with compiled/cached python bytecode.
98
+ - Expanded KIP feature support, including Cooperative Rebalance (KIP-429),
99
+ Rack-aware Fetch (KIP-392), Log-Truncation detection (KIP-320), Transactional
100
+ Producer improvements (KIP-360, KIP-447, KIP-654), Sticky Partitioner (KIP-480),
101
+ and splittting oversized producer batches (KIP-126).
102
+ - Full refactor and expansion of KafkaAdminClient.
103
+ - Networking changes to leverage kafka.net event-loop and async/await syntax.
104
+ - Python 3.8+ required
105
+
106
+ KafkaConsumer
107
+ *************
108
+
109
+ KafkaConsumer is a high-level message consumer, intended to operate as similarly
110
+ as possible to the official java client.
111
+ See https://kafka-python.readthedocs.io/en/master/apidoc/KafkaConsumer.html
112
+ for API and configuration details.
113
+
114
+ The consumer iterator returns ConsumerRecords, which are simple namedtuples
115
+ that expose basic message attributes: topic, partition, offset, key, and value:
116
+
117
+ .. code-block:: python
118
+
119
+ from kafka import KafkaConsumer
120
+ consumer = KafkaConsumer('my_favorite_topic')
121
+ for msg in consumer:
122
+ print (msg)
123
+
124
+ .. code-block:: python
125
+
126
+ # join a consumer group for dynamic partition assignment and offset commits
127
+ from kafka import KafkaConsumer
128
+ consumer = KafkaConsumer('my_favorite_topic', group_id='my_favorite_group')
129
+ for msg in consumer:
130
+ print (msg)
131
+
132
+ .. code-block:: python
133
+
134
+ # manually assign the partition list for the consumer
135
+ from kafka import KafkaConsumer, TopicPartition
136
+ consumer = KafkaConsumer(bootstrap_servers='localhost:1234')
137
+ consumer.assign([TopicPartition('foobar', 2)])
138
+ msg = next(consumer)
139
+
140
+ Keys and Values returned by KafkaConsumer will be raw bytes by default. Use a
141
+ ``value_deserializer`` to automatically decode into something else. Helpers
142
+ are available for simple utf-8 string decoding (``DefaultSerializer``) and
143
+ json (``JsonSerializer``).
144
+
145
+ .. code-block:: python
146
+
147
+ # Deserialize json-encoded values
148
+ from kafka import KafkaConsumer, JsonSerializer
149
+ consumer = KafkaConsumer(value_deserializer=JsonSerializer())
150
+ consumer.subscribe(['json-foo'])
151
+ for msg in consumer:
152
+ assert isinstance(msg.value, dict)
153
+
154
+ .. code-block:: python
155
+
156
+ # Access record headers. The returned value is a list of
157
+ # (str, bytes) tuples, representing the header key and value.
158
+ for msg in consumer:
159
+ print (msg.headers)
160
+
161
+ .. code-block:: python
162
+
163
+ # Read only committed messages from transactional topic
164
+ from kafka import KafkaConsumer, IsolationLevel
165
+ consumer = KafkaConsumer(isolation_level=IsolationLevel.READ_COMMITTED)
166
+ consumer.subscribe(['txn_topic'])
167
+ for msg in consumer:
168
+ print(msg)
169
+
170
+ .. code-block:: python
171
+
172
+ # Get consumer metrics
173
+ metrics = consumer.metrics()
174
+
175
+
176
+ KafkaProducer
177
+ *************
178
+
179
+ KafkaProducer is a high-level, asynchronous message producer. The class is
180
+ intended to operate as similarly as possible to the official java client.
181
+ See https://kafka-python.readthedocs.io/en/master/apidoc/KafkaProducer.html
182
+ for more details.
183
+
184
+ .. code-block:: python
185
+
186
+ from kafka import KafkaProducer
187
+ producer = KafkaProducer(bootstrap_servers='localhost:1234')
188
+ for _ in range(100):
189
+ # Fire-and-forget: send() is async and returns before delivery
190
+ producer.send('foobar', b'some_message_bytes')
191
+
192
+ .. code-block:: python
193
+
194
+ # To check the status of an async message delivery, use .get()
195
+ future = producer.send('foobar', b'another_message')
196
+ # future.get() will block until it can return the result or raise on error
197
+ result = future.get(timeout=60)
198
+
199
+ .. code-block:: python
200
+
201
+ # Block until all pending messages are at least put on the network
202
+ # NOTE: This does not guarantee delivery or success! It is really
203
+ # only useful if you configure internal batching using linger_ms
204
+ producer.flush()
205
+
206
+ Message keys are used to hash messages with the same key to the same
207
+ partition. Both keys and values should be raw bytes unless a serializer is configured.
208
+
209
+ .. code-block:: python
210
+
211
+ # Use a key for hashed-partitioning
212
+ producer.send('foobar', key=b'foo', value=b'bar')
213
+
214
+ .. code-block:: python
215
+
216
+ # Serialize json messages
217
+ from kafka import KafkaProducer, JsonSerializer
218
+ producer = KafkaProducer(value_serializer=JsonSerializer())
219
+ producer.send('fizzbuzz', {'foo': 'bar'})
220
+
221
+ .. code-block:: python
222
+
223
+ # Serialize string keys
224
+ from kafka import KafkaProducer, DefaultSerializer
225
+ producer = KafkaProducer(key_serializer=DefaultSerializer())
226
+ producer.send('flipflap', key='ping', value=b'1234')
227
+
228
+ Compression can be used to reduce message size on the wire. Gzip is supported
229
+ via python stdlib. For other compression types you must install optional
230
+ dependencies.
231
+
232
+ .. code-block:: python
233
+
234
+ # Compress messages
235
+ producer = KafkaProducer(compression_type='gzip')
236
+ for i in range(1000):
237
+ producer.send('foobar', b'msg %d' % i)
238
+
239
+ KafkaProducer also supports transactions and message headers when needed.
240
+
241
+ .. code-block:: python
242
+
243
+ # Use transactions
244
+ producer = KafkaProducer(transactional_id='fizzbuzz')
245
+ producer.init_transactions()
246
+ producer.begin_transaction()
247
+ future = producer.send('txn_topic', value=b'yes')
248
+ future.get() # wait for successful produce
249
+ producer.commit_transaction() # commit the transaction
250
+
251
+ producer.begin_transaction()
252
+ future = producer.send('txn_topic', value=b'no')
253
+ future.get() # wait for successful produce
254
+ producer.abort_transaction() # abort the transaction
255
+
256
+ .. code-block:: python
257
+
258
+ # Include record headers. The format is list of tuples with string key
259
+ # and bytes value.
260
+ producer.send('foobar', value=b'c29tZSB2YWx1ZQ==', headers=[('content-encoding', b'base64')])
261
+
262
+ .. code-block:: python
263
+
264
+ # Get producer performance metrics
265
+ metrics = producer.metrics()
266
+
267
+
268
+ Module CLI Interface
269
+ ********************
270
+
271
+ kafka-python also provides simple command-line interfaces for consumer, producer, and admin clients.
272
+ Access via ``python -m kafka.consumer``, ``python -m kafka.producer``, and ``python -m kafka.admin``.
273
+ See https://kafka-python.readthedocs.io/en/master/usage.html for more details.
274
+
275
+
276
+ Compression
277
+ ***********
278
+
279
+ kafka-python supports the following compression formats:
280
+
281
+ - gzip (via stdlib)
282
+ - LZ4 (via `python-lz4`, `lz4tools`, or `py-lz4framed`)
283
+ - Snappy (via `python-snappy`)
284
+ - Zstandard (via `python-zstandard`)
285
+
286
+ gzip is supported natively, the others require installing additional libraries.
287
+ See https://kafka-python.readthedocs.io/en/master/install.html for more information.
288
+
289
+
290
+ Optimized CRC32 Validation
291
+ **************************
292
+
293
+ Kafka uses CRC32 checksums to validate messages. kafka-python includes a pure
294
+ python implementation for compatibility. To improve performance for high-throughput
295
+ applications, kafka-python will use `crc32c` for optimized native code if installed.
296
+ See https://kafka-python.readthedocs.io/en/master/install.html for installation instructions.
297
+ See https://pypi.org/project/crc32c/ for details on the underlying crc32c lib.
298
+
299
+
300
+ Protocol
301
+ ********
302
+
303
+ A secondary goal of kafka-python is to provide an easy-to-use protocol layer
304
+ for interacting with kafka brokers via the python repl. This is useful for
305
+ testing, probing, and general experimentation. In version 3.0 the protocol
306
+ layer was re-written to generate encoder/decoder classes using json message
307
+ definitions imported directly from the Apache Kafka project source.
308
+
309
+
310
+ Debugging
311
+ *********
312
+
313
+ Use python's `logging` module to view internal operational events.
314
+ See https://docs.python.org/3/howto/logging.html for overview / howto.
315
+
316
+ .. code-block:: python
317
+
318
+ import logging
319
+ logging.basicConfig(level=logging.DEBUG)