Skip to main content

A well-documented, fully type-hinted Kafka client for Python

Project description

typedkafka

A well-documented, fully type-hinted Kafka client for Python.

Python Version License: MIT

Overview

typedkafka provides a modern Python interface to Apache Kafka with comprehensive documentation, full type hints, and developer-friendly features. Built on confluent-kafka for performance and reliability.

Key Features:

  • Full type hints and comprehensive docstrings
  • JSON, string, and bytes message helpers
  • Transaction support with context managers
  • Async producer and consumer (asyncio)
  • Retry utilities with exponential backoff
  • Pluggable serializer framework (JSON, String, Avro/Schema Registry)
  • Testing utilities (MockProducer/MockConsumer) with full KafkaMessage API parity
  • Type-safe configuration builders with validation and security helpers (SASL, SSL)
  • Admin client for topic management
  • Batch polling and consumer offset management (seek, assign, position)

Why typedkafka?

confluent-kafka is fast and reliable, but working with it in Python often means guessing at argument types, cross-referencing C library docs, and getting cryptic error messages. typedkafka fixes that:

  • IDE autocomplete that works — full type hints and parameter docs on every method, so you're not guessing at argument types or return values
  • Clear error messages — a proper exception hierarchy instead of cryptic confluent-kafka errors
  • Test without a broker — MockProducer and MockConsumer let you write unit tests without Docker or flaky integration setups
  • Less boilerplate — transactions, async, retry, and serialization are built in instead of requiring manual wiring

Installation

pip install typedkafka

# With Avro/Schema Registry support
pip install typedkafka[avro]

Requires Python 3.9+.

Quick Start

from typedkafka import KafkaProducer

with KafkaProducer({"bootstrap.servers": "localhost:9092"}) as producer:
    producer.send("my-topic", b"Hello, Kafka!")
    producer.send_json("events", {"user_id": 123, "action": "click"})
    producer.flush()
from typedkafka import KafkaConsumer

with KafkaConsumer({"bootstrap.servers": "localhost:9092", "group.id": "my-group"}) as consumer:
    consumer.subscribe(["my-topic"])
    for msg in consumer:
        print(msg.value_as_json())
        consumer.commit(msg)

Configuration Builders

from typedkafka import ProducerConfig, KafkaProducer

config = (
    ProducerConfig()
    .bootstrap_servers("broker:9093")
    .sasl_scram("user", "password")
    .acks("all")
    .compression("gzip")
    .build(validate=True)
)

producer = KafkaProducer(config)

See the examples/ directory for more: transactions, async, retry, serializers, batch send, testing mocks, and config builders.

Development

git clone https://github.com/Jgprog117/typedkafka.git
cd typedkafka
pip install -e ".[dev]"
pytest
ruff check .
mypy src

License

MIT License - see LICENSE file for details.

Changelog

See CHANGELOG.md for the full release history.

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

typedkafka-0.4.0.tar.gz (47.2 kB view details)

Uploaded Source

Built Distribution

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

typedkafka-0.4.0-py3-none-any.whl (29.9 kB view details)

Uploaded Python 3

File details

Details for the file typedkafka-0.4.0.tar.gz.

File metadata

  • Download URL: typedkafka-0.4.0.tar.gz
  • Upload date:
  • Size: 47.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for typedkafka-0.4.0.tar.gz
Algorithm Hash digest
SHA256 ab191b20c0ae926ee9e692934e50c0f90433c3c5b5adb07b76fe1027806ca65e
MD5 463cb26b05ac71bbb5608f105c4d1db3
BLAKE2b-256 e5fcbba72c28b350befe48139909483e83c1ae4f508ec0ca3f4e058f92bff4cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for typedkafka-0.4.0.tar.gz:

Publisher: publish.yml on Jgprog117/typedkafka

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file typedkafka-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: typedkafka-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 29.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for typedkafka-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bd3f3e8ccb6b10a35cc9a80a3fcff32e2bd7ad7813488f196e7d9ecdb6312b6c
MD5 1dc9c2262de4d154af5ceba4442410b4
BLAKE2b-256 8f8ae7806ac56cdd279e3cf5869623c038559dbf4594a904e40b80f3164df025

See more details on using hashes here.

Provenance

The following attestation bundles were made for typedkafka-0.4.0-py3-none-any.whl:

Publisher: publish.yml on Jgprog117/typedkafka

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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