This is an automated email from the ASF dual-hosted git repository.
spetz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iggy-website.git
The following commit(s) were added to refs/heads/main by this push:
new e6920dda fix(docs): make Python SDK quickstart and examples runnable
(closes #48) (#49)
e6920dda is described below
commit e6920dda02730da54a86ce0454bc6376f44c7188
Author: Justin Mclean <[email protected]>
AuthorDate: Wed Aug 5 17:46:52 2026 +1000
fix(docs): make Python SDK quickstart and examples runnable (closes #48)
(#49)
---
content/docs/sdk/python/examples.mdx | 33 ++++++++-----
content/docs/sdk/python/intro.mdx | 90 ++++++++++++++++++++++--------------
2 files changed, 77 insertions(+), 46 deletions(-)
diff --git a/content/docs/sdk/python/examples.mdx
b/content/docs/sdk/python/examples.mdx
index 44cb4a1d..ae83dad1 100644
--- a/content/docs/sdk/python/examples.mdx
+++ b/content/docs/sdk/python/examples.mdx
@@ -11,6 +11,7 @@ Working examples are available in the
[examples/python](https://github.com/apach
```python
import asyncio
+
from apache_iggy import IggyClient
from apache_iggy import SendMessage as Message
@@ -18,23 +19,26 @@ STREAM_NAME = "sample-stream"
TOPIC_NAME = "sample-topic"
PARTITION_ID = 0
+
async def main():
client = IggyClient.from_connection_string(
"iggy+tcp://iggy:[email protected]:8090"
)
await client.connect()
- await client.create_stream(name=STREAM_NAME)
- await client.create_topic(
- stream=STREAM_NAME,
- partitions_count=1,
- name=TOPIC_NAME,
- replication_factor=1,
- )
+ # 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,
+ replication_factor=1,
+ )
- messages = []
- for i in range(10):
- messages.append(Message(f"message-{i}"))
+ messages = [Message(f"message-{i}") for i in range(10)]
await client.send_messages(
stream=STREAM_NAME,
@@ -42,6 +46,8 @@ async def main():
partitioning=PARTITION_ID,
messages=messages,
)
+ print(f"Sent {len(messages)} message(s)")
+
asyncio.run(main())
```
@@ -50,18 +56,22 @@ asyncio.run(main())
```python
import asyncio
-from apache_iggy import IggyClient, PollingStrategy, ReceiveMessage
+
+from apache_iggy import IggyClient, PollingStrategy
STREAM_NAME = "sample-stream"
TOPIC_NAME = "sample-topic"
PARTITION_ID = 0
+
async def main():
client = IggyClient.from_connection_string(
"iggy+tcp://iggy:[email protected]:8090"
)
await client.connect()
+ # Next() with auto_commit=True continues from this consumer's last
committed
+ # offset, so each run picks up where the previous one finished.
polled_messages = await client.poll_messages(
stream=STREAM_NAME,
topic=TOPIC_NAME,
@@ -75,6 +85,7 @@ async def main():
payload = message.payload().decode("utf-8")
print(f"Offset: {message.offset()}, Payload: {payload}")
+
asyncio.run(main())
```
diff --git a/content/docs/sdk/python/intro.mdx
b/content/docs/sdk/python/intro.mdx
index ecf12c40..350e6b7a 100644
--- a/content/docs/sdk/python/intro.mdx
+++ b/content/docs/sdk/python/intro.mdx
@@ -15,6 +15,8 @@ pip install apache-iggy
### Producer
```python
+import asyncio
+
from apache_iggy import IggyClient
from apache_iggy import SendMessage as Message
@@ -22,56 +24,74 @@ STREAM_NAME = "sample-stream"
TOPIC_NAME = "sample-topic"
PARTITION_ID = 0
-client =
IggyClient.from_connection_string("iggy+tcp://iggy:iggy@localhost:8090")
-await client.connect()
-
-await client.create_stream(name=STREAM_NAME)
-await client.create_topic(
- stream=STREAM_NAME,
- name=TOPIC_NAME,
- partitions_count=1,
- replication_factor=1,
-)
-
-messages = []
-for i in range(10):
- payload = f"message-{i}"
- message = Message(payload)
- messages.append(message)
-
-await client.send_messages(
- stream=STREAM_NAME,
- topic=TOPIC_NAME,
- partitioning=PARTITION_ID,
- messages=messages,
-)
+
+async def main():
+ client = IggyClient.from_connection_string(
+ "iggy+tcp://iggy:[email protected]: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,
+ replication_factor=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
```python
-from apache_iggy import IggyClient, PollingStrategy, ReceiveMessage
+import asyncio
+
+from apache_iggy import IggyClient, PollingStrategy
STREAM_NAME = "sample-stream"
TOPIC_NAME = "sample-topic"
PARTITION_ID = 0
-client =
IggyClient.from_connection_string("iggy+tcp://iggy:iggy@localhost:8090")
-await client.connect()
-polled_messages = await client.poll_messages(
- stream=STREAM_NAME,
- topic=TOPIC_NAME,
- partition_id=PARTITION_ID,
- polling_strategy=PollingStrategy.Next(),
- count=10,
- auto_commit=True,
-)
+async def main():
+ client = IggyClient.from_connection_string(
+ "iggy+tcp://iggy:[email protected]:8090"
+ )
+ await client.connect()
+
+ # Next() with auto_commit=True continues from this consumer's last
committed
+ # offset, so each run picks up where the previous one finished.
+ polled_messages = await client.poll_messages(
+ stream=STREAM_NAME,
+ topic=TOPIC_NAME,
+ partition_id=PARTITION_ID,
+ polling_strategy=PollingStrategy.Next(),
+ count=10,
+ auto_commit=True,
+ )
-if polled_messages:
for message in polled_messages:
payload = message.payload().decode("utf-8")
print(f"Offset: {message.offset()}, Payload: {payload}")
+
+
+asyncio.run(main())
```
## Examples