Skip to main content

A mini-framework for Kafka apps

Project description


Så er det tid til en kop kaf'

Kaf is a small Python framework for creating Kafka apps. It is inspired by Faust, but differs in the following ways:

  • Kaf is synchronous (async is future work)
  • Kaf is compatible with Azure Eventhubs (over Kafka interface)
  • Kaf is designed to work with different brokers for the consumer and producer

The framework depends on Confluent Kafka.

How to use

Minimal example:

import logging

from kaf import KafkaApp

consumer_config = {'bootstrap.servers': 'kafka:9092', '': 'myapp'}
producer_config = {'bootstrap.servers': 'kafka:9092'}

app = KafkaApp(

@app.process(topic='foo', publish_to='bar', accepts='json', returns='json')
def add_one(input):
    number = input['number']
    yield {'result':  number+1}, bytes(number)

def done(msg, seconds_elapsed):'Processed message in {seconds_elapsed} seconds')

if __name__ == '__main__':

How errors are handled

Kafka functions keep trying until they succeed. If the user function throws an exception, kaf will continue to the next message but not commit the message that failed.

Future work:

Features to be added:

  • Add decorators for app events on_consume, on_processed and on_publised. This will allow to hook up e.g. Datadog metrics to these events.

How to deploy a new version

Steps (can maybe be improved):

  1. change version and download_url in
  2. git add + commit + push
  3. create new release in GitHub (check source-code link, should match download_url)
  4. Run python sdist
  5. Run twine upload dist/* --verbose (if not installed, pip install twine first)

Useful links used:

Project details

Download files

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

Files for kaf, version 0.1.10
Filename, size File type Python version Upload date Hashes
Filename, size kaf-0.1.10.tar.gz (5.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page