Administrative resources and operations
The administrative resource and operation layer gives the admin client simple value objects for describing Kafka topics, broker and topic settings, partition growth, and record deletion. The client turns these objects into broker requests, sends each request to the node that owns the operation, and exposes the broker response or a translated result to the caller. See Admin client for the client lifecycle and connection model, and Client and cluster connectivity for the wider connection and metadata model.
Resource value objects
Resource value objects carry the intent of an administrative action without exposing the wire shape used by Kafka. The admin client accepts these objects at its public boundary and converts them into request fields only when it assembles a call.
Topic creation resources
NewTopic describes one topic that the cluster should create. A topic can use a partition count and replication factor so the broker chooses the replica layout, or it can provide explicit replica assignments; the two modes are mutually exclusive. Optional topic settings travel with the creation request.
The object keeps topic creation intent separate from the protocol request. This lets create_topics handle a list of topics and apply one timeout and validation mode to the whole call.
References: aiokafka/…/new_topic.py• L4-38 aiokafka/…/client.py• L183-217
Configuration resources
ConfigResource identifies a Kafka resource and the settings related to it. The supported resource types are broker and topic. For a describe action, configs selects which settings to return: None means all settings and an empty map means no settings. For an alter action, the map supplies the setting names and values to change.
The same value object therefore supports both reading and changing configuration. The admin client keeps broker resources grouped by broker ID and sends topic resources as a separate request because Kafka routes those resource types differently.
References: aiokafka/…/config_resource.py• L4-29 aiokafka/…/client.py• L265-351
Partition and record resources
NewPartitions describes the desired total partition count for an existing topic. It can also carry replica assignments for the new partitions. RecordsToDelete describes a per-partition retention boundary: records before its offset become eligible for deletion.
These objects express changes to existing data structures. The client combines them with topic names or TopicPartition keys to build the grouped broker request.
References: aiokafka/…/new_partitions.py• L1-19 aiokafka/…/records_to_delete.py• L1-12 aiokafka/…/client.py• L353-387 aiokafka/…/client.py• L543-591
Administrative operation flows
Administrative calls follow a common path: the caller supplies a value object or a small collection of identifiers, the admin client maps that input to a protocol request, and the response is either returned in its protocol form or reduced to a useful Python value. Controller-owned operations use current controller metadata, while partition-owned operations use the leader for each partition.
The main routing and interpretation paths are shown below.
flowchart TD
A[Caller input] --> B{Operation group}
B --> C[Topic lifecycle]
B --> D[Configuration]
B --> E[Partition and record changes]
C --> C1[Controller request]
D --> D1[Broker or topic request]
E --> E1[Controller or partition leader]
C1 --> F[Protocol response]
D1 --> F
E1 --> F
F --> G[Response object or mapped result]
Topic lifecycle calls
Topic lifecycle calls create, inspect, and remove topics. Creation converts each NewTopic into the topic name, partition and replica intent, assignments, and settings expected by Kafka. Deletion sends topic names to the controller. Topic listing and description read cluster metadata and return either topic names or the broker-shaped topic descriptions.
The controller is refreshed when needed and retried once when Kafka reports that the selected controller is no longer current. Topic creation can validate without applying the change when the selected broker protocol version supports that option.
References: aiokafka/…/client.py• L168-263 aiokafka/…/client.py• L193-232 aiokafka/…/admin.py• L90-321
Configuration calls
Configuration calls describe or alter broker and topic settings through ConfigResource values. Describe requests preserve the caller's filter and can request setting synonyms on supported broker versions. Alter requests send the supplied setting map as the new resource configuration.
The client groups broker resources by numeric broker ID and sends topic resources together through the normal request path. It gathers the resulting response objects so one public call can cover several resource targets.
References: aiokafka/…/client.py• L265-351 aiokafka/…/admin.py• L991-1222 tests/test_admin.py• L64-108
Partition growth calls
Partition growth calls increase the total partition count of existing topics. The client maps each topic to the desired count and optional assignments, sends the request to the controller, and checks each topic-level error before returning. A requested count describes the final total, not the number of partitions to add.
The broker response can report a separate result for each topic. The client raises the matching Kafka error when any topic result is not successful, so callers do not need to inspect those errors themselves.
References: aiokafka/…/client.py• L353-387 aiokafka/…/admin.py• L1277-1349 tests/test_admin.py• L119-131
Offset lookup calls
Offset lookup calls return the committed offsets for one consumer group. The client first finds the group's coordinator when the caller does not provide it, then groups any requested TopicPartition values by topic for the offset request. It interprets each returned entry as an OffsetAndMetadata value keyed by the same topic-partition identity.
When no partition filter is supplied, supported brokers can return all offsets known for the group. A missing or unset offset remains distinct from a successful committed offset, so callers can use the returned mapping to decide which partitions have usable group state.
References: aiokafka/…/client.py• L473-541 aiokafka/…/commit.py• L1-120 tests/test_admin.py• L167-190
Record deletion calls
Record deletion calls remove records before a target offset on selected partitions. The client refreshes metadata, resolves each partition to its current leader, and groups targets by leader and topic before sending requests. It returns the resulting low watermark for each TopicPartition.
The low watermark marks the point below which records are no longer available. A missing leader or a leader that is not ready stops request assembly with a leader-related error; a broker error in a response is also raised instead of being hidden in the result map.
References: aiokafka/…/client.py• L543-591 aiokafka/…/records_to_delete.py• L1-12 aiokafka/…/admin.py• L1598-1747 tests/test_admin.py• L192-225
Response interpretation
The admin client uses two response styles. Metadata-based calls return simplified Python structures, while request-specific calls return protocol response objects that retain broker result groups and version-specific fields. This split lets callers use direct topic and cluster information while preserving per-resource status for create, delete, and configuration operations.
| Operation | Returned meaning |
|---|---|
| Topic and cluster descriptions | Metadata dictionaries for topics, brokers, and cluster state |
| Topic creation and deletion | Protocol response with one result per topic |
| Configuration describe and alter | Protocol responses with one result group per request target |
| Partition growth | Successful protocol response after topic errors are checked |
| Group offset lookup | Mapping from TopicPartition to OffsetAndMetadata |
| Record deletion | Mapping from TopicPartition to returned low watermark |
Version-aware request builders reject options that the selected broker version cannot support. For example, topic validation and configuration synonyms require protocol versions that carry those fields. The response schemas also vary by version, so callers should rely on the documented result fields rather than assume every broker returns the same tuple shape.
References: aiokafka/…/client.py• L246-263 aiokafka/…/client.py• L265-315 aiokafka/…/client.py• L376-387 aiokafka/…/client.py• L520-582 aiokafka/…/admin.py• L214-243 aiokafka/…/admin.py• L311-321 aiokafka/…/admin.py• L1204-1222
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the fields in
NewTopic,ConfigResource,NewPartitions, andRecordsToDeletealigned with the conversion helpers in admin/client.py. - Preserve the distinction between broker-targeted and topic-targeted configuration resources. A change to resource grouping can send a valid request to the wrong node.
- Keep per-topic and per-partition error handling aligned with the response schemas. A new response version can add fields without changing the error position used by the client.
- When changing a request option, update its broker-version guard and the matching protocol request schema together.
- Keep
TopicPartitionkeys stable when changing record deletion or group offset mapping. Callers depend on the returned key matching the requested topic and partition.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
NewTopic supplies neither a complete count/replication plan nor replica assignments | Topic creation is rejected before a request is sent | Choose exactly one creation mode |
| A controller change occurs between metadata lookup and a controller call | Kafka returns NotControllerError and the first attempt is retried after metadata refresh | Use the controller routing path rather than a fixed broker |
A broker version does not support validate_only or configuration synonyms | Request building raises IncompatibleBrokerVersion | Check the selected API version before enabling the option |
| A partition has no current leader during record deletion | The request cannot be routed and a leader-related error is raised | Wait for metadata to show a usable partition leader |
| A partition-growth or record-deletion result contains a Kafka error code | The public call raises the mapped Kafka error instead of returning a partial success map | Handle these calls as an all-results check |
Key files
| File | Why to read it |
|---|---|
| aiokafka/…/client.py | Main assembly and interpretation flow for administrative calls |
| aiokafka/…/new_topic.py | Topic creation value object and its mutually exclusive input modes |
| aiokafka/…/config_resource.py | Broker and topic configuration resource model |
| aiokafka/…/new_partitions.py | Partition growth value object |
| aiokafka/…/records_to_delete.py | Per-partition record deletion boundary |
| aiokafka/…/admin.py | Request and response contracts for topic, configuration, partition, and record operations |
| tests/test_admin.py | End-to-end guarantees for resource conversion, routing results, and response interpretation |