Skip to main content

Build simple kafka streams applications

Project description

Kstreams

kstreams is a library/micro framework to use with kafka. It has simple kafka streams implementation that gives certain guarantees, see below.

Build status codecov python version


Documentation: https://kpn.github.io/kstreams/


Installation

pip install kstreams

You will need a worker, we recommend aiorun

pip install aiorun

Usage

import aiorun
from kstreams import create_engine, ConsumerRecord


stream_engine = create_engine(title="my-stream-engine")

@stream_engine.stream("local--kstream")
async def consume(cr: ConsumerRecord):
    print(f"Event consumed: headers: {cr.headers}, payload: {cr.value}")


async def produce():
    payload = b'{"message": "Hello world!"}'

    for i in range(5):
        metadata = await stream_engine.send("local--kstreams", value=payload)
        print(f"Message sent: {metadata}")


async def start():
    await stream_engine.start()
    await produce()


async def shutdown(loop):
    await stream_engine.stop()


if __name__ == "__main__":
    aiorun.run(start(), stop_on_unhandled_errors=True, shutdown_callback=shutdown)

Features

  • Produce events
  • Consumer events with Streams
  • Subscribe to topics by pattern
  • Prometheus metrics and custom monitoring
  • TestClient
  • Custom Serialization and Deserialization
  • Easy to integrate with any async framework. No tied to any library!!
  • Yield events from streams
  • Opentelemetry Instrumentation
  • Middlewares
  • Hooks (on_startup, on_stop, after_startup, after_stop)
  • Store (kafka streams pattern)
  • Stream Join
  • Windowing

Development

This repo requires the use of poetry instead of pip. Note: If you want to have the virtualenv in the same path as the project first you should run poetry config --local virtualenvs.in-project true

To install the dependencies just execute:

poetry install

Then you can activate the virtualenv with

poetry shell

Run test:

./scripts/test

Run code formatting with ruff:

./scripts/format

Commit messages

We use conventional commits for the commit message.

The use of commitizen is recommended. Commitizen is part of the dev dependencies.

cz commit

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

kstreams-0.26.8rc0.dev143582937941.tar.gz (30.6 kB view details)

Uploaded Source

Built Distribution

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

kstreams-0.26.8rc0.dev143582937941-py3-none-any.whl (38.6 kB view details)

Uploaded Python 3

File details

Details for the file kstreams-0.26.8rc0.dev143582937941.tar.gz.

File metadata

  • Download URL: kstreams-0.26.8rc0.dev143582937941.tar.gz
  • Upload date:
  • Size: 30.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.12.9 Linux/6.8.0-1021-azure

File hashes

Hashes for kstreams-0.26.8rc0.dev143582937941.tar.gz
Algorithm Hash digest
SHA256 dd5901c6bc3d0a3d93ffd388833abc9978239664c21941347ab69eacf7e110ea
MD5 27b98e8fc9f77d277fbc078772987fa0
BLAKE2b-256 18641009a5abb796bf084799c6dd5fc52084e2c1c5c1947d4b4e87f00ebdae18

See more details on using hashes here.

File details

Details for the file kstreams-0.26.8rc0.dev143582937941-py3-none-any.whl.

File metadata

File hashes

Hashes for kstreams-0.26.8rc0.dev143582937941-py3-none-any.whl
Algorithm Hash digest
SHA256 0771e202ca37a043d1661cf1a31d624a80845cf97faad0c97a87b00a31669762
MD5 d772ddb95661fbf098df0c3568c06a24
BLAKE2b-256 cf858cec091188d7214bbc0dd1f16010f2f7b800be8e2ab4bcb695f05852673e

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