Exporting an agent inventory

This helper exports readable agents to CSV. Include both platform and agent IDs so that agents with the same ID on different platforms remain distinguishable.

Helper definition

import csv

def export_agent_inventory(client, output, agent_filter=None):
    writer = csv.writer(output)
    writer.writerow([
        "platform_id", "agent_id", "display_name", "state", "tags"
    ])
    count = 0
    for item in client.list_agents(agent_filter=agent_filter):
        writer.writerow([
            item.platform_id,
            item.id,
            item.display_name,
            item.state,
            ";".join(item.tags or []),
        ])
        count += 1
    return count

Example use

client is an AgentManagementClient created as described in The main AgentManagementClient class.

from dataikuapi import AgentFilter

selection = AgentFilter().with_states(AgentFilter.STATE_MANAGED)
with open("agent-inventory.csv", "w", newline="", encoding="utf-8") as output:
    count = export_agent_inventory(client, output, selection)
print("Exported agents:", count)

For other selection criteria, see Searching and filtering agents.

Reference documentation

Classes

dataikuapi.agentmanagement.agent.AgentFilter()

Agent filter accepted by search, metric retrieval and bulk action methods.

Functions

list_agents([as_type, agent_filter])

Lists readable agents matching an optional filter.

with_states(*states)