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)
  • Metrics collection and statistics tracking (KafkaMetrics, KafkaStats)
  • Dead letter queue helper (DeadLetterQueue, process_with_dlq)
  • Message headers support on send()
  • Testing utilities (MockProducer/MockConsumer/MockDeadLetterQueue) with full 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, 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.5.0.tar.gz (55.4 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.5.0-py3-none-any.whl (35.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for typedkafka-0.5.0.tar.gz
Algorithm Hash digest
SHA256 e024f63ddc5a6c2f4ebc21e732e8710f29ed70ea8a38117dcb2ea8d5ff6e8d07
MD5 6c1fe7d756f8d862c6d634fdb033f290
BLAKE2b-256 0b9e25a113d9574aced73100fc8cb2c25121e857e0540dc9124f343e7938b80e

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: typedkafka-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 35.1 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.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a5c5a1b0d3e229dadec8cbac98049e80f6c9a90fece0e61b67db083ef2c57310
MD5 2c334a22d1b46c7cb0323fb81207447e
BLAKE2b-256 fc8f43a0394b19a964e40a1f691410874cd97938e70f3ebe8876f29034669cb7

See more details on using hashes here.

Provenance

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