Skip to main content

A wrapper for kafka-python

Project description

A wrapper for kafka-python

Installation

Install using pip:

pip install kafkaPythonWrapper

Install from Github:

git clone https://github.com/Weizhang2017/pythonKakfaWrapper
cd pythonKakfaWrapper 
python setup.py install

CLI

Usage
usage: kafkaPython [-h] --type type --topic topic [--group_id group_id]
                   --bootstrap_server bootstrap_server [--value value]
                   [--key key]
Required arguments:
  --type              type of kafka client, consumer or producer
  --topic             specify a topic for Kafka
  --bootstrap_server  specify a bootstrap server for Kafka

Optional arguments:
--group_id       specify a group ID for Kafka consumer
--value          specify a value to send to Kafka
--key            specify a key to send to Kafka

The client type is either producer or consumer. If the type is producer, the flag value is required while key is optional. If the type is consumer, the flag group_id is required.

Simple Examples:

Send a message to Kafka

kafkaPython --type producer --topic test --bootstrap_server 'localhost:9092' --key test_key --value test_value

Print messages from Kafka

kafkaPython --type consumer --bootstrap_server 'localhost:9092' --topic test --group_id 1

API

Usage

Send the output of a function to Kafka

from kafkaPythonWrapper import MessageSender

message_sender = MessageSender(topic='test')

@message_sender.send_sync()
def produce_message():
    key, value = 'email_address', 'wzhang@leadbook.com'
    print(f'{key}: {value}')
    yield key, value

Receive and print messages from Kafka

from kafkaPythonWrapper import MessageCollector

message_collector = MessageCollector(topic='test', group_id='1')

@message_collector.consume
def print_message(**kwargs):
    print(kwargs)

Close producer or consumer

message_sender.close()
message_collector.close()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kafkaPythonWrapper-0.1.3.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

kafkaPythonWrapper-0.1.3-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file kafkaPythonWrapper-0.1.3.tar.gz.

File metadata

  • Download URL: kafkaPythonWrapper-0.1.3.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

File hashes

Hashes for kafkaPythonWrapper-0.1.3.tar.gz
Algorithm Hash digest
SHA256 02141e41ba00d6de3e313bdeadc822acad00478e0cfa15726391bfdfb71b8558
MD5 deac21bb11babf0d3eb18fa05d1aec57
BLAKE2b-256 d414e176d02fa51bfd88384943cf7638dadc87f54896f10ad42a0c628ae17099

See more details on using hashes here.

File details

Details for the file kafkaPythonWrapper-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: kafkaPythonWrapper-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

File hashes

Hashes for kafkaPythonWrapper-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c9f4dbecd85c2e059a0e6c9a61a83e73601f06d5696f18210b7a52622fcd586c
MD5 c3accd40c39a6bbb8dcdc825c3e7c2a0
BLAKE2b-256 4fe29f35cbb8c1ed6979a31de30c15a0831b7131533c5adefb17d8f0ad313c14

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page