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.

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 bounded push sources. 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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hgraph_kafka-0.8.16.tar.gz (86.9 kB view details)

Uploaded Source

Built Distributions

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

hgraph_kafka-0.8.16-cp312-abi3-win_amd64.whl (3.0 MB view details)

Uploaded CPython 3.12+Windows x86-64

hgraph_kafka-0.8.16-cp312-abi3-manylinux_2_28_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.28+ x86-64

hgraph_kafka-0.8.16-cp312-abi3-macosx_15_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.12+macOS 15.0+ ARM64

File details

Details for the file hgraph_kafka-0.8.16.tar.gz.

File metadata

  • Download URL: hgraph_kafka-0.8.16.tar.gz
  • Upload date:
  • Size: 86.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for hgraph_kafka-0.8.16.tar.gz
Algorithm Hash digest
SHA256 fd240849f56096ca623df844660a62f2e5f3844a564188f76572b7ce9a7c2471
MD5 a910315695a09025360f1afd35f12527
BLAKE2b-256 3b479a6fddba41cecacca449f3d0f664c4066c9e955006eb1a96bba879561e14

See more details on using hashes here.

Provenance

The following attestation bundles were made for hgraph_kafka-0.8.16.tar.gz:

Publisher: release-wheels.yml on hhenson/hgraph

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

File details

Details for the file hgraph_kafka-0.8.16-cp312-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for hgraph_kafka-0.8.16-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 1b197c15be8f8650a66a4529f8a675e3a05a1149adca64ab8e02c6ae54604791
MD5 b23574b684861667b5b147f563f352a7
BLAKE2b-256 417ab582b7a30e644a4d2d89929b92a767f83eb3803cfc581fa1bd17995efba9

See more details on using hashes here.

Provenance

The following attestation bundles were made for hgraph_kafka-0.8.16-cp312-abi3-win_amd64.whl:

Publisher: release-wheels.yml on hhenson/hgraph

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

File details

Details for the file hgraph_kafka-0.8.16-cp312-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for hgraph_kafka-0.8.16-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 58bd20cad7f7b45fb2dcf6157073dcf5d89e8b022d394a79cb97b9ff34739a55
MD5 1cc2c09dacd521555a548ecf6463bd32
BLAKE2b-256 f33e05d28c964c652b5d306ed5f371170c91132dcd7dba98b5d1113207fc9182

See more details on using hashes here.

Provenance

The following attestation bundles were made for hgraph_kafka-0.8.16-cp312-abi3-manylinux_2_28_x86_64.whl:

Publisher: release-wheels.yml on hhenson/hgraph

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

File details

Details for the file hgraph_kafka-0.8.16-cp312-abi3-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for hgraph_kafka-0.8.16-cp312-abi3-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 63e861f51fd5d2e5779d9f0d109778199b0cb983ecf1d5b15fb2ea32e602655b
MD5 2cd03eef750c5dde71a37742c9eeabd3
BLAKE2b-256 ce53eb1309fc3eaffa4b5b10e031db84cf521b668af905f299cc139ddc4c55b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for hgraph_kafka-0.8.16-cp312-abi3-macosx_15_0_arm64.whl:

Publisher: release-wheels.yml on hhenson/hgraph

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

Release history Release notifications | RSS feed

0.8.22

4 files

0.8.21

4 files

0.8.20

4 files

0.8.19

4 files

0.8.18

4 files

0.8.17

4 files

This release

0.8.16 This release

4 files

0.8.15

4 files

0.8.14

4 files

0.8.13

4 files

0.8.12

4 files

0.8.11

4 files

0.8.10

4 files

0.8.9

4 files

0.8.8

4 files

0.8.7

4 files

0.8.6

4 files

0.8.5

4 files

0.8.4

4 files

0.8.3

4 files

0.8.2

4 files

0.8.1

4 files

0.8.0

4 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