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.5.tar.gz (126.0 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.5-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.5-cp313-cp313t-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.13tmacOS 11.0+ ARM64

kafkars-0.0.5-cp313-cp313t-macosx_10_12_x86_64.whl (555.0 kB view details)

Uploaded CPython 3.13tmacOS 10.12+ x86-64

kafkars-0.0.5-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.5-cp310-abi3-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

kafkars-0.0.5-cp310-abi3-macosx_10_12_x86_64.whl (561.0 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: kafkars-0.0.5.tar.gz
  • Upload date:
  • Size: 126.0 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.5.tar.gz
Algorithm Hash digest
SHA256 2c57661afdf43288dc9b7745f8e3b74ea765a74ac097a7b136796b372a66817c
MD5 588899653688497ff1f6cbbbc8b00c6e
BLAKE2b-256 e8e39161e0f4e55575b3dc000d5e79637dc15f6046147f8238350faa8332bf10

See more details on using hashes here.

Provenance

The following attestation bundles were made for kafkars-0.0.5.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.5-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for kafkars-0.0.5-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f2948aa7de7cafc2452488b41e8da8d5ce682565f3bb1a0e8ae1f817a2b7cb76
MD5 cb220633b9036ac451c56b278b15c737
BLAKE2b-256 0468b169ad656923d996fcb36c276b7cc42eb69fc125331722063958ef6d0b8f

See more details on using hashes here.

Provenance

The following attestation bundles were made for kafkars-0.0.5-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.5-cp313-cp313t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kafkars-0.0.5-cp313-cp313t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f91f6eee4d4472d4dbc38a03460e34bb60bf24d7f8d9f8c774a8229f6ee7c80a
MD5 f1d0134b3b08dd4e98d418ca2217abc9
BLAKE2b-256 cac8ec1385300282245e96abed723c12e9ef1e40cb4a0370d7b09eb380b7a7f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for kafkars-0.0.5-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.5-cp313-cp313t-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for kafkars-0.0.5-cp313-cp313t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 33267d63732a6be2a5abf902480682d028a0dc6471b55595dba3a2b649c6e282
MD5 14ab97c829dbf467252c3d82d12d6eb0
BLAKE2b-256 b070f2b48f7dafbf4a2683778dadbd64478add1dfdc69c0c1d8ee1a78a2f6ede

See more details on using hashes here.

Provenance

The following attestation bundles were made for kafkars-0.0.5-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.5-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for kafkars-0.0.5-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7c2ddfe959b8e85eebe2469e3a5e5311f090de45591d54cd1bdb5ba8b67eb202
MD5 0d4b399553c18867a38915f1035b84de
BLAKE2b-256 3b9e2bf7a428c2d534be438a805b886c2276ae7c4cc873a7fbc86640374a4718

See more details on using hashes here.

Provenance

The following attestation bundles were made for kafkars-0.0.5-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.5-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kafkars-0.0.5-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5d0699a1b8d0343a45923a7c11c751d6f4c5c2a680722d3025f5d912c2672ffd
MD5 d06843a164288c9fe7245d190717bf4a
BLAKE2b-256 9e1a1dc4f1c0dcb68b361eaf0418c542060a1ad70b2aea2252585b4335af3624

See more details on using hashes here.

Provenance

The following attestation bundles were made for kafkars-0.0.5-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.5-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for kafkars-0.0.5-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ddc1836220bcff4882585cbcc0fe94dfb8b3076d431cc8b68177c4fcf83a0c9a
MD5 14d56c966a46c240cd3436f055d2ee7a
BLAKE2b-256 f422575d4ef8ef194c578ae95024ca6ecb92402a416f9edaaffe6e403a360256

See more details on using hashes here.

Provenance

The following attestation bundles were made for kafkars-0.0.5-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