Skip to main content

Fast Python Kafka client powered by Rust and librdkafka — producer and consumer with native performance

Project description

pyrkafka: Fast Python Kafka Client Powered by Rust

PyPI version License

pyrkafka is a fast, lightweight Python client for Apache Kafka, built on top of librdkafka via the Rust rdkafka crate. It provides a simple, Pythonic API for producing and consuming Kafka messages with native Rust performance through PyO3.

Features

  • Rust-powered performance — wraps librdkafka through Rust, avoiding the overhead of pure-Python implementations
  • GIL release during polling — consumer polling releases the Python GIL, allowing other threads to run while waiting for messages
  • Simple Pythonic API — producer and consumer with familiar Python patterns (for and async for for consuming)
  • Full librdkafka configuration — pass any librdkafka config option via a dict
  • SSL and compression built-in — compiled with SSL (vendored OpenSSL) and zstd compression support
  • Cross-platform wheels — pre-built for Linux (x86_64, aarch64), macOS (x86_64, Apple Silicon), and Windows

Installation

pip install pyrkafka

Requires Python 3.13+. Pre-built wheels are available for all major platforms — no Rust toolchain needed for installation.

Getting Started

Producing Messages

from pyrkafka import PyrKafkaProducer

producer = PyrKafkaProducer("localhost:9092")

# Send a message (partitioned round-robin)
producer.produce("my_topic", b"Hello, Kafka!")

# Send with a key (messages with the same key go to the same partition)
producer.produce_with_key("my_topic", b"Hello, Kafka!", "my_key")

# Flush pending messages (also happens automatically when the producer is dropped)
producer.flush()

Consuming Messages

from pyrkafka import PyrKafkaConsumer

consumer = PyrKafkaConsumer("localhost:9092", "my_topic", "my_group")

for message in consumer:
    print(message.decode())

Async Consuming

The consumer supports async for for use in asyncio applications. The blocking Kafka poll is automatically offloaded to a thread so the event loop stays responsive:

import asyncio
from pyrkafka import PyrKafkaConsumer

async def main():
    consumer = PyrKafkaConsumer("localhost:9092", "my_topic", "my_group")
    async for message in consumer:
        print(message.decode())

asyncio.run(main())

Custom Configuration

Both producer and consumer accept an optional config dict for additional librdkafka configuration:

producer = PyrKafkaProducer("localhost:9092", config={
    "message.timeout.ms": "5000",
    "compression.type": "zstd",
})

consumer = PyrKafkaConsumer("localhost:9092", "my_topic", "my_group", config={
    "auto.offset.reset": "latest",
    "enable.auto.commit": "false",
})

License

MIT

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

pyrkafka-0.3.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distributions

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

pyrkafka-0.3.0-cp313-abi3-win_amd64.whl (3.5 MB view details)

Uploaded CPython 3.13+Windows x86-64

pyrkafka-0.3.0-cp313-abi3-manylinux_2_28_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.13+manylinux: glibc 2.28+ ARM64

pyrkafka-0.3.0-cp313-abi3-macosx_11_0_arm64.whl (3.4 MB view details)

Uploaded CPython 3.13+macOS 11.0+ ARM64

pyrkafka-0.3.0-cp313-abi3-macosx_10_12_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.13+macOS 10.12+ x86-64

pyrkafka-0.3.0-cp312-cp312-manylinux_2_28_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

File details

Details for the file pyrkafka-0.3.0.tar.gz.

File metadata

  • Download URL: pyrkafka-0.3.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyrkafka-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b2d4f7f4e213389590f4a1a5b1968ece711b1ed91c85dd27f92670ab396fe903
MD5 2121ec462a13e96a751aaa34d70df00a
BLAKE2b-256 7b1aa5c6559ac97df5e95eb1f16e786754eb59008c62f1dd9f4d29c69ef705f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrkafka-0.3.0.tar.gz:

Publisher: release.yaml on Miggets7/pyrkafka

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

File details

Details for the file pyrkafka-0.3.0-cp313-abi3-win_amd64.whl.

File metadata

  • Download URL: pyrkafka-0.3.0-cp313-abi3-win_amd64.whl
  • Upload date:
  • Size: 3.5 MB
  • Tags: CPython 3.13+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyrkafka-0.3.0-cp313-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c33ed5a350093bc25c19da445d557ec28b0221f4fc123160ec0abbb5d21fc32e
MD5 34932880177d428155869b5b8944b0a0
BLAKE2b-256 d1d2b7bb608cc2bf8e94d24ce0db1db7c3397f17193aec146aca6dabb85756e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrkafka-0.3.0-cp313-abi3-win_amd64.whl:

Publisher: release.yaml on Miggets7/pyrkafka

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

File details

Details for the file pyrkafka-0.3.0-cp313-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pyrkafka-0.3.0-cp313-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f3bb3c956dac5382ab66c915457369c5e7f9e67d1755d007bd844ab6cadbc9aa
MD5 03044bd2e9e65e0318c8ce58db0b744a
BLAKE2b-256 b3bd248e5bbad6691167ebdd0d3f0d78bfd3cd78f9649588b5ce9395875053ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrkafka-0.3.0-cp313-abi3-manylinux_2_28_aarch64.whl:

Publisher: release.yaml on Miggets7/pyrkafka

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

File details

Details for the file pyrkafka-0.3.0-cp313-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyrkafka-0.3.0-cp313-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e5266f4692c192fcc1e4364000b76181d2193969397f6d385101faf334475e5b
MD5 89f221052df2ed3c5a2005c689799af5
BLAKE2b-256 637ef5954fece9d90ab3ceea0eaec53ce3efc0bad52ceae9ad4156bb13c7edb6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrkafka-0.3.0-cp313-abi3-macosx_11_0_arm64.whl:

Publisher: release.yaml on Miggets7/pyrkafka

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

File details

Details for the file pyrkafka-0.3.0-cp313-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pyrkafka-0.3.0-cp313-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9b356312abcca30a236c73961f6b638d3f1ae1ead12a9628324150ebed1dc3e8
MD5 e2282aec107c24be3b27bb178ce87af8
BLAKE2b-256 0c9943a3c33b035f2132eff88287a823430703f05c91fe65724ffd3a83d4ed61

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrkafka-0.3.0-cp313-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yaml on Miggets7/pyrkafka

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

File details

Details for the file pyrkafka-0.3.0-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyrkafka-0.3.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fb070be0c063dd296c81e6a0b9e10913ae22dd8744f8e0cf694a9a6fc46bdad7
MD5 e7468d2bfa81249d498332ca99678bc7
BLAKE2b-256 ab5d88c7927a42ac9774e4321eb49ce23a3732bf277e8a008a69a04e984fb0f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrkafka-0.3.0-cp312-cp312-manylinux_2_28_x86_64.whl:

Publisher: release.yaml on Miggets7/pyrkafka

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