Skip to main content

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

Release files for pyrkafka 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyrkafka 0.3.0
File Size Uploaded
pyrkafka-0.3.0.tar.gz 11.8 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pyrkafka 0.3.0
File
pyrkafka-0.3.0-cp313-abi3-win_amd64.whl CPython 3.13 abi3 Windows x86-64 Details
pyrkafka-0.3.0-cp313-abi3-manylinux_2_28_aarch64.whl CPython 3.13 abi3 Linux glibc 2.28+ ARM64 Details
pyrkafka-0.3.0-cp313-abi3-macosx_11_0_arm64.whl CPython 3.13 abi3 macOS 11.0+ ARM64 Details
pyrkafka-0.3.0-cp313-abi3-macosx_10_12_x86_64.whl CPython 3.13 abi3 macOS 10.12+ x86-64 Details
pyrkafka-0.3.0-cp312-cp312-manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64 Details

Total release size: 18.2 MB

Release files / pyrkafka-0.3.0.tar.gz

Download URL pyrkafka-0.3.0.tar.gz
Size 11.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b2d4f7f4e213389590f4a1a5b1968ece711b1ed91c85dd27f92670ab396fe903
BLAKE2b-256 checksum
How to use checksums
7b1aa5c6559ac97df5e95eb1f16e786754eb59008c62f1dd9f4d29c69ef705f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 25, 2026.

Transparency log

Release files / pyrkafka-0.3.0-cp313-abi3-win_amd64.whl

Download URL pyrkafka-0.3.0-cp313-abi3-win_amd64.whl
Size 3.5 MB
Tags CPython 3.13 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
c33ed5a350093bc25c19da445d557ec28b0221f4fc123160ec0abbb5d21fc32e
BLAKE2b-256 checksum
How to use checksums
d1d2b7bb608cc2bf8e94d24ce0db1db7c3397f17193aec146aca6dabb85756e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 25, 2026.

Transparency log

Release files / pyrkafka-0.3.0-cp313-abi3-manylinux_2_28_aarch64.whl

Download URL pyrkafka-0.3.0-cp313-abi3-manylinux_2_28_aarch64.whl
Size 4.0 MB
Tags CPython 3.13 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
f3bb3c956dac5382ab66c915457369c5e7f9e67d1755d007bd844ab6cadbc9aa
BLAKE2b-256 checksum
How to use checksums
b3bd248e5bbad6691167ebdd0d3f0d78bfd3cd78f9649588b5ce9395875053ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 25, 2026.

Transparency log

Release files / pyrkafka-0.3.0-cp313-abi3-macosx_11_0_arm64.whl

Download URL pyrkafka-0.3.0-cp313-abi3-macosx_11_0_arm64.whl
Size 3.4 MB
Tags CPython 3.13 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e5266f4692c192fcc1e4364000b76181d2193969397f6d385101faf334475e5b
BLAKE2b-256 checksum
How to use checksums
637ef5954fece9d90ab3ceea0eaec53ce3efc0bad52ceae9ad4156bb13c7edb6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 25, 2026.

Transparency log

Release files / pyrkafka-0.3.0-cp313-abi3-macosx_10_12_x86_64.whl

Download URL pyrkafka-0.3.0-cp313-abi3-macosx_10_12_x86_64.whl
Size 3.3 MB
Tags CPython 3.13 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
9b356312abcca30a236c73961f6b638d3f1ae1ead12a9628324150ebed1dc3e8
BLAKE2b-256 checksum
How to use checksums
0c9943a3c33b035f2132eff88287a823430703f05c91fe65724ffd3a83d4ed61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 25, 2026.

Transparency log

Release files / pyrkafka-0.3.0-cp312-cp312-manylinux_2_28_x86_64.whl

Download URL pyrkafka-0.3.0-cp312-cp312-manylinux_2_28_x86_64.whl
Size 3.9 MB
Tags CPython 3.12 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
fb070be0c063dd296c81e6a0b9e10913ae22dd8744f8e0cf694a9a6fc46bdad7
BLAKE2b-256 checksum
How to use checksums
ab5d88c7927a42ac9774e4321eb49ce23a3732bf277e8a008a69a04e984fb0f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 25, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.0 This release

6 release files

0.2.1

6 release files

0.2.0

7 release files

0.1.1

4 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page