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)
  • Type-safe configuration builders with validation
  • Admin client for topic management

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)

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

0.3.2

  • Move code examples from README into standalone examples/ directory
  • Pin all CI/CD actions to commit SHAs for supply chain security
  • Switch PyPI publishing to Trusted Publishers (OIDC) instead of API tokens
  • Add py.typed marker file for PEP 561 compliance

0.3.1

  • Update README, CONTRIBUTING, and SECURITY docs for v0.3.0 features

0.3.0

  • Transaction support: init_transactions(), begin/commit/abort_transaction(), transaction() context manager
  • Async producer and consumer (typedkafka.aio)
  • Retry utilities: @retry decorator and RetryPolicy class
  • Pluggable serializers: Serializer/Deserializer ABCs, JSON, String, and Avro implementations
  • Batch send: send_batch() on producer
  • Consumer rebalance callbacks: on_assign, on_revoke, on_lost on subscribe()
  • Configurable iterator poll timeout via poll_timeout attribute
  • Config validation: early ValueError on invalid acks, compression, auto_offset_reset, linger_ms, batch_size
  • Expanded test suite (120 tests)

0.2.0

  • Testing utilities (MockProducer, MockConsumer)
  • Type-safe configuration builders (ProducerConfig, ConsumerConfig)
  • Admin client wrapper for topic management

0.1.0

  • Initial release with KafkaProducer, KafkaConsumer, full type hints, context manager support

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.3.2.tar.gz (33.8 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.3.2-py3-none-any.whl (27.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for typedkafka-0.3.2.tar.gz
Algorithm Hash digest
SHA256 b0a938e19804704e5fda8afb96802991d3e2e2884d274272d56eba68bb55d469
MD5 2ebe92665f84f905fac1f7c45415a75a
BLAKE2b-256 d2152fe92fd617503c540e8e9989c5cf5e97d45a6e0d91ea9af6c6b942cc2893

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: typedkafka-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 27.7 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.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4a65c796e91aa87964a6502ffd8656910c165898f4e43ca59cd57c8c6cd54d9c
MD5 e3fff504bb0ea0f82639dfa57cf832f1
BLAKE2b-256 b8f0c92cba5c3ec82b1a3a4fb6e71417313a3a73d379f9be937c10595edd1eb9

See more details on using hashes here.

Provenance

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