-
Notifications
You must be signed in to change notification settings - Fork 9
tested and working #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
cmd = [ | ||
"curl", "-s", | ||
"-H", f"Authorization: Bearer {DATABRICKS_TOKEN}", | ||
"-H", "Content-Type: application/json", | ||
f"https://{DATABRICKS_HOST}/api/2.0/dbfs/list?path={path}" | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think here we can use the request function as in the other calls. Not sure why to do it using subprocess and cmd.
# Build URL with query parameters directly | ||
encoded_path = urllib.parse.quote(path) | ||
url = f"https://{DATABRICKS_HOST}/api/2.0/dbfs/read?path={encoded_path}&length={length}" | ||
|
||
print(f"Requesting URL: {url}") | ||
response = requests.get(url, headers=headers) | ||
print(f"Status code: {response.status_code}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, we can reuse the databricks_api_request
function
headers = { | ||
"Authorization": f"Bearer {DATABRICKS_TOKEN}", | ||
"Content-Type": "application/json" | ||
} | ||
|
||
# DBFS file upload requires three steps: | ||
# 1. Create a handle | ||
create_url = f"https://{DATABRICKS_HOST}/api/2.0/dbfs/create" | ||
create_data = { | ||
"path": dbfs_path, | ||
"overwrite": overwrite | ||
} | ||
|
||
create_response = requests.post(create_url, headers=headers, json=create_data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
headers = { | ||
"Authorization": f"Bearer {DATABRICKS_TOKEN}", | ||
"Content-Type": "application/json" | ||
} | ||
|
||
# Build URL with query parameters directly | ||
encoded_path = urllib.parse.quote(path) | ||
url = f"https://{DATABRICKS_HOST}/api/2.0/workspace/list?path={encoded_path}" | ||
|
||
print(f"Requesting URL: {url}") | ||
response = requests.get(url, headers=headers) | ||
print(f"Status code: {response.status_code}") | ||
print(f"Response: {response.text}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
headers = { | ||
"Authorization": f"Bearer {DATABRICKS_TOKEN}", | ||
"Content-Type": "application/json" | ||
} | ||
|
||
# Build request | ||
export_url = f"https://{DATABRICKS_HOST}/api/2.0/workspace/export" | ||
export_data = { | ||
"path": path, | ||
"format": format | ||
} | ||
|
||
response = requests.get(export_url, headers=headers, params=export_data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
headers = { | ||
"Authorization": f"Bearer {DATABRICKS_TOKEN}", | ||
"Content-Type": "application/json" | ||
} | ||
|
||
# Encode the content as base64 | ||
import base64 | ||
content_bytes = content.encode("utf-8") | ||
encoded_content = base64.b64encode(content_bytes).decode("utf-8") | ||
|
||
# Build request | ||
import_url = f"https://{DATABRICKS_HOST}/api/2.0/workspace/import" | ||
import_data = { | ||
"path": path, | ||
"content": encoded_content, | ||
"language": language, | ||
"format": format, | ||
"overwrite": overwrite | ||
} | ||
|
||
response = requests.post(import_url, headers=headers, json=import_data) | ||
response.raise_for_status() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
Thank you so much for this contribution! Let me know if you want to apply the changes, if not, I'll apply them later 😄 |
My honest take is that i actually did a lot of this with AI to get it working faster. I actually use for my job. |
Hey, yes, I noticed you used AI 😅 Thank you! 🙏 |
feel free to accept or not, but it's heloping me a lot