Skip to main content

An easy to use kafka consumer that uses the kafka-python library, it runs concurently with your flask server

Project description

Flask Kafka

This is an easy to use utility to help Flask developers to implement microservices that interact with Kafka. This library has been inspired by two other similar libraries :-

After looking around the web and on Github, I was not able to find a lot of content on how to consume from a Kafka topic using the Kafka framework. From what I found, I was able to come up with this library by borrowing from the above libraries. They both had a little of what I wanted so I combined them to come up with this one.

I hope you find this useful.

Features

  • Doesn't block process
  • Configure by config.py
  • Support comsuming from topic by decorator

Installation

This project has been commited to Pypi, can be installed by pip:

$ pip install flask-kafka

Simple example

from flask import Flask
from threading import Event
import signal

from flask_kafka import FlaskKafka
app = Flask(__name__)

INTERRUPT_EVENT = Event()

bus = FlaskKafka(INTERRUPT_EVENT,
                 bootstrap_servers=",".join(["localhost:9092"]),
                 group_id="consumer-grp-id"
                 )


def listen_kill_server():
    signal.signal(signal.SIGTERM, bus.interrupted_process)
    signal.signal(signal.SIGINT, bus.interrupted_process)
    signal.signal(signal.SIGQUIT, bus.interrupted_process)
    signal.signal(signal.SIGHUP, bus.interrupted_process)


@bus.handle('test-topic')
def test_topic_handler(msg):
    print("consumed {} from test-topic".format(msg))


if __name__ == '__main__':
    bus.run()
    listen_kill_server()
    app.run(debug=True, port=5004)

License

MIT License

Copyright (c) 2019 Nimrod Kevin Maina

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

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

flask-kafka-0.0.3.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flask_kafka-0.0.3-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file flask-kafka-0.0.3.tar.gz.

File metadata

  • Download URL: flask-kafka-0.0.3.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.7

File hashes

Hashes for flask-kafka-0.0.3.tar.gz
Algorithm Hash digest
SHA256 68a7a4076a9144eb364cc8cff89773e3ce515ab8bfb4ba4e8e58dc4676189440
MD5 b1b5470de976c303294d3d64317f2e89
BLAKE2b-256 dc0475417ca93e3e11d41123ce0d99e194645665fde74c7bc5ab65570b2ea76f

See more details on using hashes here.

File details

Details for the file flask_kafka-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: flask_kafka-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.7

File hashes

Hashes for flask_kafka-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 61a5fcb728a72836c7dfeae9ad049ae157047ec6ebefd0621ddcca5323975507
MD5 16ea25164995e41a87b8e7eaa12c6aad
BLAKE2b-256 69aa81d65aa9f0690fcafa796e4bc161676ff82c2d9b489f1d3347218a3af514

See more details on using hashes here.

Supported by

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