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 on every public method
  • JSON, string, bytes, Protobuf, and Avro/Schema Registry serialization
  • Transaction support with context managers
  • Async producer and consumer (asyncio) with batch consumption
  • Retry utilities with exponential backoff
  • OpenTelemetry tracing (KafkaTracer) with graceful no-op fallback
  • Metrics collection and statistics tracking (KafkaMetrics, KafkaStats)
  • Dead letter queue (DeadLetterQueue, process_with_dlq)
  • Type-safe configuration builders with presets, validation, env loading, and security helpers
  • Testing utilities (MockProducer, MockConsumer, MockDeadLetterQueue) with full API parity
  • Structured exception hierarchy with error context
  • Admin client for topic management
  • Consumer offset management, batch polling, and message headers

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]

# With Protobuf support
pip install typedkafka[protobuf]

# Everything
pip install typedkafka[all]

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, config builders, metrics, and dead letter queues.

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.6.0.tar.gz (70.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.6.0-py3-none-any.whl (41.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: typedkafka-0.6.0.tar.gz
  • Upload date:
  • Size: 70.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.6.0.tar.gz
Algorithm Hash digest
SHA256 cfc06d2033203172e63a270a0e9fcf65960b7be4f19879bb8273c434038bdf25
MD5 45df40f81a8aa6c91875af9d211d65c3
BLAKE2b-256 4dcaf2de478d127505902ac4f9f92b62aafa54fbca08e7828c4e6fa8a3c35676

See more details on using hashes here.

Provenance

The following attestation bundles were made for typedkafka-0.6.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.6.0-py3-none-any.whl.

File metadata

  • Download URL: typedkafka-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 41.3 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.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ef57e6ba1c75a84053cff21d3911cd380732cf40dea8e56428aebf096a091ad1
MD5 62a53beb2e6a970f7ef8ac934e2653ba
BLAKE2b-256 1b31bd6748e7a427e464d6f7fce30113671cc16027cee6b8e89b45fa1c42b86e

See more details on using hashes here.

Provenance

The following attestation bundles were made for typedkafka-0.6.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