<?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 Re: How to extract the start and end time of the command line cell of the notebook using REST API in Azure Databricks? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-extract-the-start-and-end-time-of-the-command-line-cell/m-p/5102#M1614</link>
    <description>&lt;P&gt;Hi @Milind Keer​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for posting your question in our community! We are happy to assist you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To help us provide you with the most accurate information, could you please take a moment to review the responses and select the one that best answers your question?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will also help other community members who may have similar questions in the future. Thank you for your participation and let us know if you need any further assistance!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 29 Apr 2023 05:57:06 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2023-04-29T05:57:06Z</dc:date>
    <item>
      <title>How to extract the start and end time of the command line cell of the notebook using REST API in Azure Databricks?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-extract-the-start-and-end-time-of-the-command-line-cell/m-p/5100#M1612</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a notebook with many command line cells in it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to extract the execution time of each cell using Databricks REST API? How can I do that?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please note - I managed to get the Start &amp;amp; End time of the Job using REST API (/2.1/jobs/runs/get) for the notebook however struggling to get it at the Cell level &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am on Azure Databricks Runtime version 13.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help on this would be highly appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 20:24:59 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-extract-the-start-and-end-time-of-the-command-line-cell/m-p/5100#M1612</guid>
      <dc:creator>Mikki007</dc:creator>
      <dc:date>2023-04-27T20:24:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the start and end time of the command line cell of the notebook using REST API in Azure Databricks?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-extract-the-start-and-end-time-of-the-command-line-cell/m-p/5101#M1613</link>
      <description>&lt;P&gt;@Milind Keer​&amp;nbsp;:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To extract the execution time of each cell in a notebook using the Databricks REST API, you can use the get method of the api/2.0/workspace endpoint.&lt;/P&gt;&lt;P&gt;First, you need to get the notebook's ID using the api/2.0/workspace/get-status endpoint. Once you have the ID, you can use the get method of the api/2.0/workspace endpoint to get the notebook content. The response includes the cell's start time and end time. You can then calculate the execution time of each cell.&lt;/P&gt;&lt;P&gt;Here's an example Python script that uses the Databricks REST API to extract the execution time of each cell in a notebook:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;import requests
import json
&amp;nbsp;
# Databricks workspace URL
url = 'https://&amp;lt;databricks-instance&amp;gt;.azuredatabricks.net'
&amp;nbsp;
# Databricks workspace API token
token = '&amp;lt;databricks-token&amp;gt;'
&amp;nbsp;
# Notebook path
notebook_path = '/path/to/notebook'
&amp;nbsp;
# Get notebook ID
get_status_url = f'{url}/api/2.0/workspace/get-status'
headers = {'Authorization': f'Bearer {token}'}
params = {'path': notebook_path}
response = requests.get(get_status_url, headers=headers, params=params)
notebook_id = response.json()['object_id']
&amp;nbsp;
# Get notebook content
get_url = f'{url}/api/2.0/workspace/get'
params = {'path': notebook_path}
data = {'format': 'SOURCE'}
response = requests.get(get_url, headers=headers, params=params, data=json.dumps(data))
notebook_content = response.json()['content']
&amp;nbsp;
# Extract cell execution time
cells = notebook_content.split('# COMMAND ----------\n')
for cell in cells[1:]:
    cell = cell.strip()
    if not cell:
        continue
    cell_content = cell.split('\n')
    cell_start_time = cell_content[0].split(' - ')[0]
    cell_end_time = cell_content[-1].split(' - ')[0]
    execution_time = (pd.to_datetime(cell_end_time) - pd.to_datetime(cell_start_time)).total_seconds()
    print(f'Cell execution time: {execution_time} seconds')&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You will need to replace &amp;lt;databricks-instance&amp;gt;, &amp;lt;databricks-token&amp;gt;, and /path/to/notebook with your Databricks instance URL, API token, and the path to your notebook, respectively.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 17:44:00 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-extract-the-start-and-end-time-of-the-command-line-cell/m-p/5101#M1613</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-04-28T17:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the start and end time of the command line cell of the notebook using REST API in Azure Databricks?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-extract-the-start-and-end-time-of-the-command-line-cell/m-p/5102#M1614</link>
      <description>&lt;P&gt;Hi @Milind Keer​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for posting your question in our community! We are happy to assist you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To help us provide you with the most accurate information, could you please take a moment to review the responses and select the one that best answers your question?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will also help other community members who may have similar questions in the future. Thank you for your participation and let us know if you need any further assistance!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Apr 2023 05:57:06 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-extract-the-start-and-end-time-of-the-command-line-cell/m-p/5102#M1614</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-04-29T05:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the start and end time of the command line cell of the notebook using REST API in Azure Databricks?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-extract-the-start-and-end-time-of-the-command-line-cell/m-p/5103#M1615</link>
      <description>&lt;P&gt;@Suteja Kanuri​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks for your reply however I am getting below error -&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;b'{"error_code":"ENDPOINT_NOT_FOUND","message":"No API found for \'GET /workspace/get\'"}'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; the GET endpoint has been deprecated as per below doc,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.databricks.com/dev-tools/api/latest/workspace.html#notebooks" alt="https://docs.databricks.com/dev-tools/api/latest/workspace.html#notebooks" target="_blank"&gt;Workspace API 2.0 | Databricks on AWS&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I even tried 'Export' but it didn't return anything (blank)&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2023 11:59:11 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-extract-the-start-and-end-time-of-the-command-line-cell/m-p/5103#M1615</guid>
      <dc:creator>Mikki007</dc:creator>
      <dc:date>2023-05-02T11:59:11Z</dc:date>
    </item>
  </channel>
</rss>

