โ10-18-2021 07:17 AM
Hi, we are testing the new Files support in Databricks repos. Is there a way how to programmatically read notebooks?
Thanks
โ11-23-2021 07:37 PM
Hi @Jiri Koutnyโ these files anyway should be synced to your remote repository (git, bitbucket, GitLab etc). The APIs from version control tools Git API for example might help you achieve what you want.
https://stackoverflow.com/questions/38491722/reading-a-github-file-using-python-returns-html-tags
#!/usr/bin/env python3
import base64
import requests
url = 'https://api.github.com/repos/{user}/{repo_name}/contents/{path_to_file}'
req = requests.get(url)
if req.status_code == requests.codes.ok:
req = req.json() # the response is a JSON
# req is now a dict with keys: name, encoding, url, size ...
# and content. But it is encoded with base64.
content = base64.decodestring(req['content'])
else:
print('Content was not found.')
โ10-18-2021 07:24 AM
Thanks @Kaniz Fatmaโ for quick reply. Looking forward to the answers ๐
โ10-20-2021 02:25 AM
โ11-10-2021 08:06 AM
@Jiri Koutnyโ Alternatively, using export API, you can download it and use
curl -n -o example.scala \
'https://<databricks-instance>/api/2.0/workspace/export?path=/Users/user@example.com/ScalaExampleNotebook&direct_download=true'
Documentation https://docs.databricks.com/dev-tools/api/latest/workspace.html#export
โ11-11-2021 12:21 AM
Hi Sandeep, is it really possible to download files (not notebooks) from Repos using the export API? Last time I tried, only notebooks were exported and all files were skipped...
โ11-23-2021 07:37 PM
Hi @Jiri Koutnyโ these files anyway should be synced to your remote repository (git, bitbucket, GitLab etc). The APIs from version control tools Git API for example might help you achieve what you want.
https://stackoverflow.com/questions/38491722/reading-a-github-file-using-python-returns-html-tags
#!/usr/bin/env python3
import base64
import requests
url = 'https://api.github.com/repos/{user}/{repo_name}/contents/{path_to_file}'
req = requests.get(url)
if req.status_code == requests.codes.ok:
req = req.json() # the response is a JSON
# req is now a dict with keys: name, encoding, url, size ...
# and content. But it is encoded with base64.
content = base64.decodestring(req['content'])
else:
print('Content was not found.')
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโt want to miss the chance to attend and share knowledge.
If there isnโt a group near you, start one and help create a community that brings people together.
Request a New Group