Skip to main content

Rust based, Arrow powered, python kafka client

Project description

kafkars

PyPI Downloads Documentation Python License GitHub stars GitHub repo size GitHub issues PRs Welcome Rust Apache Arrow Ruff prek

Rust-based, Arrow-powered Python Kafka client for high-throughput data pipelines.

Motivation

Python's Global Interpreter Lock (GIL) and memory management create bottlenecks when consuming high-volume Kafka streams. Traditional Python Kafka clients process messages one at a time, requiring serialization/deserialization overhead for each message and limiting throughput.

kafkars solves this by:

  • Rust core: All Kafka operations (polling, buffering, ordering) happen in Rust, bypassing the GIL
  • Batch processing: Messages are accumulated and returned as Apache Arrow RecordBatches, not individual Python objects
  • Zero-copy where possible: Arrow's columnar format enables efficient data transfer between Rust and Python
  • Vectorized operations: Process thousands of messages at once with pandas, polars, or any Arrow-compatible library

This architecture is ideal for:

  • Real-time analytics pipelines
  • ML feature stores consuming from Kafka
  • High-volume event processing
  • Data lake ingestion

Important: Analytics-Focused Design

kafkars does not commit offsets. It is designed for analytics and high-throughput batch processing, not transactional workloads.

  • No exactly-once semantics: Messages may be reprocessed if your application restarts
  • No offset tracking: You control where to start reading via offset policies
  • Stateless consumers: Each consumer instance starts fresh based on the configured policy

If you need exactly-once processing, transactional guarantees, or automatic offset management, use a traditional Kafka client like confluent-kafka-python.

Features

  • Ordered delivery: Messages released in timestamp order across all partitions
  • Flexible offset policies: Start from earliest, latest, or any timestamp
  • Backpressure management: Automatically pauses fast partitions to prevent memory overflow
  • Arrow-native output: Returns PyArrow RecordBatch for efficient downstream processing

Installation

pip install kafkars

Quick Start

from kafkars import ConsumerManager, SourceTopic

# Define source topics with offset policies
topics = [
    SourceTopic.from_earliest("events"),
    SourceTopic.from_relative_time("metrics", 3600_000),  # 1 hour ago
]

# Create consumer
manager = ConsumerManager(
    config={"bootstrap.servers": "localhost:9092"},
    topics=topics,
)

# Poll returns PyArrow RecordBatch
while True:
    batch = manager.poll(timeout_ms=1000)
    if batch.num_rows > 0:
        # Convert to pandas/polars for processing
        df = batch.to_pandas()
        print(f"Received {len(df)} messages")

    if manager.is_live():
        print("Caught up to real-time")
        break

Message Schema

Each poll returns a RecordBatch with the following schema:

Column Type Description
key binary Message key (nullable)
value binary Message payload (nullable)
topic utf8 Source topic name
partition int32 Partition number
offset int64 Message offset
timestamp timestamp[ms, UTC] Message timestamp

Offset Policies

Policy Description
from_earliest(topic) Start from the beginning
from_latest(topic) Start from the end (new messages only)
from_relative_time(topic, ms) Start from N milliseconds ago
from_absolute_time(topic, ms) Start from specific Unix timestamp

Documentation

Full documentation is available at kafkars.readthedocs.io.

License

Apache 2.0

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

kafkars-0.0.6.tar.gz (136.5 kB view details)

Uploaded Source

Built Distributions

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

kafkars-0.0.6-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.17+ x86-64

kafkars-0.0.6-cp313-cp313t-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.13tmacOS 11.0+ ARM64

kafkars-0.0.6-cp313-cp313t-macosx_10_12_x86_64.whl (553.5 kB view details)

Uploaded CPython 3.13tmacOS 10.12+ x86-64

kafkars-0.0.6-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

kafkars-0.0.6-cp310-abi3-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

kafkars-0.0.6-cp310-abi3-macosx_10_12_x86_64.whl (560.1 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file kafkars-0.0.6.tar.gz.

File metadata

  • Download URL: kafkars-0.0.6.tar.gz
  • Upload date:
  • Size: 136.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for kafkars-0.0.6.tar.gz
Algorithm Hash digest
SHA256 5945ef45c8b871c98280a4c4e9ccbbf9dab4b4876b88c182b58e6ee4ca4c216f
MD5 4c1e270e5a389e7bf171d5fd1e1af426
BLAKE2b-256 79275822df596d0a73f9b5dba2a900c9338c4288393133a1db4f691f5c224b4e

See more details on using hashes here.

Provenance

The following attestation bundles were made for kafkars-0.0.6.tar.gz:

Publisher: ci.yaml on 0x26res/kafkars

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

File details

Details for the file kafkars-0.0.6-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for kafkars-0.0.6-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cb1c853ba7b9d71ba020e681ea0330a22f02994319eaf572c0e81bdb5dac39d1
MD5 f152ddffc5962b0dd25d2834bafc41b4
BLAKE2b-256 52a7b12ac59017d57695aaaf6de741b00e85b14f1c7e964ce041b0138b8c2456

See more details on using hashes here.

Provenance

The following attestation bundles were made for kafkars-0.0.6-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: ci.yaml on 0x26res/kafkars

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

File details

Details for the file kafkars-0.0.6-cp313-cp313t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kafkars-0.0.6-cp313-cp313t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 003cee8edb6e2ea1653ec164ffebdbe97ace47e69e2894d528e067a9f74ad572
MD5 ba6aba4c5cda28bcc315d4786e8cd0ff
BLAKE2b-256 21fdfe3d17d9b7fb22b868821b9d8d21ff9c49e631fa23e0f3d1c61dd9c4b453

See more details on using hashes here.

Provenance

The following attestation bundles were made for kafkars-0.0.6-cp313-cp313t-macosx_11_0_arm64.whl:

Publisher: ci.yaml on 0x26res/kafkars

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

File details

Details for the file kafkars-0.0.6-cp313-cp313t-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for kafkars-0.0.6-cp313-cp313t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6b51f95adb2173f21f16e89acfaba31565c7104ca9025420d5a4d2c2f2496787
MD5 cb0fd4ffd538fe765388529cff33212e
BLAKE2b-256 eadc46f728ed0cb3ff43807a014af37b51e2defe8d732244cdc452903fe1ea26

See more details on using hashes here.

Provenance

The following attestation bundles were made for kafkars-0.0.6-cp313-cp313t-macosx_10_12_x86_64.whl:

Publisher: ci.yaml on 0x26res/kafkars

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

File details

Details for the file kafkars-0.0.6-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for kafkars-0.0.6-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5c10f6e88fd5f21a8d3a9bcadf3ce7761cec9ea793e37a0cc8aef0f9f0599f53
MD5 1e946d5fd2d2d354d5935c21718f13c5
BLAKE2b-256 92a1226a31e7195519429edd5f1b28f754e3c498a651c0e25adee16e25276004

See more details on using hashes here.

Provenance

The following attestation bundles were made for kafkars-0.0.6-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: ci.yaml on 0x26res/kafkars

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

File details

Details for the file kafkars-0.0.6-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kafkars-0.0.6-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bc6ffe619550e974a5291040c22fcb1c94467f7030ee250c5addaa740a0e418d
MD5 d8c39a51386b11dd3b67628bbab33392
BLAKE2b-256 3805283a8be1802854c91d122594050637ac42d9c6e68e6cd0b089a0114d1bcf

See more details on using hashes here.

Provenance

The following attestation bundles were made for kafkars-0.0.6-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: ci.yaml on 0x26res/kafkars

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

File details

Details for the file kafkars-0.0.6-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for kafkars-0.0.6-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b4b6933a0bba20ac9cee5654ddb0564fdf42d1efbeccb2e3317fc9407ebbf4ca
MD5 a1f29be62b67139036dfd8b363c5146a
BLAKE2b-256 baa48c2af70e932e2c62ced751c312ead7b46bb485cfc25e3c0c4c9517e6fa6a

See more details on using hashes here.

Provenance

The following attestation bundles were made for kafkars-0.0.6-cp310-abi3-macosx_10_12_x86_64.whl:

Publisher: ci.yaml on 0x26res/kafkars

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