Skip to content

docs: clarify KafkaProducer.send() return value methods #2658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thomaswong25520
Copy link

Description

This PR improves the documentation for the KafkaProducer.send() method by clarifying what methods are available on the returned FutureRecordMetadata object.

Motivation

While practising the Kafka Python package by trying to build a consumer, I have tried to understand what was is that KafkaProducer.send() method was returning as an object.
Currently, the documentation, as per generated by Sphinx + autodoc did not display such information, states that send() returns a FutureRecordMetadata that "resolves to RecordMetadata", but it doesn't explain how to actually use this future object. Users need to dig through the source code to discover methods like get(), add_callback(), and add_errback().

Changes

  • Enhanced the Returns section of KafkaProducer.send() docstring
  • Added documentation for the main methods available on the returned future:
    • get(timeout=None): for synchronous/blocking behavior
    • add_callback(fn): for handling successful sends asynchronously
    • add_errback(fn): for handling failed sends asynchronously

Testing

  • Verified the docstring renders correctly
  • No code changes, only documentation improvements

Notes

I considered adding more detailed documentation directly on the FutureRecordMetadata class, but since it's not part of the public API (not exported in __init__.py), I kept the changes minimal and focused on the user-facing send() method.

Thank you for considering this contribution!

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.

1 participant