code: def ExportClientsByKeywords(keywords, filename, token=None):
    r
    index = client_index.CreateClientIndex(token=token)
    client_list = index.LookupClients(keywords)
    logging.info("found %d clients", len(client_list))
    if not client_list:
      return
  
    writer = csv.DictWriter([
        u"client_id",
        u"hostname",
        u"last_seen",
        u"os",
        u"os_release",
        u"os_version",
        u"users",
        u"ips",
        u"macs",
    ])
    writer.WriteHeader()
  
    for client in aff4.FACTORY.MultiOpen(client_list, token=token):
      s = client.Schema
      writer.WriteRow({
          u"client_id": client.urn.Basename(),
          u"hostname": client.Get(s.HOSTNAME),
          u"os": client.Get(s.SYSTEM),
          u"os_release": client.Get(s.OS_RELEASE),
          u"os_version": client.Get(s.OS_VERSION),
          u"ips": client.Get(s.HOST_IPS),
          u"macs": client.Get(s.MAC_ADDRESS),
          u"users": "\n".join(client.Get(s.USERNAMES, [])),
          u"last_seen": client.Get(s.PING),
      })
  
    with io.open(filename, "w") as csv_out:
      csv_out.write(writer.Content())
docs: r"""A script to export clients summaries selected by a keyword search.
  
    This script does a client search for machines matching all of keywords and
    writes a .csv summary of the results to filename. Multi-value fields are '\n'
    separated.
  
    Args:
      keywords: a list of keywords to search for
      filename: the name of the file to write to, will be replaced if already
        present
      token: datastore token.