Giter VIP home page Giter VIP logo

kafka-python-example's Introduction

Kafka Python example

Simple example how you can interact with Kafka in python

This example written with poetry so you have to install it first

pip install poetry

Usage

git clone https://github.com/Ivan-Feofanov/kafka-python-example.git
cd kafka-python-example
poetry install
poetry shell

Config

Befor you start you have to provide some configuration values as it presented in example .env_example file. You can set them or just rename this file to .env and fill by yourself. Pydantic will parse it and use as application settings.

Authentification

This example show two ways of Kafka authentification - by certificates and by username and password. You have to choose one of them.

Database

For this example you have to use PostgreSQL database because of using UUID field, but you feel free to fork this repo and change this behaviour.

Web API

To start web app you also have to install an ASGI server, such as uvicorn, daphne, or hypercorn.

If you choose uvicorn, you can run development version

uvicorn main:app --reload

It will run web API that will getting messages and passing them in Kafka.

Receiver

To receive messages and store them in database run receiver

python receiver.py

API doc

If api service is running on address 127.0.0.1:8000 you can find usefull API documentation on http://127.0.0.1:8000/docs or http://127.0.0.1:8000/redoc (thanks to FastAPI)

Tests and linter

Don't forget to set env variable ENVIRONMENT to test and point your test database in DATABASE_URL.

To run tests use

poetry run python -m pytest

For linter just run

prospector

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.