If Apache Iggy is useful to you, give it a star on GitHubStar apache/iggy
Apache Iggy
SDKPython

The Python SDK, a PyO3 wrapper around the Rust SDK, and how to install it.

The Iggy Python SDK is a client library that allows you to interact with the Iggy API from your Python application. It is built as a PyO3 wrapper around the Rust SDK, which means it supports TCP, QUIC, HTTP, and WebSocket transports via connection strings. The package is available on PyPI and the source code can be found on GitHub.

The wheel bundles the Rust SDK, whose binary transports speak the current Iggy wire protocol without falling back to older formats. Use an SDK release compatible with your server. For unreleased changes, build the SDK and server from the same source checkout; the published wheel can lag source API changes.

Installation

Python 3.10 or newer is required. Install the published package in a virtual environment:

python -m venv .venv
source .venv/bin/activate
pip install apache-iggy

For the source version described here, install from the repository root with Rust and Cargo available:

pip install ./foreign/python

Quick start

The samples below target Iggy 0.9.0 on 127.0.0.1:8090:

# Server 0.9.0
docker run --rm \
  --cap-add=SYS_NICE --security-opt seccomp=unconfined --ulimit memlock=-1:-1 \
  -p 8090:8090 \
  -e IGGY_TCP_ADDRESS=0.0.0.0:8090 \
  -e IGGY_NODE_ADVERTISED_ADDRESS=localhost \
  -e IGGY_ROOT_USERNAME=iggy -e IGGY_ROOT_PASSWORD=iggy \
  apache/iggy:0.9.0

# Or from the same repository root as the SDK
cargo run --bin iggy-server -- --fresh --with-default-root-credentials

The environment variables make the server reachable through the published port (it binds to 127.0.0.1 inside the container by default) and bootstrap the iggy/iggy root credentials for new data. Stored credentials are not replaced. Environment credentials override the default-credentials flag, so unset them or set them to match the sample. --fresh deletes local replica state; use disposable development data. A new standalone server without explicit credentials generates a root password; a new cluster requires explicit credentials.

Producer

import asyncio

from apache_iggy import IggyClient
from apache_iggy import SendMessage as Message

STREAM_NAME = "sample-stream"
TOPIC_NAME = "sample-topic"
PARTITION_ID = 0


async def main():
    client = IggyClient.from_connection_string(
        "iggy+tcp://iggy:iggy@127.0.0.1:8090"
    )
    await client.connect()

    # Re-running this example is fine: only create what is missing.
    if await client.get_stream(STREAM_NAME) is None:
        await client.create_stream(name=STREAM_NAME)

    if await client.get_topic(STREAM_NAME, TOPIC_NAME) is None:
        await client.create_topic(
            stream=STREAM_NAME,
            name=TOPIC_NAME,
            partitions_count=1,
        )

    messages = [Message(f"message-{i}") for i in range(10)]

    await client.send_messages(
        stream=STREAM_NAME,
        topic=TOPIC_NAME,
        partitioning=PARTITION_ID,
        messages=messages,
    )
    print(f"Sent {len(messages)} message(s)")


asyncio.run(main())

Consumer

import asyncio

from apache_iggy import Consumer, IggyClient, PollingStrategy

STREAM_NAME = "sample-stream"
TOPIC_NAME = "sample-topic"
PARTITION_ID = 0


async def main():
    client = IggyClient.from_connection_string(
        "iggy+tcp://iggy:iggy@127.0.0.1:8090"
    )
    await client.connect()

    # Next() resumes this named consumer after its stored offset. Auto-commit
    # can store the offset before application processing finishes.
    polled_messages = await client.poll_messages(
        stream=STREAM_NAME,
        topic=TOPIC_NAME,
        consumer=Consumer.Single("sample-consumer"),
        partition_id=PARTITION_ID,
        polling_strategy=PollingStrategy.Next(),
        count=10,
        auto_commit=True,
    )

    for message in polled_messages:
        payload = message.payload().decode("utf-8")
        print(f"Offset: {message.offset()}, Payload: {payload}")


asyncio.run(main())

Beyond the basics

  • TLS: use TcpConfig with tls_enabled and tls_ca_file, or the TLS options in a connection string. The certificate must match tls_domain, which defaults to the dialed host. The getting-started example shows the full setup.
  • Consumer groups: await client.consumer_group(...) returns an IggyConsumer that creates and joins the group by default and commits offsets according to the configured AutoCommit mode. Groups require a binary transport; HTTP supports ordinary consumers only.
  • User headers: SendMessage(data, user_headers=...) accepts a plain dict with str, bytes, bool, int, or float values. HeaderKey/HeaderValue give explicit control over the wire type. See the message-headers examples.
  • Topic options: create_topic(..., options=...) accepts extra option keys as a dict[str, str], validated against the server's catalog. client.describe_options("topic") lists the keys a server accepts.
  • Administration: user and permission management. Personal access tokens can be used for login via AutoLogin.personal_access_token(...) in the connection config. PAT management isn't exposed yet.

Examples

Working examples are available in the examples/python directory. See Examples for the list and how to run them.

On this page