Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rushidave sync fork to upstream #28

Open
wants to merge 30 commits into
base: rushidave-main-backup-feb-2024
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7ac6c6e
Allow disabling thread wakeup in send_request_to_node (#2335)
yzhan289 Mar 2, 2023
f8a7e9b
Transition CI/CD to GitHub Workflows (#2378)
wbarnha Aug 4, 2023
94901bb
Update usage.rst (#2334)
majeeddl Aug 4, 2023
46473ba
docs: Fix a few typos (#2319)
timgates42 Aug 4, 2023
b7a9be6
Update usage.rst (#2308)
athlatif Aug 4, 2023
57d8338
Enable testing for Python 3.12 (#2379)
wbarnha Aug 4, 2023
7e87a01
Add py312 to tox.ini (#2382)
wbarnha Aug 6, 2023
f984984
Update fixtures.py to use "127.0.0.1" for local ports (#2384)
wbarnha Aug 6, 2023
d920108
use isinstance in builtin crc32 (#2329)
FlxB2 Aug 8, 2023
a33fcf4
Update setup.py to install zstandard instead of python-zstandard (#2387)
wbarnha Aug 9, 2023
d894e9a
build: update vendored six from 1.11.0 to 1.16.0 (#2398)
shifqu Nov 2, 2023
779a23c
Bump actions/checkout from 3 to 4 (#2392)
dependabot[bot] Nov 2, 2023
4861bee
Uses assert_called_with instead of called_with (#2375)
Nov 3, 2023
0362b87
Update python-package.yml to expect 3.12 tests to pass and extend exp…
wbarnha Nov 3, 2023
0dbf746
Update setup.py to indicate 3.12 support
wbarnha Nov 3, 2023
38e8d04
Update conn.py to catch OSError in case of failed import (#2407)
wbarnha Nov 3, 2023
a1d268a
Update PYTHON_LATEST in python-package.yml to 3.12
wbarnha Nov 3, 2023
364397c
[FIX] suitablt for the high vresion python. (#2394)
rootlulu Nov 4, 2023
0864817
Update python-package.yml to publish to PyPi for every release (#2381)
wbarnha Nov 7, 2023
43822d0
Bump github/codeql-action from 2 to 3 (#2419)
dependabot[bot] Dec 14, 2023
e9dfaf9
Bump actions/setup-python from 4 to 5 (#2418)
dependabot[bot] Dec 14, 2023
b68f61d
Bump actions/setup-java from 3 to 4 (#2417)
dependabot[bot] Dec 14, 2023
ce7d853
Avoid 100% CPU usage while socket is closed (sleep)
orange-kao Aug 4, 2020
6efff52
Support connecting through SOCKS5 proxies (#2169)
hnousiainen Sep 29, 2020
a927ff2
bugfix: fix infinite loop on KafkaAdminClient (#2194)
hackaugusto Jan 14, 2021
6985761
bugfix: infinite loop when send msgs to controller (#2194)
hackaugusto Jan 14, 2021
4ca2f45
bugfix: race among _connecting and cluster metadata (#2189)
hackaugusto Jan 5, 2021
919f61d
bugfix: raise error in check_version if broker is unavailable
keejon Feb 22, 2024
1a6bf01
Revert "bugfix: raise error in check_version if broker is unavailable"
keejon Feb 26, 2024
c662d94
bugfix: catch KeyError in check_version and retry
keejon Feb 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
67 changes: 67 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: CodeQL
on:
push:
branches: [master]
pull_request:
# The branches below must be a subset of the branches above
branches: [master]
schedule:
- cron: 19 10 * * 6
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [python]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
steps:
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
198 changes: 198 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
name: CI/CD

on:
push:
branches: ["master"]
pull_request:
branches: ["master"]
release:
types: [created]
branches:
- 'master'
workflow_dispatch:

env:
FORCE_COLOR: "1" # Make tools pretty.
PIP_DISABLE_PIP_VERSION_CHECK: "1"
PIP_NO_PYTHON_VERSION_WARNING: "1"
PYTHON_LATEST: "3.12"
KAFKA_LATEST: "2.6.0"

# For re-actors/checkout-python-sdist
sdist-artifact: python-package-distributions

jobs:

build-sdist:
name: 📦 Build the source distribution
runs-on: ubuntu-latest
steps:
- name: Checkout project
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_LATEST }}
cache: pip
- run: python -m pip install build
name: Install core libraries for build and install
- name: Build artifacts
run: python -m build
- name: Upload built artifacts for testing
uses: actions/upload-artifact@v3
with:
name: ${{ env.sdist-artifact }}
# NOTE: Exact expected file names are specified here
# NOTE: as a safety measure — if anything weird ends
# NOTE: up being in this dir or not all dists will be
# NOTE: produced, this will fail the workflow.
path: dist/${{ env.sdist-name }}
retention-days: 15

test-python:
name: Tests on ${{ matrix.python-version }}
needs:
- build-sdist
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
experimental: [ false ]
include:
- python-version: "pypy3.9"
experimental: true
- python-version: "~3.13.0-0"
experimental: true
steps:
- name: Checkout the source code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 11
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: |
requirements-dev.txt
- name: Check Java installation
run: source travis_java_install.sh
- name: Pull Kafka releases
run: ./build_integration.sh
env:
PLATFORM: ${{ matrix.platform }}
KAFKA_VERSION: ${{ env.KAFKA_LATEST }}
# TODO: Cache releases to expedite testing
- name: Install dependencies
run: |
sudo apt install -y libsnappy-dev libzstd-dev
python -m pip install --upgrade pip
python -m pip install tox tox-gh-actions
pip install .
pip install -r requirements-dev.txt
- name: Test with tox
run: tox
env:
PLATFORM: ${{ matrix.platform }}
KAFKA_VERSION: ${{ env.KAFKA_LATEST }}

test-kafka:
name: Tests for Kafka ${{ matrix.kafka-version }}
needs:
- build-sdist
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
kafka-version:
- "0.8.2.2"
- "0.9.0.1"
- "0.10.2.2"
- "0.11.0.2"
- "0.11.0.3"
- "1.1.1"
- "2.4.0"
- "2.5.0"
- "2.6.0"
steps:
- name: Checkout the source code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 8
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_LATEST }}
cache: pip
cache-dependency-path: |
requirements-dev.txt
- name: Pull Kafka releases
run: ./build_integration.sh
env:
# This is fast enough as long as you pull only one release at a time,
# no need to worry about caching
PLATFORM: ${{ matrix.platform }}
KAFKA_VERSION: ${{ matrix.kafka-version }}
- name: Install dependencies
run: |
sudo apt install -y libsnappy-dev libzstd-dev
python -m pip install --upgrade pip
python -m pip install tox tox-gh-actions
pip install .
pip install -r requirements-dev.txt
- name: Test with tox
run: tox
env:
PLATFORM: ${{ matrix.platform }}
KAFKA_VERSION: ${{ matrix.kafka-version }}

check: # This job does nothing and is only used for the branch protection
name: ✅ Ensure the required checks passing
if: always()
needs:
- build-sdist
- test-python
- test-kafka
runs-on: ubuntu-latest
steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
publish:
name: 📦 Publish to PyPI
runs-on: ubuntu-latest
needs: [build-sdist]
permissions:
id-token: write
environment: pypi
if: github.event_name == 'release' && github.event.action == 'created'
steps:
- name: Download the sdist artifact
uses: actions/download-artifact@v3
with:
name: artifact
path: dist
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ test37: build-integration
test27: build-integration
KAFKA_VERSION=$(KAFKA_VERSION) SCALA_VERSION=$(SCALA_VERSION) tox -e py27 -- $(FLAGS)

# Test using py.test directly if you want to use local python. Useful for other
# Test using pytest directly if you want to use local python. Useful for other
# platforms that require manual installation for C libraries, ie. Windows.
test-local: build-integration
KAFKA_VERSION=$(KAFKA_VERSION) SCALA_VERSION=$(SCALA_VERSION) py.test \
KAFKA_VERSION=$(KAFKA_VERSION) SCALA_VERSION=$(SCALA_VERSION) pytest \
--pylint --pylint-rcfile=pylint.rc --pylint-error-types=EF $(FLAGS) kafka test

cov-local: build-integration
KAFKA_VERSION=$(KAFKA_VERSION) SCALA_VERSION=$(SCALA_VERSION) py.test \
KAFKA_VERSION=$(KAFKA_VERSION) SCALA_VERSION=$(SCALA_VERSION) pytest \
--pylint --pylint-rcfile=pylint.rc --pylint-error-types=EF --cov=kafka \
--cov-config=.covrc --cov-report html $(FLAGS) kafka test
@echo "open file://`pwd`/htmlcov/index.html"
Expand Down
10 changes: 8 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ Kafka Python client
:target: https://pypi.python.org/pypi/kafka-python
.. image:: https://coveralls.io/repos/dpkp/kafka-python/badge.svg?branch=master&service=github
:target: https://coveralls.io/github/dpkp/kafka-python?branch=master
.. image:: https://travis-ci.org/dpkp/kafka-python.svg?branch=master
:target: https://travis-ci.org/dpkp/kafka-python
.. image:: https://img.shields.io/badge/license-Apache%202-blue.svg
:target: https://github.com/dpkp/kafka-python/blob/master/LICENSE
.. image:: https://img.shields.io/pypi/dw/kafka-python.svg
:target: https://pypistats.org/packages/kafka-python
.. image:: https://img.shields.io/pypi/v/kafka-python.svg
:target: https://pypi.org/project/kafka-python
.. image:: https://img.shields.io/pypi/implementation/kafka-python
:target: https://github.com/dpkp/kafka-python/blob/master/setup.py



Python client for the Apache Kafka distributed stream processing system.
kafka-python is designed to function much like the official java client, with a
Expand Down
53 changes: 53 additions & 0 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ KafkaConsumer
.. code:: python

from kafka import KafkaConsumer
import json
import msgpack

# To consume latest messages and auto-commit offsets
consumer = KafkaConsumer('my-topic',
Expand Down Expand Up @@ -57,6 +59,8 @@ KafkaProducer

from kafka import KafkaProducer
from kafka.errors import KafkaError
import msgpack
import json

producer = KafkaProducer(bootstrap_servers=['broker1:1234'])

Expand Down Expand Up @@ -108,3 +112,52 @@ KafkaProducer

# configure multiple retries
producer = KafkaProducer(retries=5)


ClusterMetadata
=============
.. code:: python

from kafka.cluster import ClusterMetadata

clusterMetadata = ClusterMetadata(bootstrap_servers=['broker1:1234'])

# get all brokers metadata
print(clusterMetadata.brokers())

# get specific broker metadata
print(clusterMetadata.broker_metadata('bootstrap-0'))

# get all partitions of a topic
print(clusterMetadata.partitions_for_topic("topic"))

# list topics
print(clusterMetadata.topics())


KafkaAdminClient
=============
.. code:: python
from kafka import KafkaAdminClient
from kafka.admin import NewTopic

admin = KafkaAdminClient(bootstrap_servers=['broker1:1234'])

# create a new topic
topics_list = []
topics_list.append(NewTopic(name="testtopic", num_partitions=1, replication_factor=1))
admin.create_topics(topics_list,timeout_ms=None, validate_only=False)

# delete a topic
admin.delete_topics(['testtopic'])

# list consumer groups
print(admin.list_consumer_groups())

# get consumer group details
print(admin.describe_consumer_groups('cft-plt-qa.connect'))

# get consumer group offset
print(admin.list_consumer_group_offsets('cft-plt-qa.connect'))


Loading