{"id":13477249,"url":"https://github.com/dpkp/kafka-python","last_synced_at":"2025-12-17T03:01:48.114Z","repository":{"id":4782365,"uuid":"5934517","full_name":"dpkp/kafka-python","owner":"dpkp","description":"Python client for Apache Kafka","archived":false,"fork":false,"pushed_at":"2025-12-14T14:15:42.000Z","size":5836,"stargazers_count":5865,"open_issues_count":39,"forks_count":1447,"subscribers_count":140,"default_branch":"master","last_synced_at":"2025-12-15T12:18:32.100Z","etag":null,"topics":["kafka","python"],"latest_commit_sha":null,"homepage":"http://kafka-python.readthedocs.io/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dpkp.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":"docs/support.rst","governance":null,"roadmap":null,"authors":"AUTHORS.md","dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2012-09-24T13:00:26.000Z","updated_at":"2025-12-15T08:49:03.000Z","dependencies_parsed_at":"2023-07-05T20:32:24.003Z","dependency_job_id":"3beae280-566d-4c9e-b450-629e6a89b782","html_url":"https://github.com/dpkp/kafka-python","commit_stats":{"total_commits":1914,"total_committers":222,"mean_commits":8.621621621621621,"dds":0.7100313479623824,"last_synced_commit":"a33fcf4d22bdf34e9660e394a7a6f84225411325"},"previous_names":[],"tags_count":67,"template":false,"template_full_name":null,"purl":"pkg:github/dpkp/kafka-python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpkp%2Fkafka-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpkp%2Fkafka-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpkp%2Fkafka-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpkp%2Fkafka-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dpkp","download_url":"https://codeload.github.com/dpkp/kafka-python/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpkp%2Fkafka-python/sbom","scorecard":{"id":354495,"data":{"date":"2025-08-11","repo":{"name":"github.com/dpkp/kafka-python","commit":"512d0a0b8d71cf7f34f1b23f8a42d52c28af3266"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.8,"checks":[{"name":"Maintained","score":10,"reason":"30 commit(s) and 15 issue activity found in the last 90 days -- score normalized to 10","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":1,"reason":"Found 4/30 approved changesets -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Info: jobLevel 'actions' permission set to 'read': .github/workflows/codeql-analysis.yml:27","Info: jobLevel 'contents' permission set to 'read': .github/workflows/codeql-analysis.yml:28","Warn: no topLevel permission defined: .github/workflows/codeql-analysis.yml:1","Warn: no topLevel permission defined: .github/workflows/python-package.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:39: update your workflow using https://app.stepsecurity.io/secureworkflow/dpkp/kafka-python/codeql-analysis.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:43: update your workflow using https://app.stepsecurity.io/secureworkflow/dpkp/kafka-python/codeql-analysis.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:54: update your workflow using https://app.stepsecurity.io/secureworkflow/dpkp/kafka-python/codeql-analysis.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:67: update your workflow using https://app.stepsecurity.io/secureworkflow/dpkp/kafka-python/codeql-analysis.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/python-package.yml:55: update your workflow using https://app.stepsecurity.io/secureworkflow/dpkp/kafka-python/python-package.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/python-package.yml:57: update your workflow using https://app.stepsecurity.io/secureworkflow/dpkp/kafka-python/python-package.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/python-package.yml:71: update your workflow using https://app.stepsecurity.io/secureworkflow/dpkp/kafka-python/python-package.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/python-package.yml:77: update your workflow using https://app.stepsecurity.io/secureworkflow/dpkp/kafka-python/python-package.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/python-package.yml:85: update your workflow using https://app.stepsecurity.io/secureworkflow/dpkp/kafka-python/python-package.yml/master?enable=pin","Warn: pipCommand not pinned by hash: .github/workflows/python-package.yml:66","Warn: pipCommand not pinned by hash: .github/workflows/python-package.yml:67","Info:   0 out of   9 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 pipCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":7,"reason":"3 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: PYSEC-2014-80","Warn: Project is vulnerable to: PYSEC-2020-92 / GHSA-hj5v-574p-mj7c","Warn: Project is vulnerable to: PYSEC-2022-42969"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":10,"reason":"SAST tool is run on all commits","details":["Info: SAST configuration detected: CodeQL","Info: all commits (22) are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-18T09:12:01.157Z","repository_id":4782365,"created_at":"2025-08-18T09:12:01.157Z","updated_at":"2025-08-18T09:12:01.157Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27775881,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-17T02:00:08.291Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["kafka","python"],"created_at":"2024-07-31T16:01:40.178Z","updated_at":"2025-12-17T03:01:48.107Z","avatar_url":"https://github.com/dpkp.png","language":"Python","readme":"Kafka Python client\n------------------------\n\n.. image:: https://img.shields.io/badge/kafka-4.0--0.8-brightgreen.svg\n    :target: https://kafka-python.readthedocs.io/en/master/compatibility.html\n.. image:: https://img.shields.io/pypi/pyversions/kafka-python.svg\n    :target: https://pypi.python.org/pypi/kafka-python\n.. image:: https://coveralls.io/repos/dpkp/kafka-python/badge.svg?branch=master\u0026service=github\n    :target: https://coveralls.io/github/dpkp/kafka-python?branch=master\n.. image:: https://img.shields.io/badge/license-Apache%202-blue.svg\n    :target: https://github.com/dpkp/kafka-python/blob/master/LICENSE\n.. image:: https://img.shields.io/pypi/dw/kafka-python.svg\n    :target: https://pypistats.org/packages/kafka-python\n.. image:: https://img.shields.io/pypi/v/kafka-python.svg\n    :target: https://pypi.org/project/kafka-python\n.. image:: https://img.shields.io/pypi/implementation/kafka-python\n    :target: https://github.com/dpkp/kafka-python/blob/master/setup.py\n\n\n\nPython client for the Apache Kafka distributed stream processing system.\nkafka-python is designed to function much like the official java client, with a\nsprinkling of pythonic interfaces (e.g., consumer iterators).\n\nPlease note that the master branch may contain unreleased features. For release\ndocumentation, please see readthedocs and/or python's inline help.\n\nNew in 2.3 release: python -m kafka.* interfaces for quick scripts and testing.\n\n.. code-block:: bash\n\n    $ pip install kafka-python\n\n\nKafkaConsumer\n*************\n\nKafkaConsumer is a high-level message consumer, intended to operate as similarly\nas possible to the official java client. Full support for coordinated\nconsumer groups requires use of kafka brokers that support the Group APIs: kafka v0.9+.\n\nSee https://kafka-python.readthedocs.io/en/master/apidoc/KafkaConsumer.html\nfor API and configuration details.\n\nThe consumer iterator returns ConsumerRecords, which are simple namedtuples\nthat expose basic message attributes: topic, partition, offset, key, and value:\n\n.. code-block:: python\n\n    from kafka import KafkaConsumer\n    consumer = KafkaConsumer('my_favorite_topic')\n    for msg in consumer:\n        print (msg)\n\n.. code-block:: python\n\n    # join a consumer group for dynamic partition assignment and offset commits\n    from kafka import KafkaConsumer\n    consumer = KafkaConsumer('my_favorite_topic', group_id='my_favorite_group')\n    for msg in consumer:\n        print (msg)\n\n.. code-block:: python\n\n    # manually assign the partition list for the consumer\n    from kafka import TopicPartition\n    consumer = KafkaConsumer(bootstrap_servers='localhost:1234')\n    consumer.assign([TopicPartition('foobar', 2)])\n    msg = next(consumer)\n\n.. code-block:: python\n\n    # Deserialize msgpack-encoded values\n    consumer = KafkaConsumer(value_deserializer=msgpack.loads)\n    consumer.subscribe(['msgpackfoo'])\n    for msg in consumer:\n        assert isinstance(msg.value, dict)\n\n.. code-block:: python\n\n    # Access record headers. The returned value is a list of tuples\n    # with str, bytes for key and value\n    for msg in consumer:\n        print (msg.headers)\n\n.. code-block:: python\n\n    # Read only committed messages from transactional topic\n    consumer = KafkaConsumer(isolation_level='read_committed')\n    consumer.subscribe(['txn_topic'])\n    for msg in consumer:\n        print(msg)\n\n.. code-block:: python\n\n    # Get consumer metrics\n    metrics = consumer.metrics()\n\n\nKafkaProducer\n*************\n\nKafkaProducer is a high-level, asynchronous message producer. The class is\nintended to operate as similarly as possible to the official java client.\nSee https://kafka-python.readthedocs.io/en/master/apidoc/KafkaProducer.html\nfor more details.\n\n.. code-block:: python\n\n    from kafka import KafkaProducer\n    producer = KafkaProducer(bootstrap_servers='localhost:1234')\n    for _ in range(100):\n        producer.send('foobar', b'some_message_bytes')\n\n.. code-block:: python\n\n    # Block until a single message is sent (or timeout)\n    future = producer.send('foobar', b'another_message')\n    result = future.get(timeout=60)\n\n.. code-block:: python\n\n    # Block until all pending messages are at least put on the network\n    # NOTE: This does not guarantee delivery or success! It is really\n    # only useful if you configure internal batching using linger_ms\n    producer.flush()\n\n.. code-block:: python\n\n    # Use a key for hashed-partitioning\n    producer.send('foobar', key=b'foo', value=b'bar')\n\n.. code-block:: python\n\n    # Serialize json messages\n    import json\n    producer = KafkaProducer(value_serializer=lambda v: json.dumps(v).encode('utf-8'))\n    producer.send('fizzbuzz', {'foo': 'bar'})\n\n.. code-block:: python\n\n    # Serialize string keys\n    producer = KafkaProducer(key_serializer=str.encode)\n    producer.send('flipflap', key='ping', value=b'1234')\n\n.. code-block:: python\n\n    # Compress messages\n    producer = KafkaProducer(compression_type='gzip')\n    for i in range(1000):\n        producer.send('foobar', b'msg %d' % i)\n\n.. code-block:: python\n\n    # Use transactions\n    producer = KafkaProducer(transactional_id='fizzbuzz')\n    producer.init_transactions()\n    producer.begin_transaction()\n    future = producer.send('txn_topic', value=b'yes')\n    future.get() # wait for successful produce\n    producer.commit_transaction() # commit the transaction\n\n    producer.begin_transaction()\n    future = producer.send('txn_topic', value=b'no')\n    future.get() # wait for successful produce\n    producer.abort_transaction() # abort the transaction\n\n.. code-block:: python\n\n    # Include record headers. The format is list of tuples with string key\n    # and bytes value.\n    producer.send('foobar', value=b'c29tZSB2YWx1ZQ==', headers=[('content-encoding', b'base64')])\n\n.. code-block:: python\n\n    # Get producer performance metrics\n    metrics = producer.metrics()\n\n\nModule CLI Interface\n********************\n\nkafka-python also provides simple command-line interfaces for consumer, producer, and admin clients.\nAccess via ``python -m kafka.consumer``, ``python -m kafka.producer``, and ``python -m kafka.admin``.\nSee https://kafka-python.readthedocs.io/en/master/usage.html for more details.\n\n\nThread safety\n*************\n\nThe KafkaProducer can be used across threads without issue, unlike the\nKafkaConsumer which cannot.\n\nWhile it is possible to use the KafkaConsumer in a thread-local manner,\nmultiprocessing is recommended.\n\n\nCompression\n***********\n\nkafka-python supports the following compression formats:\n\n- gzip\n- LZ4\n- Snappy\n- Zstandard (zstd)\n\ngzip is supported natively, the others require installing additional libraries.\nSee https://kafka-python.readthedocs.io/en/master/install.html for more information.\n\n\nOptimized CRC32 Validation\n**************************\n\nKafka uses CRC32 checksums to validate messages. kafka-python includes a pure\npython implementation for compatibility. To improve performance for high-throughput\napplications, kafka-python will use `crc32c` for optimized native code if installed.\nSee https://kafka-python.readthedocs.io/en/master/install.html for installation instructions.\nSee https://pypi.org/project/crc32c/ for details on the underlying crc32c lib.\n\n\nProtocol\n********\n\nA secondary goal of kafka-python is to provide an easy-to-use protocol layer\nfor interacting with kafka brokers via the python repl. This is useful for\ntesting, probing, and general experimentation. The protocol support is\nleveraged to enable a KafkaClient.check_version() method that\nprobes a kafka broker and attempts to identify which version it is running\n(0.8.0 to 2.6+).\n\n\nDebugging\n*********\n\nUse python's `logging` module to view internal operational events.\nSee https://docs.python.org/3/howto/logging.html for overview / howto.\n\n.. code-block:: python\n\n    import logging\n    logging.basicConfig(level=logging.DEBUG)\n","funding_links":[],"categories":["Database Drivers","资源列表","Python","Data Management \u0026 Processing","数据库驱动程序","数据库 Drivers","Libraries","Database Drivers [🔝](#readme)","Development","Awesome Python","Database Clients","Clients"],"sub_categories":["数据库驱动","Streaming Data Management","Python","Client libraries","Database Drivers","ASGI Servers"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpkp%2Fkafka-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdpkp%2Fkafka-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpkp%2Fkafka-python/lists"}