tested and working#3
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.
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.
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) |
| 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}") |
| 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) |
| 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() |
|
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