Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

Commit 33935e7

Browse files
Merge branch 'main' of https://github.com/databricks/databricks-sdk-py into update-main
2 parents 57b7b90 + d3b85cb commit 33935e7

File tree

195 files changed

+17021
-4747
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

195 files changed

+17021
-4747
lines changed

.codegen.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"formatter": "yapf -pri $FILENAMES && autoflake -i $FILENAMES && isort $FILENAMES",
3+
"changelog_config": ".codegen/changelog_config.yml",
34
"template_libraries": [
45
".codegen/lib.tmpl"
56
],

.codegen/__init__.py.tmpl

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@ from databricks.sdk.credentials_provider import CredentialsStrategy
55
from databricks.sdk.mixins.files import DbfsExt
66
from databricks.sdk.mixins.compute import ClustersExt
77
from databricks.sdk.mixins.workspace import WorkspaceExt
8-
{{- range .Services}} {{if not .IsDataPlane}}
9-
from databricks.sdk.service.{{.Package.Name}} import {{.PascalName}}API{{end}}{{end}}
8+
from databricks.sdk.mixins.open_ai_client import ServingEndpointsExt
9+
{{- range .Services}}
10+
from databricks.sdk.service.{{.Package.Name}} import {{.PascalName}}API{{end}}
1011
from databricks.sdk.service.provisioning import Workspace
1112
from databricks.sdk import azure
13+
from typing import Optional
1214

1315
{{$args := list "host" "account_id" "username" "password" "client_id" "client_secret"
1416
"token" "profile" "config_file" "azure_workspace_resource_id" "azure_client_secret"
1517
"azure_client_id" "azure_tenant_id" "azure_environment" "auth_type" "cluster_id"
1618
"google_credentials" "google_service_account" }}
1719

1820
{{- define "api" -}}
19-
{{- $mixins := dict "ClustersAPI" "ClustersExt" "DbfsAPI" "DbfsExt" "WorkspaceAPI" "WorkspaceExt" -}}
21+
{{- $mixins := dict "ClustersAPI" "ClustersExt" "DbfsAPI" "DbfsExt" "WorkspaceAPI" "WorkspaceExt" "ServingEndpointsAPI" "ServingEndpointsExt" -}}
2022
{{- $genApi := concat .PascalName "API" -}}
2123
{{- getOrDefault $mixins $genApi $genApi -}}
2224
{{- end -}}
@@ -41,14 +43,14 @@ class WorkspaceClient:
4143
"""
4244
The WorkspaceClient is a client for the workspace-level Databricks REST API.
4345
"""
44-
def __init__(self, *{{range $args}}, {{.}}: str = None{{end}},
45-
debug_truncate_bytes: int = None,
46-
debug_headers: bool = None,
46+
def __init__(self, *{{range $args}}, {{.}}: Optional[str] = None{{end}},
47+
debug_truncate_bytes: Optional[int] = None,
48+
debug_headers: Optional[bool] = None,
4749
product="unknown",
4850
product_version="0.0.0",
49-
credentials_strategy: CredentialsStrategy = None,
50-
credentials_provider: CredentialsStrategy = None,
51-
config: client.Config = None):
51+
credentials_strategy: Optional[CredentialsStrategy] = None,
52+
credentials_provider: Optional[CredentialsStrategy] = None,
53+
config: Optional[client.Config] = None):
5254
if not config:
5355
config = client.Config({{range $args}}{{.}}={{.}}, {{end}}
5456
credentials_strategy=credentials_strategy,
@@ -61,8 +63,20 @@ class WorkspaceClient:
6163
self._dbutils = _make_dbutils(self._config)
6264
self._api_client = client.ApiClient(self._config)
6365

64-
{{- range .Services}}{{if and (not .IsAccounts) (not .HasParent) (not .IsDataPlane)}}
65-
self._{{.SnakeName}} = {{template "api" .}}(self._api_client){{end -}}{{end}}
66+
{{- range .Services}}{{if and (not .IsAccounts) (not .HasParent) .HasDataPlaneAPI (not .IsDataPlane)}}
67+
{{.SnakeName}} = {{template "api" .}}(self._api_client){{end -}}{{end}}
68+
69+
{{- range .Services}}
70+
{{- if and (not .IsAccounts) (not .HasParent)}}
71+
{{- if .IsDataPlane}}
72+
self._{{.SnakeName}} = {{template "api" .}}(self._api_client, {{.ControlPlaneService.SnakeName}})
73+
{{- else if .HasDataPlaneAPI}}
74+
self._{{.SnakeName}} = {{.SnakeName}}
75+
{{- else}}
76+
self._{{.SnakeName}} = {{template "api" .}}(self._api_client)
77+
{{- end -}}
78+
{{- end -}}
79+
{{end}}
6680

6781
@property
6882
def config(self) -> client.Config:
@@ -76,7 +90,7 @@ class WorkspaceClient:
7690
def dbutils(self) -> dbutils.RemoteDbUtils:
7791
return self._dbutils
7892

79-
{{- range .Services}}{{if and (not .IsAccounts) (not .HasParent) (not .IsDataPlane)}}
93+
{{- range .Services}}{{if and (not .IsAccounts) (not .HasParent)}}
8094
@property
8195
def {{.SnakeName}}(self) -> {{template "api" .}}:
8296
{{if .Description}}"""{{.Summary}}"""{{end}}
@@ -98,14 +112,14 @@ class AccountClient:
98112
The AccountClient is a client for the account-level Databricks REST API.
99113
"""
100114

101-
def __init__(self, *{{range $args}}, {{.}}: str = None{{end}},
102-
debug_truncate_bytes: int = None,
103-
debug_headers: bool = None,
115+
def __init__(self, *{{range $args}}, {{.}}: Optional[str] = None{{end}},
116+
debug_truncate_bytes: Optional[int] = None,
117+
debug_headers: Optional[bool] = None,
104118
product="unknown",
105119
product_version="0.0.0",
106-
credentials_strategy: CredentialsStrategy = None,
107-
credentials_provider: CredentialsStrategy = None,
108-
config: client.Config = None):
120+
credentials_strategy: Optional[CredentialsStrategy] = None,
121+
credentials_provider: Optional[CredentialsStrategy] = None,
122+
config: Optional[client.Config] = None):
109123
if not config:
110124
config = client.Config({{range $args}}{{.}}={{.}}, {{end}}
111125
credentials_strategy=credentials_strategy,
@@ -117,8 +131,20 @@ class AccountClient:
117131
self._config = config.copy()
118132
self._api_client = client.ApiClient(self._config)
119133

120-
{{- range .Services}}{{if and .IsAccounts (not .HasParent) (not .IsDataPlane)}}
121-
self._{{(.TrimPrefix "account").SnakeName}} = {{template "api" .}}(self._api_client){{end -}}{{end}}
134+
{{- range .Services}}{{if and .IsAccounts (not .HasParent) .HasDataPlaneAPI (not .IsDataPlane)}}
135+
{{(.TrimPrefix "account").SnakeName}} = {{template "api" .}}(self._api_client){{end -}}{{end}}
136+
137+
{{- range .Services}}
138+
{{- if and .IsAccounts (not .HasParent)}}
139+
{{- if .IsDataPlane}}
140+
self._{{(.TrimPrefix "account").SnakeName}} = {{template "api" .}}(self._api_client, {{.ControlPlaneService.SnakeName}})
141+
{{- else if .HasDataPlaneAPI}}
142+
self._{{(.TrimPrefix "account").SnakeName}} = {{(.TrimPrefix "account").SnakeName}}
143+
{{- else}}
144+
self._{{(.TrimPrefix "account").SnakeName}} = {{template "api" .}}(self._api_client)
145+
{{- end -}}
146+
{{- end -}}
147+
{{end}}
122148

123149
@property
124150
def config(self) -> client.Config:
@@ -128,7 +154,7 @@ class AccountClient:
128154
def api_client(self) -> client.ApiClient:
129155
return self._api_client
130156

131-
{{- range .Services}}{{if and .IsAccounts (not .HasParent) (not .IsDataPlane)}}
157+
{{- range .Services}}{{if and .IsAccounts (not .HasParent)}}
132158
@property
133159
def {{(.TrimPrefix "account").SnakeName}}(self) -> {{template "api" .}}:{{if .Description}}
134160
"""{{.Summary}}"""{{end}}

.codegen/_openapi_sha

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7437dabb9dadee402c1fc060df4c1ce8cc5369f0
1+
cf9c61453990df0f9453670f2fe68e1b128647a2

.codegen/changelog.md.tmpl

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
# Version changelog
22

33
## {{.Version}}
4+
{{- range .GroupChanges}}
45

5-
{{range .Changes -}}
6+
### {{.Type.Message}}
7+
{{range .Changes}}
68
* {{.}}.
7-
{{end}}{{- if .ApiChanges}}
8-
API Changes:
9-
{{range .ApiChanges}}
10-
* {{.Action}} {{template "what" .}}{{if .Extra}} {{.Extra}}{{with .Other}} {{template "what" .}}{{end}}{{end}}.
9+
{{- end}}
10+
{{end}}
11+
{{if .ApiChanges}}
12+
### API Changes:
13+
{{range .ApiChanges.GroupDiff}}
14+
* {{.Action}} {{template "group-what" .}}{{if .Extra}} {{.Extra}}{{with .Other}} {{template "other-what" .}}{{end}}{{end}}.
1115
{{- end}}
1216

1317
OpenAPI SHA: {{.Sha}}, Date: {{.Changed}}
@@ -20,7 +24,35 @@ Dependency updates:
2024

2125
## {{.PrevVersion}}
2226

23-
{{- define "what" -}}
27+
{{- define "group-what" -}}
28+
{{if gt (len .Changes) 1 -}} {{template "single-what" .Changes.First}}{{end -}}
29+
{{range .Changes.Middle -}}, {{template "single-what" .}}{{end -}}
30+
{{if gt (len .Changes) 1}} and {{end}}{{template "single-what" .Changes.Last}}{{template "suffix-what" .}}
31+
{{- end -}}
32+
33+
{{- define "single-what" -}}
34+
{{if eq .X "package" -}}
35+
`databricks.sdk.service.{{.Package.Name}}`
36+
{{- else if eq .X "service" -}}
37+
{{template "service" .Service}}
38+
{{- else if eq .X "method" -}}
39+
`{{.Method.SnakeName}}()`
40+
{{- else if eq .X "entity" -}}
41+
{{template "entity" .Entity}}
42+
{{- else if eq .X "field" -}}
43+
`{{.Field.SnakeName}}`
44+
{{- end}}
45+
{{- end -}}
46+
47+
{{- define "suffix-what" -}}
48+
{{if eq .Type "package" }} package{{if gt (len .Changes) 1}}s{{end}}
49+
{{- else if eq .Type "method" }} method{{if gt (len .Changes) 1}}s{{end}} for {{template "service" .Parent.Service}}
50+
{{- else if eq .Type "entity" }} dataclass{{if gt (len .Changes) 1}}es{{end}}
51+
{{- else if eq .Type "field" }} field{{if gt (len .Changes) 1}}s{{end}} for {{template "entity" .Parent.Entity}}
52+
{{- end}}
53+
{{- end -}}
54+
55+
{{- define "other-what" -}}
2456
{{if eq .X "package" -}}
2557
`databricks.sdk.service.{{.Package.Name}}` package
2658
{{- else if eq .X "service" -}}

.codegen/changelog_config.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
change_types:
2+
- message: New Features and Improvements
3+
tag: "[Feature]"
4+
- message: Bug Fixes
5+
tag: "[Fix]"
6+
- message: Documentation
7+
tag: "[Doc]"
8+
- message: Internal Changes
9+
tag: "[Internal]"
10+
# Does not appear in the Changelog. Only for PR validation.
11+
- message: Release
12+
tag: "[Release]"
13+
# Default for messages without a tag
14+
- message: Other Changes

.codegen/error_overrides.py.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ _ALL_OVERRIDES = [
1111
debug_name="{{.Name}}",
1212
path_regex=re.compile(r'{{.PathRegex}}'),
1313
verb="{{.Verb}}",
14-
status_code_matcher=re.compile(r'{{.StatusCodeMatcher}}'),
15-
error_code_matcher=re.compile(r'{{.ErrorCodeMatcher}}'),
16-
message_matcher=re.compile(r'{{.MessageMatcher}}'),
14+
status_code_matcher=re.compile(r'{{replaceAll "'" "\\'" .StatusCodeMatcher}}'),
15+
error_code_matcher=re.compile(r'{{replaceAll "'" "\\'" .ErrorCodeMatcher}}'),
16+
message_matcher=re.compile(r'{{replaceAll "'" "\\'" .MessageMatcher}}'),
1717
custom_error={{.OverrideErrorCode.PascalName}},
1818
),
1919
{{- end }}

.codegen/service.py.tmpl

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ from typing import Dict, List, Any, Iterator, Type, Callable, Optional, BinaryIO
88
import time
99
import random
1010
import logging
11+
import requests
12+
13+
from ..data_plane import DataPlaneService
1114
from ..errors import OperationTimeout, OperationFailed
1215
from ._internal import _enum, _from_dict, _repeated_dict, _repeated_enum, Wait, _escape_multi_segment_path_parameter
16+
from ..oauth import Token
1317

1418
_LOG = logging.getLogger('databricks.sdk')
1519

@@ -100,12 +104,16 @@ class {{.PascalName}}{{if eq "List" .PascalName}}Request{{end}}:{{if .Descriptio
100104
{{- end -}}
101105
{{- end -}}
102106

103-
{{range .Services}} {{if not .IsDataPlane}}
107+
{{range .Services}}
104108
class {{.PascalName}}API:{{if .Description}}
105109
"""{{.Comment " " 110}}"""
106110
{{end}}
107-
def __init__(self, api_client):
111+
def __init__(self, api_client{{if .IsDataPlane}}, control_plane{{end}}):
108112
self._api = api_client
113+
{{if .IsDataPlane -}}
114+
self._control_plane = control_plane
115+
self._data_plane_service = DataPlaneService()
116+
{{end -}}
109117
{{range .Subservices}}
110118
self._{{.SnakeName}} = {{.PascalName}}API(self._api){{end}}
111119

@@ -183,6 +191,9 @@ class {{.PascalName}}API:{{if .Description}}
183191
{{if .Request -}}
184192
{{template "method-serialize" .}}
185193
{{- end}}
194+
{{- if .Service.IsDataPlane}}
195+
{{template "data-plane" .}}
196+
{{- end}}
186197
{{template "method-headers" . }}
187198
{{if .Response.HasHeaderField -}}
188199
{{template "method-response-headers" . }}
@@ -195,7 +206,27 @@ class {{.PascalName}}API:{{if .Description}}
195206
return self.{{template "safe-snake-name" .}}({{range $i, $x := .Request.Fields}}{{if $i}}, {{end}}{{template "safe-snake-name" .}}={{template "safe-snake-name" .}}{{end}}).result(timeout=timeout)
196207
{{end}}
197208
{{end -}}
198-
{{end}}
209+
{{- end}}
210+
211+
{{define "data-plane" -}}
212+
def info_getter():
213+
response = self._control_plane.{{.Service.DataPlaneInfoMethod.SnakeName}}(
214+
{{- range .Service.DataPlaneInfoMethod.Request.Fields }}
215+
{{.SnakeName}} = {{.SnakeName}},
216+
{{- end}}
217+
)
218+
if response.{{(index .DataPlaneInfoFields 0).SnakeName}} is None:
219+
raise Exception("Resource does not support direct Data Plane access")
220+
return response{{range .DataPlaneInfoFields}}.{{.SnakeName}}{{end}}
221+
222+
get_params = [{{- range .Service.DataPlaneInfoMethod.Request.Fields }}{{.SnakeName}},{{end}}]
223+
data_plane_details = self._data_plane_service.get_data_plane_details('{{.SnakeName}}', get_params, info_getter, self._api.get_oauth_token)
224+
token = data_plane_details.token
225+
226+
def auth(r: requests.PreparedRequest) -> requests.PreparedRequest:
227+
authorization = f"{token.token_type} {token.access_token}"
228+
r.headers["Authorization"] = authorization
229+
return r
199230
{{- end}}
200231

201232
{{define "method-parameters" -}}
@@ -264,7 +295,7 @@ class {{.PascalName}}API:{{if .Description}}
264295
{{if .NeedsOffsetDedupe -}}
265296
# deduplicate items that may have been added during iteration
266297
seen = set()
267-
{{- end}}{{if and .Pagination.Offset (not (eq .Path "/api/2.0/clusters/events")) }}
298+
{{- end}}{{if and .Pagination.Offset (not (eq .Path "/api/2.1/clusters/events")) }}
268299
query['{{.Pagination.Offset.Name}}'] =
269300
{{- if eq .Pagination.Increment 1 -}}
270301
1
@@ -290,7 +321,7 @@ class {{.PascalName}}API:{{if .Description}}
290321
if '{{.Pagination.Token.Bind.Name}}' not in json or not json['{{.Pagination.Token.Bind.Name}}']:
291322
return
292323
{{if or (eq "GET" .Verb) (eq "HEAD" .Verb)}}query{{else}}body{{end}}['{{.Pagination.Token.PollField.Name}}'] = json['{{.Pagination.Token.Bind.Name}}']
293-
{{- else if eq .Path "/api/2.0/clusters/events" -}}
324+
{{- else if eq .Path "/api/2.1/clusters/events" -}}
294325
if 'next_page' not in json or not json['next_page']:
295326
return
296327
body = json['next_page']
@@ -319,25 +350,32 @@ class {{.PascalName}}API:{{if .Description}}
319350
{{- else if .Response.MapValue -}}
320351
return res
321352
{{- else -}}
322-
return {{.Response.PascalName}}.from_dict(res)
353+
return {{template "type" .Response}}.from_dict(res)
323354
{{- end}}
324355
{{- end}}
325356
{{- end}}
326357

327358
{{define "method-do" -}}
328-
self._api.do('{{.Verb}}',
329-
{{ template "path" . }}
330-
{{if .Request}}
331-
{{- if .Request.HasQueryField}}, query=query{{end}}
332-
{{- if .Request.MapValue}}, body=contents
333-
{{- else if .Request.HasJsonField}}, body=body{{end}}
334-
{{end}}
335-
, headers=headers
336-
{{if .Response.HasHeaderField -}}
337-
, response_headers=response_headers
338-
{{- end}}
339-
{{- if and .IsRequestByteStream .RequestBodyField }}, data={{template "safe-snake-name" .RequestBodyField}}{{ end }}
340-
{{- if .IsResponseByteStream }}, raw=True{{ end }})
359+
self._api.do('{{.Verb}}',
360+
{{- if .Service.IsDataPlane -}}
361+
url=data_plane_details.endpoint_url
362+
{{- else -}}
363+
{{ template "path" . }}
364+
{{- end -}}
365+
{{if .Request}}
366+
{{- if .Request.HasQueryField}}, query=query{{end}}
367+
{{- if .Request.MapValue}}, body=contents
368+
{{- else if .Request.HasJsonField}}, body=body{{end}}
369+
{{end}}
370+
, headers=headers
371+
{{if .Response.HasHeaderField -}}
372+
, response_headers=response_headers
373+
{{- end}}
374+
{{- if and .IsRequestByteStream .RequestBodyField }}, data={{template "safe-snake-name" .RequestBodyField}}{{ end }}
375+
{{- if .Service.IsDataPlane -}}
376+
,auth=auth
377+
{{- end -}}
378+
{{- if .IsResponseByteStream }}, raw=True{{ end }})
341379
{{- end}}
342380

343381
{{- define "path" -}}

0 commit comments

Comments
 (0)