Skip to content

feat(python): add sink data producer example - #4710

Merged
hubcio merged 6 commits into
apache:masterfrom
himanchalkaushale:feat/sink-data-producer-python
Nov 5, 2026
Merged

hubcio merged 6 commits into
apache:masterfrom
himanchalkaushale:feat/sink-data-producer-python

Conversation

@himanchalkaushale

Copy link
Copy Markdown
Contributor

Which issue does this PR address?

Closes #4700

Rationale

The Python examples were missing a sink data producer. Adding one makes it easier to generate sample JSON records for sink connectors and brings the Python examples in line with the existing Rust implementation.

What changed?

Added examples/python/sink-data-producer/producer.py, which:

  • Reads IGGY_STREAM (default: qw) and IGGY_TOPIC (default: records) from environment variables.
  • Connects to the Iggy server using IggyClient.from_connection_string().
  • Creates the stream and topic if they don't already exist.
  • Generates 100 batches of 100 to 500 JSON records each.
  • Uses the same record structure as the Rust implementation:
    • user_id (string)
    • user_type (integer)
    • email (string)
    • source (string)
    • state (string)
    • created_at (ISO-formatted string)
    • message (string)
  • Sends records using Partitioning.balanced() and DirectProducerConfig.
  • Keeps the stream and topic after execution, following the Rust implementation.

Also updated examples/python/README.md with instructions for running the new example, configuring environment variables, and understanding its behaviour.

Local Execution

  • Python syntax was validated using ast.parse.
  • SDK methods were checked against the existing Python examples and type stubs.
  • Record fields and generation logic were compared with the Rust implementation.
  • Pre-commit hooks were not run.

AI Usage

AI was used to assist with repository exploration, implementation, and documentation.

  • Development assistance: Reviewed existing Python and Rust examples while implementing the producer.
  • Verification: Cross-checked the implementation against existing SDK examples and repository conventions.

I reviewed the changes and can explain the implementation and its design decisions.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Thanks for the PR. It is labeled S-waiting-on-review and queued for review.

If AI was used to create this PR, you must run the team-review skill before opening it.

Slash commands (own line, regular comment) move it around the queue:

  • /ready - back to S-waiting-on-review after addressing feedback
  • /author - flip to S-waiting-on-author while you finish changes
  • /request-review @user-or-team - request a reviewer
  • /pin - exempt the PR from the stale bot, /unpin to undo

See CONTRIBUTING.md for details.

@github-actions github-actions Bot added the S-waiting-on-review PR is waiting on a reviewer label Nov 2, 2026
@justinmclean

Copy link
Copy Markdown
Member

Thanks for this. The record fields and value ranges match the Rust sink data producer, the SDK calls match the Python stubs, and the examples job ran it. A few things to change before it goes in:

  • random_alnum calls secrets.choice once per character. secrets asks the operating system for secure randomness on every call, which is slow when it runs millions of times, and the string generation alone takes about 1.8 s for a full run compared with 0.2 s using random. Demo data does not need secure randomness, so please use random.choices(alphabet, k=length) here and random for the other fields in random_record. Add # noqa: S311 to those lines so the ruff security check accepts them.
  • The README lists IGGY_ADDRESS, IGGY_USERNAME and IGGY_PASSWORD, but parse_args only uses them when no connection string is passed on the command line. Someone who passes one and also sets the variables will not see the variables take effect. Please add a sentence saying the connection string replaces them.
  • The username and password go into the default connection URL without encoding, so a password containing @ or : fails with a parse error. Wrapping both in urllib.parse.quote(..., safe="") fixes it.
  • The while loop with batches_count can be for _ in range(MAX_BATCHES):, and random_record can return a plain dict, which removes the Record dataclass and the asdict call.

The PR description says AI helped and the pre-commit hooks were not run. CONTRIBUTING.md asks for both: please run the team-review skill on the branch and install the hooks with prek install before you push the next revision. CI skipped the Python lint job for this path, so the hooks are the only lint check it gets.

@himanchalkaushale

Copy link
Copy Markdown
Contributor Author

@justinmclean Plz re-review

@hubcio hubcio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please address the issues below.

@github-actions github-actions Bot added S-waiting-on-author PR is waiting on author response and removed S-waiting-on-review PR is waiting on a reviewer labels Nov 4, 2026

@hubcio hubcio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please address the issues below.

Comment thread examples/python/README.md Resolved
@hubcio
hubcio merged commit 7bcf398 into apache:master Nov 5, 2026
37 checks passed
@github-actions github-actions Bot removed the S-waiting-on-author PR is waiting on author response label Nov 5, 2026
@himanchalkaushale
himanchalkaushale deleted the feat/sink-data-producer-python branch November 7, 2026 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python examples: add a sink data producer

4 participants