Introducing a new way to review your PRs.

Read the announcement

aio-libs / aiokafka

asyncio client for kafka

View on GitHub

19 documents · Updated Nov 23, 2026

docs / admin-client

Kafka administration client

The Kafka administration client provides asynchronous control and inspection of a Kafka cluster. It uses the shared client for secure connections, cluster metadata, broker routing, timeouts, and retries while it manages topics, partitions, settings, consumer groups, and stored records.

System role

Administrative client

The AIOKafkaAdminClient is the user-facing entry point for cluster administration. It turns high-level admin requests into Kafka requests and returns broker responses or simple result mappings. The client is marked experimental, so callers should treat its public surface as subject to change.

The client accepts the same connection and security settings as the shared Kafka client. This lets administrative traffic use the same bootstrap hosts, TLS or SASL setup, request limits, and retry timing as the other Kafka clients. For the shared connectivity model, see Kafka client and cluster connectivity.

References: aiokafka/…/client.py• L41-80 aiokafka/…/client.py• L86-136

Client lifecycle

The lifecycle has an explicit start and close boundary. Construction creates the shared client, start() bootstraps cluster metadata, and close() stops background metadata work and closes broker connections. A started client can be used for several admin operations before it is closed.

The normal request path is shown below.

flowchart LR
    A[Create admin client] --> B[Start and bootstrap]
    B --> C[Read cluster metadata]
    C --> D[Choose request target]
    D --> E[Send Kafka request]
    E --> F[Return response or result]
    F --> G[Close client]

start() is safe to call more than once. close() is also safe to call after the client is already closed. The shared client must run on the same event loop that created it.

References: aiokafka/…/client.py• L115-162 aiokafka/…/client.py• L138-146

Shared client infrastructure

Bootstrap and metadata

Bootstrap turns one or more seed addresses into a view of the Kafka cluster. The shared client asks a seed broker for metadata, records brokers, the controller, topic partitions, and leaders, then refreshes that view in the background.

The admin client uses this view for both inspection and routing. A metadata request with no topic filter supports cluster-wide discovery, while a topic filter supports topic descriptions. The shared metadata and routing model is described in Kafka client and cluster connectivity.

References: aiokafka/…/client.py• L157-162 aiokafka/…/client.py• L240-269 aiokafka/client.py• L190-270 aiokafka/…/metadata.py• L7-32

Request routing

Kafka assigns different admin work to different broker roles. The admin client sends general inspection requests to a known broker, sends topic and partition changes to the controller, sends consumer-group requests to each group coordinator, and sends record deletion requests to partition leaders.

If the controller changes during a request, the client refreshes metadata and retries once. Other routing failures remain visible as Kafka errors so the caller can decide whether to retry.

References: aiokafka/…/client.py• L148-187 aiokafka/…/client.py• L395-435 aiokafka/…/client.py• L479-547 aiokafka/…/client.py• L549-588

Administrative operations

Topic management

Topic operations create, list, describe, and delete topics. Creation accepts a topic model with either a partition and replication plan or explicit replica assignments. It can also carry topic settings and can validate a request without applying it when the broker supports that option.

Topic descriptions and cluster descriptions come from metadata. They expose the broker and partition view that the shared client uses for later routed operations. The resource models and request forms are covered in Administrative resources and operations.

References: aiokafka/…/client.py• L189-269 aiokafka/…/new_topic.py• L4-38 aiokafka/…/admin.py• L90-321

Partition management

Partition management expands an existing topic to a new total partition count. The caller can let Kafka choose replica placement or provide assignments for the new partitions. The request is controller-bound because the controller owns topic partition changes.

The client checks topic-level errors in the response and raises the mapped Kafka error when partition creation fails. It does not reduce the partition count.

References: aiokafka/…/client.py• L359-393 aiokafka/…/new_partitions.py• L1-19 aiokafka/…/admin.py• L1277-1349

Configuration management

Configuration operations read or change settings for broker and topic resources. A ConfigResource identifies the resource and carries either a set of names to read or a map of values to change. A missing configuration filter means read all values; an empty filter means read none.

Broker settings are sent to the named broker. Topic settings are grouped into a request for the cluster. Describe operations can include configuration synonyms when the broker supports them.

References: aiokafka/…/client.py• L271-357 aiokafka/…/config_resource.py• L4-29 aiokafka/…/admin.py• L991-1222

Consumer-group management

Consumer-group operations list groups, describe group state and members, locate a group coordinator, and read committed offsets. Group listing can query all brokers or a selected broker set. Group description and offset reads are grouped by coordinator to avoid sending a group request to the wrong broker.

Offset reads return a mapping from TopicPartition to OffsetAndMetadata. They inspect stored offsets; they do not prove that the group or the requested partitions still exist.

References: aiokafka/…/client.py• L395-547 aiokafka/…/admin.py• L324-535 aiokafka/…/commit.py• L1-120

ACL operations

Kafka ACL operations describe, create, and delete access rules for resources. The shared Kafka protocol layer defines request and response forms for these operations, including resource, principal, host, operation, permission, and resource-pattern fields.

The current AIOKafkaAdminClient does not expose public ACL methods or route those ACL requests. ACL support is therefore present at the protocol level but is not part of the client-level operation set. See Administrative resources and operations for the resource and request model boundary.

References: aiokafka/…/admin.py• L582-987 aiokafka/…/client.py• L18-37

Record deletion

Record deletion removes records before a supplied offset from selected topic partitions. The client first refreshes metadata, groups each partition by its current leader, and sends one deletion request to each leader. The result maps each partition to its returned low watermark.

This operation changes retained data. It does not delete the topic or reset a consumer group's committed offset.

References: aiokafka/…/client.py• L549-597 aiokafka/…/records_to_delete.py• L1-12 aiokafka/…/admin.py• L1598-1747

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep each new admin operation aligned with its Kafka request version and response shape. Optional fields can fail on older brokers.
  • Keep the request target aligned with Kafka ownership: controller, partition leader, group coordinator, or a general broker.
  • Update the public admin exports when a new input model becomes part of the client API.
  • Preserve metadata refresh behavior when an operation depends on a changed controller, leader, or coordinator.
  • Keep the client page and Administrative resource models and request operations aligned when a resource model or wire request changes.
  • Keep lifecycle changes aligned with the shared client event-loop and connection rules described in Kafka client and cluster connectivity.

Important failure modes

TriggerConsequenceGuard
The bootstrap brokers cannot provide metadatastart() cannot establish the cluster view and raises a connection error.Provide a reachable seed broker and valid security settings.
The controller changes while a topic or partition request is in flightThe first request fails with a controller error.The client refreshes metadata and retries once.
A partition has no usable leaderRecord deletion cannot be routed and raises a leader error.Wait for partition leadership and retry after metadata refresh.
A group coordinator is loading or unavailableGroup listing, description, or offset reads fail with the broker error.Retry after the coordinator becomes ready.
An optional request field is sent to an older brokerThe protocol layer raises an incompatible-version error.Disable the optional feature or use a broker version that supports it.
A caller expects ACL methods on AIOKafkaAdminClientThe operation has no client-level entry point.Use the supported client operations or the protocol layer where appropriate.

Key files

FileWhy to read it
aiokafka/…/client.pyDefines the admin lifecycle, request routing, and public operation groups.
aiokafka/client.pyExplains shared bootstrap, metadata refresh, broker connections, and request delivery.
aiokafka/…/new_topic.py and aiokafka/…/new_partitions.pyDefine the inputs for topic creation and partition expansion.
aiokafka/…/config_resource.pyDefines the resource model used by configuration operations.
aiokafka/…/records_to_delete.pyDefines the offset boundary for record deletion.
aiokafka/…/admin.pyDefines Kafka admin request and response forms, including ACL and record-deletion operations.
aiokafka/…/metadata.pyDefines the broker, controller, topic, and partition metadata used for discovery and routing.
docs/admin-resources-and-operations.mdProvides the related view of administrative resource models and request operations.
docs/client-and-cluster-connectivity.mdProvides the related view of shared broker discovery, metadata, and request delivery.