Skip to content

Commit a902dcc

Browse files
dpkpclaude
andauthored
docs: Add Command-Line docs with sphinx-argparse (#3064)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 7fa6715 commit a902dcc

12 files changed

Lines changed: 445 additions & 323 deletions

File tree

.unicode_files

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Files that have known unicode chars; all others should be ascii-only
22
.github/workflows/codeql-analysis.yml
33
AUTHORS.md
4-
docs/usage.rst
4+
docs/high_level.rst
55
test/protocol/old/test_compact.py
66
test/protocol/old/test_types.py
77
test/protocol/schemas/test_codec_types.py

docs/cli/admin.rst

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
kafka-python admin
2+
******************
3+
4+
``kafka-python admin`` exposes :class:`~kafka.KafkaAdminClient`
5+
operations as a command-line tool. Commands are grouped by the kind of
6+
resource they act on (topics, partitions, configs, ...). Each group
7+
contains one or more subcommands.
8+
9+
Output is printed to stdout. ``--format raw`` (the default) uses
10+
``pprint``; ``--format json`` emits a single JSON document, useful for
11+
piping to ``jq`` or other tooling.
12+
13+
.. code-block:: bash
14+
15+
kafka-python admin -b localhost:9092 cluster describe
16+
kafka-python admin -b localhost:9092 --format json topics list
17+
python -m kafka.admin -b localhost:9092 topics create -t foo --num-partitions 3
18+
19+
20+
Global options
21+
==============
22+
23+
.. argparse::
24+
:module: kafka.cli.admin
25+
:func: main_parser
26+
:prog: kafka-python admin
27+
:nosubcommands:
28+
29+
30+
acls
31+
====
32+
33+
.. argparse::
34+
:module: kafka.cli.admin
35+
:func: main_parser
36+
:prog: kafka-python admin
37+
:path: acls
38+
39+
40+
cluster
41+
=======
42+
43+
.. argparse::
44+
:module: kafka.cli.admin
45+
:func: main_parser
46+
:prog: kafka-python admin
47+
:path: cluster
48+
49+
50+
configs
51+
=======
52+
53+
.. argparse::
54+
:module: kafka.cli.admin
55+
:func: main_parser
56+
:prog: kafka-python admin
57+
:path: configs
58+
59+
60+
topics
61+
======
62+
63+
.. argparse::
64+
:module: kafka.cli.admin
65+
:func: main_parser
66+
:prog: kafka-python admin
67+
:path: topics
68+
69+
70+
partitions
71+
==========
72+
73+
.. argparse::
74+
:module: kafka.cli.admin
75+
:func: main_parser
76+
:prog: kafka-python admin
77+
:path: partitions
78+
79+
80+
groups
81+
======
82+
83+
.. argparse::
84+
:module: kafka.cli.admin
85+
:func: main_parser
86+
:prog: kafka-python admin
87+
:path: groups
88+
89+
90+
transactions
91+
============
92+
93+
KIP-664 administrative tools for inspecting and recovering from hanging
94+
transactions. ``list``, ``describe``, and ``describe-producers`` require
95+
broker >= 3.0 (``describe-producers`` works against broker >= 2.8).
96+
97+
.. argparse::
98+
:module: kafka.cli.admin
99+
:func: main_parser
100+
:prog: kafka-python admin
101+
:path: transactions
102+
103+
104+
users
105+
=====
106+
107+
SCRAM credential management. See KIP-554.
108+
109+
.. argparse::
110+
:module: kafka.cli.admin
111+
:func: main_parser
112+
:prog: kafka-python admin
113+
:path: users

docs/cli/consumer.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
kafka-python consumer
2+
*********************
3+
4+
A line-oriented console consumer. Subscribes to one or more topics and
5+
prints each received record to standard output.
6+
7+
Examples
8+
========
9+
10+
.. code-block:: bash
11+
12+
# Read every record on a topic until interrupted
13+
kafka-python consumer -b localhost:9092 -t my-topic
14+
15+
# Join a consumer group and commit offsets automatically
16+
kafka-python consumer -b localhost:9092 -g my-group -t my-topic
17+
18+
# Read from the beginning, then exit after 1s of idle
19+
kafka-python consumer -b localhost:9092 -t my-topic \
20+
-C auto_offset_reset=earliest \
21+
-C consumer_timeout_ms=1000
22+
23+
# Print full ConsumerRecord (topic, partition, offset, key, value, ...)
24+
kafka-python consumer -b localhost:9092 -t my-topic -f full
25+
26+
27+
Reference
28+
=========
29+
30+
.. argparse::
31+
:module: kafka.cli.consumer
32+
:func: main_parser
33+
:prog: kafka-python consumer

docs/cli/index.rst

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
Command-Line Interface
2+
**********************
3+
4+
kafka-python ships simple command-line interfaces for consumer, producer,
5+
and admin clients. They can be invoked either as the ``kafka-python``
6+
console script or as module entry points:
7+
8+
.. code-block:: bash
9+
10+
kafka-python consumer -b localhost:9092 -t my-topic
11+
kafka-python producer -b localhost:9092 -t my-topic
12+
kafka-python admin -b localhost:9092 cluster describe
13+
14+
# equivalent module invocations
15+
python -m kafka.consumer -b localhost:9092 -t my-topic
16+
python -m kafka.producer -b localhost:9092 -t my-topic
17+
python -m kafka.admin -b localhost:9092 cluster describe
18+
19+
The ``kafka-python admin`` command, in particular, is a convenient
20+
alternative to the apache kafka ``bin/`` scripts when a compatible JVM is
21+
not available.
22+
23+
.. toctree::
24+
:maxdepth: 2
25+
26+
consumer
27+
producer
28+
admin
29+
30+
31+
Common Options
32+
==============
33+
34+
All three commands share a common set of connection, logging, and
35+
configuration options. They are documented in full on the individual
36+
command pages; the summary below highlights the most commonly used
37+
flags.
38+
39+
Connection
40+
----------
41+
42+
``-b/--bootstrap-servers HOST:PORT``
43+
One or more bootstrap servers used to discover the rest of the
44+
cluster. May be supplied multiple times.
45+
46+
``-S/--security-protocol``
47+
One of ``PLAINTEXT``, ``SSL``, ``SASL_PLAINTEXT``, ``SASL_SSL``.
48+
Defaults to ``PLAINTEXT``.
49+
50+
``-M/--sasl-mechanism``
51+
One of ``PLAIN``, ``GSSAPI``, ``OAUTHBEARER``, ``SCRAM-SHA-256``,
52+
``SCRAM-SHA-512``. Defaults to ``PLAIN``.
53+
54+
``-U/--sasl-user`` / ``-P/--sasl-password``
55+
Credentials for SASL ``PLAIN`` and ``SCRAM-*`` mechanisms.
56+
57+
Logging
58+
-------
59+
60+
``-l/--log-level``
61+
Python ``logging`` level (``DEBUG``, ``INFO``, ...). Defaults to
62+
``CRITICAL`` so the CLI is quiet by default.
63+
64+
``-L/--enable-logger`` / ``-D/--disable-logger``
65+
Selectively turn on or off a single logger by name. Both flags may
66+
be supplied multiple times.
67+
68+
Extended Configuration
69+
----------------------
70+
71+
``-C/--extra-config key=value``
72+
Pass arbitrary keyword arguments through to the underlying client
73+
constructor (:class:`~kafka.KafkaConsumer`,
74+
:class:`~kafka.KafkaProducer`, or
75+
:class:`~kafka.KafkaAdminClient`). Values that parse as ``int``,
76+
``True``, ``False``, or ``None`` are converted; everything else is
77+
passed through as a string. May be supplied multiple times.
78+
79+
.. code-block:: bash
80+
81+
kafka-python consumer -b localhost:9092 -t foo \
82+
-C auto_offset_reset=earliest \
83+
-C consumer_timeout_ms=1000

docs/cli/producer.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
kafka-python producer
2+
*********************
3+
4+
A line-oriented console producer. Reads lines from standard input and
5+
publishes each one as a record to the configured topic.
6+
7+
Examples
8+
========
9+
10+
.. code-block:: bash
11+
12+
# Publish a single message
13+
echo "hello kafka" | kafka-python producer -b localhost:9092 -t my-topic
14+
15+
# Stream lines from a file
16+
kafka-python producer -b localhost:9092 -t my-topic < messages.txt
17+
18+
19+
Reference
20+
=========
21+
22+
.. argparse::
23+
:module: kafka.cli.producer
24+
:func: main_parser
25+
:prog: kafka-python producer

docs/conf.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
# documentation root, use os.path.abspath to make it absolute, like shown here.
2121
sys.path.insert(0, os.path.abspath('../'))
2222

23+
# Suppress ANSI color escapes from argparse 3.14+ help/usage output captured
24+
# by sphinx-argparse.
25+
os.environ['NO_COLOR'] = '1'
26+
2327
# -- General configuration ------------------------------------------------
2428

2529
# If your documentation needs a minimal Sphinx version, state it here.
@@ -34,6 +38,7 @@
3438
'sphinx.ext.viewcode',
3539
'sphinx.ext.napoleon',
3640
'sphinx_rtd_theme',
41+
'sphinxarg.ext',
3742
]
3843

3944
# Add any paths that contain templates here, relative to this directory.

0 commit comments

Comments
 (0)