FastAPI Event Driven Development With Kafka, Zookeeper and Docker Compose: A Step-by-Step Guide Part -2

Ahmed Nafies
6 min readApr 18, 2023

Setting up FastAPI with Kafka and docker compose
Full Code on github here

Introduction

In this tutorial, we will build a simple FastAPI application that integrates with Apache Kafka to produce messages whenever an operation occurs. We will use Docker to containerize the application and Poetry for dependency management. It is important to check part 1 before proceeding with this tutorial.

Prerequisites

  • Python 3.10 or later
  • Docker and Docker Compose
  • Poetry (Python dependency management tool)

Getting Started

1. Install Poetry

First, install Poetry globally on your system by following the official installation guide: https://python-poetry.org/docs/#installation

2. Create a new Poetry project

Run the following command to create a new Poetry project:

poetry init -n
poetry add fastapi uvicorn kafka-python

3. Create a main.py file

--

--