<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Know CSV file size before download in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Know-CSV-file-size-before-download/m-p/602984#M10664</link>
    <description>&lt;P&gt;Using the Splunk Python SDK, is there any way to know the size of the CSV file that will be generated after streaming and writing all the results?&lt;/P&gt;&lt;P&gt;I've managed to achieve this with the approach below, but it makes me to download and iterate the CSV lines two times.&lt;/P&gt;&lt;PRE&gt;splunk_job = service.jobs.create(query, **kwargs)

# waits job to be done

splunk_job_result_args = {
    "output_mode": "csv"
}

splunk_job_results = splunk_job.results(**splunk_job_result_args)
results_length = 0
for bytes_csv_line in splunk_job_results:
    results_length += len(bytes_csv_line)
splunk_job_results.close()

# checks if the results_length exceeds the limit
# if not, executes the following:

splunk_job_results = splunk_job.results(**splunk_job_result_args)
for bytes_csv_line in splunk_job_results:
    # writes the bytes in a file
splunk_job_results.close()&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 23 Jun 2022 11:20:56 GMT</pubDate>
    <dc:creator>brunoabreu</dc:creator>
    <dc:date>2022-06-23T11:20:56Z</dc:date>
    <item>
      <title>Know CSV file size before download</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Know-CSV-file-size-before-download/m-p/602984#M10664</link>
      <description>&lt;P&gt;Using the Splunk Python SDK, is there any way to know the size of the CSV file that will be generated after streaming and writing all the results?&lt;/P&gt;&lt;P&gt;I've managed to achieve this with the approach below, but it makes me to download and iterate the CSV lines two times.&lt;/P&gt;&lt;PRE&gt;splunk_job = service.jobs.create(query, **kwargs)

# waits job to be done

splunk_job_result_args = {
    "output_mode": "csv"
}

splunk_job_results = splunk_job.results(**splunk_job_result_args)
results_length = 0
for bytes_csv_line in splunk_job_results:
    results_length += len(bytes_csv_line)
splunk_job_results.close()

# checks if the results_length exceeds the limit
# if not, executes the following:

splunk_job_results = splunk_job.results(**splunk_job_result_args)
for bytes_csv_line in splunk_job_results:
    # writes the bytes in a file
splunk_job_results.close()&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 11:20:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Know-CSV-file-size-before-download/m-p/602984#M10664</guid>
      <dc:creator>brunoabreu</dc:creator>
      <dc:date>2022-06-23T11:20:56Z</dc:date>
    </item>
  </channel>
</rss>

