Skip to main content

hgraph-kafka

C++-first Kafka services for hgraph, implementing the contract in hgraph RFC 0015. The extension uses librdkafka's C API and exposes the same service model to native C++ and Python graphs.

For installation, concepts, recovery and commit semantics, operational configuration, and Python/C++ usage patterns, see the Kafka user guide. Runnable Python worker, publisher, and bounded-replay examples are in python/examples.

One path-bound, multi-interface service_impl owns the Kafka clients for a configuration. Subscriptions, publish requests, explicit commits, and events all bind to that service instance. Graph output reaches Kafka through the service's sink inputs; records, delivery reports, and events re-enter the root graph through one standard unbounded burst push source. Subscription lifecycle envelopes use that same ordered transport as their records. Kafka clients and worker threads are created on graph start and stopped with the graph.

The public record and configuration shapes are hgraph compound scalars. Kafka headers preserve order, duplicates, null values, and empty byte strings.

Native C++

The installed package exports hgraph::kafka:

#include <hgraph/kafka/service.h>
#include <hgraph/kafka/value_builders.h>
#include <hgraph/lib/std/operators/conversion.h>
#include <hgraph/lib/std/operators/registration.h>

using namespace hgraph;
using namespace hgraph::kafka;

struct KafkaGraph {
    static constexpr auto name = "kafka_graph";

    static void compose(Wiring &w) {
        const auto path = service::path("primary");
        register_service(
            w, path,
            service_config().bootstrap_servers({Str{"localhost:9092"}}).build());

        auto key = wire<stdlib::const_, TS<KafkaSubscriptionKey>>(
            w, subscription_key()
                   .topics({Str{"orders"}})
                   .group_id(Str{"orders-worker"})
                   .build());
        auto subscription = subscribe(w, path, key);

        auto record = wire<stdlib::const_, TS<KafkaProduceRecord>>(
            w, make_produce_record(Bytes{"ready"}));
        auto delivery = publish(
            w, path, publish_request(w, Str{"status"}, record));

        auto cursor = wire<stdlib::getattr_, TS<KafkaCursor>>(
            w, subscription, Str{"cursor"});
        commit(w, path, cursor);
        auto event = events(w, path);
    }
};

KafkaSubscriptionOutput provides the record and its matching next-offset cursor on the same graph tick, plus subscription state. A cursor is accepted only while its subscription identity, assignment generation, and partition remain live. Commits are monotonic per assigned partition.

Python

The Python authoring surface lowers to the same native service:

import hgraph as hg
import hgraph_kafka as kafka

@hg.graph
def app():
    kafka.register_kafka_service(
        kafka.KafkaServiceConfig.from_bootstrap_servers(
            ["localhost:9092"], client_id="orders-worker"
        ),
        path="primary",
    )
    key = kafka.KafkaSubscriptionKey(
        topics=("orders",),
        group_id="orders-worker",
        start_position=kafka.KafkaStartPosition.committed(),
    )
    subscription = kafka.kafka_subscribe(
        hg.const(key, tp=hg.TS[kafka.KafkaSubscriptionKey]),
        path="primary",
    )
    kafka.kafka_commit(subscription["cursor"], path="primary")

The core hgraph wheel owns a guarded compatibility shim at the released hgraph.adaptors.kafka import path. Existing message_publisher, message_subscriber, KafkaMessage, and register_kafka_adaptor imports continue to work when hgraph-kafka is installed. The extension wheel installs only hgraph_kafka; it never contributes files to the core hgraph package.

Recovery and simulation

Subscriptions support explicit topic, pattern, or partition selection; group or independent assignment; earliest, latest, committed, timestamp, explicit, and graph-start positions; snapshot, timestamp, and explicit stop boundaries; key filters; deterministic timestamp/topic/partition/offset replay; and explicit or graph-delivery commits.

Simulation is intentionally limited to bounded, record-time recovery. The consumer preloads the finite replay and schedules records at deterministic graph times. Publish, commit, unbounded asynchronous input, and OnGraphDelivery commit mode are rejected in simulation rather than silently changing their semantics.

Build and test

This is a first-party extension in the hgraph monorepo. It remains a separate CMake package and Python distribution: the top-level core package does not link librdkafka or install these modules.

For an in-tree native development build from the repository root:

cmake -S . -B build-kafka \
  -DHGRAPH_BUILD_KAFKA_EXTENSION=ON \
  -DBUILD_TESTING=ON
cmake --build build-kafka --parallel
ctest --test-dir build-kafka --output-on-failure

The extension can still be configured independently against an installed hgraph SDK:

cmake -S . -B build -DCMAKE_PREFIX_PATH=/path/to/hgraph/install
cmake --build build --parallel
ctest --test-dir build --output-on-failure

Build its separately deployable ABI3 wheel from the repository root after making the matching hgraph SDK discoverable through CMAKE_PREFIX_PATH:

CMAKE_PREFIX_PATH=/path/to/hgraph/sdk \
  uv build --wheel --package hgraph-kafka --python 3.12

The deterministic suite uses librdkafka's mock cluster and the extension fake transport. To include a real broker round trip, provide a clean topic:

HGRAPH_KAFKA_INTEGRATION_BOOTSTRAP=localhost:9092 \
HGRAPH_KAFKA_INTEGRATION_TOPIC=hgraph-kafka-integration \
ctest --test-dir build --output-on-failure

Wheel builds require the SDK installed by a stable-ABI hgraph wheel. The extension rejects an SDK that links Python::Python, because that would pin the nominal ABI3 module to the build interpreter.

Metadata

Release files for hgraph-kafka 0.8.34

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

Source distribution (sdist)

Source distribution for hgraph-kafka 0.8.34
File Size Uploaded
hgraph_kafka-0.8.34.tar.gz 103.1 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for hgraph-kafka 0.8.34
File Interpreter ABI Platform
hgraph_kafka-0.8.34-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details
hgraph_kafka-0.8.34-cp312-abi3-manylinux_2_28_x86_64.whl CPython 3.12 abi3 Linux glibc 2.28+ x86-64 Details
hgraph_kafka-0.8.34-cp312-abi3-macosx_26_0_arm64.whl CPython 3.12 abi3 macOS 26.0+ ARM64 Details

Total release size: 6.2 MB

Release files / hgraph_kafka-0.8.34.tar.gz

Download URL hgraph_kafka-0.8.34.tar.gz
Size 103.1 kB
Tags Source
SHA-256 checksum
How to use checksums
14863be93c9c4054dac2d0d735f877ee5e0e9d026ead35c4daa68ff8305ab772
BLAKE2b-256 checksum
How to use checksums
b7f5fc203861bd87f6e9531d00c9e6ce45ca20145d8fec54256eb1cacbb3a632
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 18, 2026.

Transparency log

Release files / hgraph_kafka-0.8.34-cp312-abi3-win_amd64.whl

Download URL hgraph_kafka-0.8.34-cp312-abi3-win_amd64.whl
Size 3.0 MB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
fe5712f18743afbb4bf9c3ab0c248d5fb35e8d8677cfdf02957cdccafbccd2f8
BLAKE2b-256 checksum
How to use checksums
8fc935158eae667f813f2874a1dbdf64619718f3b8ebb3a6fd940a96925a39ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 18, 2026.

Transparency log

Release files / hgraph_kafka-0.8.34-cp312-abi3-manylinux_2_28_x86_64.whl

Download URL hgraph_kafka-0.8.34-cp312-abi3-manylinux_2_28_x86_64.whl
Size 1.8 MB
Tags CPython 3.12 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
dddf1bf16dee64274fe52fbbd002cf5a1ae13aeddc559fc8aaefd1e26802d74e
BLAKE2b-256 checksum
How to use checksums
9dfa6746b04573c642e16a770e32e0ad260d8c8c002b2ec58dd8d7bd4c61853a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 18, 2026.

Transparency log

Release files / hgraph_kafka-0.8.34-cp312-abi3-macosx_26_0_arm64.whl

Download URL hgraph_kafka-0.8.34-cp312-abi3-macosx_26_0_arm64.whl
Size 1.2 MB
Tags CPython 3.12 abi3 macOS 26.0+ ARM64
SHA-256 checksum
How to use checksums
e2f71f3323d58a9219e4640acc243bb3ab1e49b6aac63e52f407df660785280c
BLAKE2b-256 checksum
How to use checksums
810c9c9cb40b48c8d750c684ae450388858b0a9de5a9d40cf89282040724293c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 18, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.8.34 This release

4 release files

0.8.33

4 release files

0.8.31

4 release files

0.8.30

4 release files

0.8.29

4 release files

0.8.28

4 release files

0.8.27

4 release files

0.8.26

4 release files

0.8.25

4 release files

0.8.24

4 release files

0.8.20

4 release files

0.8.19

4 release files

0.8.18

4 release files

0.8.17

4 release files

0.8.16

4 release files

0.8.15

4 release files

0.8.14

4 release files

0.8.13

4 release files

0.8.12

4 release files

0.8.11

4 release files

0.8.10

4 release files

0.8.9

4 release files

0.8.8

4 release files

0.8.7

4 release files

0.8.6

4 release files

0.8.5

4 release files

0.8.4

4 release files

0.8.3

4 release files

0.8.2

4 release files

0.8.1

4 release files

0.8.0

4 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