Skip to content

Commit 3f38293

Browse files
formated and documented
1 parent 483a732 commit 3f38293

File tree

14 files changed

+102
-63
lines changed

14 files changed

+102
-63
lines changed

databricks/sdk/__init__.py

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

databricks/sdk/config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pathlib
77
import sys
88
import urllib.parse
9-
from typing import Dict, Iterable, Optional, List
9+
from typing import Dict, Iterable, List, Optional
1010

1111
import requests
1212

@@ -110,7 +110,9 @@ class Config:
110110

111111
disable_async_token_refresh: bool = ConfigAttribute(env="DATABRICKS_DISABLE_ASYNC_TOKEN_REFRESH")
112112

113-
disable_experimental_files_api_client: bool = ConfigAttribute(env="DATABRICKS_DISABLE_EXPERIMENTAL_FILES_API_CLIENT")
113+
disable_experimental_files_api_client: bool = ConfigAttribute(
114+
env="DATABRICKS_DISABLE_EXPERIMENTAL_FILES_API_CLIENT"
115+
)
114116

115117
files_ext_client_download_streaming_chunk_size: int = 2 * 1024 * 1024 # 2 MiB
116118

docs/account/iam/workspace_assignment.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@
7474
7575
spn_id = spn.id
7676
77-
workspace_id = os.environ["TEST_WORKSPACE_ID"]
77+
workspace_id = os.environ["DUMMY_WORKSPACE_ID"]
7878
79-
a.workspace_assignment.update(
79+
_ = a.workspace_assignment.update(
8080
workspace_id=workspace_id,
8181
principal_id=spn_id,
8282
permissions=[iam.WorkspacePermission.USER],

docs/account/provisioning/storage.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
.. code-block::
1818
19+
import os
1920
import time
2021
2122
from databricks.sdk import AccountClient
@@ -25,8 +26,11 @@
2526
2627
storage = a.storage.create(
2728
storage_configuration_name=f"sdk-{time.time_ns()}",
28-
root_bucket_info=provisioning.RootBucketInfo(bucket_name=f"sdk-{time.time_ns()}"),
29+
root_bucket_info=provisioning.RootBucketInfo(bucket_name=os.environ["TEST_ROOT_BUCKET"]),
2930
)
31+
32+
# cleanup
33+
a.storage.delete(storage_configuration_id=storage.storage_configuration_id)
3034
3135
Creates a Databricks storage configuration for an account.
3236

docs/workspace/catalog/storage_credentials.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
3333
created = w.storage_credentials.create(
3434
name=f"sdk-{time.time_ns()}",
35-
aws_iam_role=catalog.AwsIamRoleRequest(role_arn=os.environ["TEST_METASTORE_DATA_ACCESS_ARN"]),
35+
aws_iam_role=catalog.AwsIamRole(role_arn=os.environ["TEST_METASTORE_DATA_ACCESS_ARN"]),
3636
)
3737
3838
# cleanup
39-
w.storage_credentials.delete(name=created.name)
39+
w.storage_credentials.delete(delete=created.name)
4040
4141
Creates a new storage credential.
4242

@@ -123,11 +123,10 @@
123123
.. code-block::
124124
125125
from databricks.sdk import WorkspaceClient
126-
from databricks.sdk.service import catalog
127126
128127
w = WorkspaceClient()
129128
130-
all = w.storage_credentials.list(catalog.ListStorageCredentialsRequest())
129+
all = w.storage_credentials.list()
131130
132131
Gets an array of storage credentials (as __StorageCredentialInfo__ objects). The array is limited to
133132
only those storage credentials the caller has permission to access. If the caller is a metastore

docs/workspace/catalog/tables.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
157157
created_schema = w.schemas.create(name=f"sdk-{time.time_ns()}", catalog_name=created_catalog.name)
158158
159-
summaries = w.tables.list_summaries(catalog_name=created_catalog.name, schema_name_pattern=created_schema.name)
159+
all_tables = w.tables.list(catalog_name=created_catalog.name, schema_name=created_schema.name)
160160
161161
# cleanup
162162
w.schemas.delete(full_name=created_schema.full_name)

docs/workspace/files/files.rst

Lines changed: 66 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
==================
33
.. currentmodule:: databricks.sdk.service.files
44

5-
.. py:class:: FilesAPI
5+
.. py:class:: FilesExt
66
77
The Files API is a standard HTTP API that allows you to read, write, list, and delete files and
88
directories by referring to their URI. The API makes working with file content as raw bytes easier and
@@ -61,15 +61,39 @@
6161

6262
.. py:method:: download(file_path: str) -> DownloadResponse
6363
64-
Downloads a file. The file contents are the response body. This is a standard HTTP file download, not
65-
a JSON RPC. It supports the Range and If-Unmodified-Since HTTP headers.
64+
Download a file.
65+
66+
Downloads a file of any size. The file contents are the response body.
67+
This is a standard HTTP file download, not a JSON RPC.
68+
69+
It is strongly recommended, for fault tolerance reasons,
70+
to iteratively consume from the stream with a maximum read(size)
71+
defined instead of using indefinite-size reads.
6672

6773
:param file_path: str
68-
The absolute path of the file.
74+
The remote path of the file, e.g. /Volumes/path/to/your/file
6975

7076
:returns: :class:`DownloadResponse`
7177

7278

79+
.. py:method:: download_to(file_path: str, destination: str [, overwrite: bool = True, use_parallel: bool = False, parallelism: Optional[int]]) -> DownloadFileResult
80+
81+
Download a file to a local path. There would be no responses returned if the download is successful.
82+
83+
:param file_path: str
84+
The remote path of the file, e.g. /Volumes/path/to/your/file
85+
:param destination: str
86+
The local path where the file will be saved.
87+
:param overwrite: bool
88+
If true, an existing file will be overwritten. When not specified, assumed True.
89+
:param use_parallel: bool
90+
If true, the download will be performed using multiple threads.
91+
:param parallelism: int
92+
The number of parallel threads to use for downloading. If not specified, defaults to the number of CPU cores.
93+
94+
:returns: :class:`DownloadFileResult`
95+
96+
7397
.. py:method:: get_directory_metadata(directory_path: str)
7498
7599
Get the metadata of a directory. The response HTTP headers contain the metadata. There is no response
@@ -124,19 +148,48 @@
124148
:returns: Iterator over :class:`DirectoryEntry`
125149

126150

127-
.. py:method:: upload(file_path: str, contents: BinaryIO [, overwrite: Optional[bool]])
151+
.. py:method:: upload(file_path: str, content: BinaryIO [, overwrite: Optional[bool], part_size: Optional[int], use_parallel: bool = True, parallelism: Optional[int]]) -> UploadStreamResult
128152
129-
Uploads a file of up to 5 GiB. The file contents should be sent as the request body as raw bytes (an
130-
octet stream); do not encode or otherwise modify the bytes before sending. The contents of the
131-
resulting file will be exactly the bytes sent in the request body. If the request is successful, there
132-
is no response body.
153+
154+
Upload a file with stream interface.
133155

134156
:param file_path: str
135-
The absolute path of the file.
136-
:param contents: BinaryIO
157+
The absolute remote path of the target file, e.g. /Volumes/path/to/your/file
158+
:param content: BinaryIO
159+
The contents of the file to upload. This must be a BinaryIO stream.
137160
:param overwrite: bool (optional)
138-
If true or unspecified, an existing file will be overwritten. If false, an error will be returned if
139-
the path points to an existing file.
161+
If true, an existing file will be overwritten. When not specified, assumed True.
162+
:param part_size: int (optional)
163+
If set, multipart upload will use the value as its size per uploading part.
164+
:param use_parallel: bool (optional)
165+
If true, the upload will be performed using multiple threads. Be aware that this will consume more memory
166+
because multiple parts will be buffered in memory before being uploaded. The amount of memory used is proportional
167+
to `parallelism * part_size`.
168+
If false, the upload will be performed in a single thread.
169+
Default is True.
170+
:param parallelism: int (optional)
171+
The number of threads to use for parallel uploads. This is only used if `use_parallel` is True.
172+
173+
:returns: :class:`UploadStreamResult`
174+
140175

176+
.. py:method:: upload_from(file_path: str, source_path: str [, overwrite: Optional[bool], part_size: Optional[int], use_parallel: bool = True, parallelism: Optional[int]]) -> UploadFileResult
141177
178+
Upload a file directly from a local path.
179+
180+
:param file_path: str
181+
The absolute remote path of the target file.
182+
:param source_path: str
183+
The local path of the file to upload. This must be a path to a local file.
184+
:param part_size: int
185+
The size of each part in bytes for multipart upload. This is a required parameter for multipart uploads.
186+
:param overwrite: bool (optional)
187+
If true, an existing file will be overwritten. When not specified, assumed True.
188+
:param use_parallel: bool (optional)
189+
If true, the upload will be performed using multiple threads. Default is True.
190+
:param parallelism: int (optional)
191+
The number of threads to use for parallel uploads. This is only used if `use_parallel` is True.
192+
If not specified, the default parallelism will be set to config.multipart_upload_default_parallelism
193+
194+
:returns: :class:`UploadFileResult`
142195

docs/workspace/iam/permissions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
4545
obj = w.workspace.get_status(path=notebook_path)
4646
47-
_ = w.permissions.get(request_object_type="notebooks", request_object_id="%d" % (obj.object_id))
47+
levels = w.permissions.get_permission_levels(request_object_type="notebooks", request_object_id="%d" % (obj.object_id))
4848
4949
Gets the permissions of an object. Objects can inherit permissions from their parent objects or root
5050
object.

docs/workspace/ml/model_registry.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
121121
model = w.model_registry.create_model(name=f"sdk-{time.time_ns()}")
122122
123-
created = w.model_registry.create_model_version(name=model.registered_model.name, source="dbfs:/tmp")
123+
mv = w.model_registry.create_model_version(name=model.registered_model.name, source="dbfs:/tmp")
124124
125125
Creates a model version.
126126

@@ -734,13 +734,14 @@
734734
735735
w = WorkspaceClient()
736736
737-
created = w.model_registry.create_model(name=f"sdk-{time.time_ns()}")
737+
model = w.model_registry.create_model(name=f"sdk-{time.time_ns()}")
738738
739-
model = w.model_registry.get_model(name=created.registered_model.name)
739+
created = w.model_registry.create_model_version(name=model.registered_model.name, source="dbfs:/tmp")
740740
741-
w.model_registry.update_model(
742-
name=model.registered_model_databricks.name,
741+
w.model_registry.update_model_version(
743742
description=f"sdk-{time.time_ns()}",
743+
name=created.model_version.name,
744+
version=created.model_version.version,
744745
)
745746
746747
Updates a registered model.

docs/workspace/sharing/providers.rst

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,25 +101,12 @@
101101

102102
.. code-block::
103103
104-
import time
105-
106104
from databricks.sdk import WorkspaceClient
105+
from databricks.sdk.service import sharing
107106
108107
w = WorkspaceClient()
109108
110-
public_share_recipient = """{
111-
"shareCredentialsVersion":1,
112-
"bearerToken":"dapiabcdefghijklmonpqrstuvwxyz",
113-
"endpoint":"https://sharing.delta.io/delta-sharing/"
114-
}
115-
"""
116-
117-
created = w.providers.create(name=f"sdk-{time.time_ns()}", recipient_profile_str=public_share_recipient)
118-
119-
shares = w.providers.list_shares(name=created.name)
120-
121-
# cleanup
122-
w.providers.delete(name=created.name)
109+
all = w.providers.list(sharing.ListProvidersRequest())
123110
124111
Gets an array of available authentication providers. The caller must either be a metastore admin or
125112
the owner of the providers. Providers not owned by the caller are not included in the response. There

0 commit comments

Comments
 (0)