google-developer-knowledge 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. google/developer_knowledge/__init__.py +49 -0
  2. google/developer_knowledge/gapic_version.py +16 -0
  3. google/developer_knowledge/py.typed +2 -0
  4. google/developer_knowledge_v1/__init__.py +135 -0
  5. google/developer_knowledge_v1/gapic_metadata.json +73 -0
  6. google/developer_knowledge_v1/gapic_version.py +16 -0
  7. google/developer_knowledge_v1/py.typed +2 -0
  8. google/developer_knowledge_v1/services/__init__.py +15 -0
  9. google/developer_knowledge_v1/services/developer_knowledge/__init__.py +22 -0
  10. google/developer_knowledge_v1/services/developer_knowledge/async_client.py +642 -0
  11. google/developer_knowledge_v1/services/developer_knowledge/client.py +1067 -0
  12. google/developer_knowledge_v1/services/developer_knowledge/pagers.py +201 -0
  13. google/developer_knowledge_v1/services/developer_knowledge/transports/__init__.py +36 -0
  14. google/developer_knowledge_v1/services/developer_knowledge/transports/base.py +227 -0
  15. google/developer_knowledge_v1/services/developer_knowledge/transports/grpc.py +449 -0
  16. google/developer_knowledge_v1/services/developer_knowledge/transports/grpc_asyncio.py +502 -0
  17. google/developer_knowledge_v1/services/developer_knowledge/transports/rest.py +855 -0
  18. google/developer_knowledge_v1/services/developer_knowledge/transports/rest_base.py +236 -0
  19. google/developer_knowledge_v1/types/__init__.py +36 -0
  20. google/developer_knowledge_v1/types/developerknowledge.py +413 -0
  21. google_developer_knowledge-0.1.0.dist-info/METADATA +240 -0
  22. google_developer_knowledge-0.1.0.dist-info/RECORD +25 -0
  23. google_developer_knowledge-0.1.0.dist-info/WHEEL +5 -0
  24. google_developer_knowledge-0.1.0.dist-info/licenses/LICENSE +202 -0
  25. google_developer_knowledge-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,855 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2026 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ import dataclasses
17
+ import json # type: ignore
18
+ import logging
19
+ import warnings
20
+ from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
21
+
22
+ import google.protobuf
23
+ from google.api_core import exceptions as core_exceptions
24
+ from google.api_core import gapic_v1, rest_helpers, rest_streaming
25
+ from google.api_core import retry as retries
26
+ from google.auth import credentials as ga_credentials # type: ignore
27
+ from google.auth.transport.requests import AuthorizedSession # type: ignore
28
+ from google.protobuf import json_format
29
+ from requests import __version__ as requests_version
30
+
31
+ from google.developer_knowledge_v1.types import developerknowledge
32
+
33
+ from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO
34
+ from .rest_base import _BaseDeveloperKnowledgeRestTransport
35
+
36
+ try:
37
+ OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]
38
+ except AttributeError: # pragma: NO COVER
39
+ OptionalRetry = Union[retries.Retry, object, None] # type: ignore
40
+
41
+ try:
42
+ from google.api_core import client_logging # type: ignore
43
+
44
+ CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
45
+ except ImportError: # pragma: NO COVER
46
+ CLIENT_LOGGING_SUPPORTED = False
47
+
48
+ _LOGGER = logging.getLogger(__name__)
49
+
50
+ DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
51
+ gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version,
52
+ grpc_version=None,
53
+ rest_version=f"requests@{requests_version}",
54
+ )
55
+
56
+ if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER
57
+ DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__
58
+
59
+
60
+ class DeveloperKnowledgeRestInterceptor:
61
+ """Interceptor for DeveloperKnowledge.
62
+
63
+ Interceptors are used to manipulate requests, request metadata, and responses
64
+ in arbitrary ways.
65
+ Example use cases include:
66
+ * Logging
67
+ * Verifying requests according to service or custom semantics
68
+ * Stripping extraneous information from responses
69
+
70
+ These use cases and more can be enabled by injecting an
71
+ instance of a custom subclass when constructing the DeveloperKnowledgeRestTransport.
72
+
73
+ .. code-block:: python
74
+ class MyCustomDeveloperKnowledgeInterceptor(DeveloperKnowledgeRestInterceptor):
75
+ def pre_batch_get_documents(self, request, metadata):
76
+ logging.log(f"Received request: {request}")
77
+ return request, metadata
78
+
79
+ def post_batch_get_documents(self, response):
80
+ logging.log(f"Received response: {response}")
81
+ return response
82
+
83
+ def pre_get_document(self, request, metadata):
84
+ logging.log(f"Received request: {request}")
85
+ return request, metadata
86
+
87
+ def post_get_document(self, response):
88
+ logging.log(f"Received response: {response}")
89
+ return response
90
+
91
+ def pre_search_document_chunks(self, request, metadata):
92
+ logging.log(f"Received request: {request}")
93
+ return request, metadata
94
+
95
+ def post_search_document_chunks(self, response):
96
+ logging.log(f"Received response: {response}")
97
+ return response
98
+
99
+ transport = DeveloperKnowledgeRestTransport(interceptor=MyCustomDeveloperKnowledgeInterceptor())
100
+ client = DeveloperKnowledgeClient(transport=transport)
101
+
102
+
103
+ """
104
+
105
+ def pre_batch_get_documents(
106
+ self,
107
+ request: developerknowledge.BatchGetDocumentsRequest,
108
+ metadata: Sequence[Tuple[str, Union[str, bytes]]],
109
+ ) -> Tuple[
110
+ developerknowledge.BatchGetDocumentsRequest,
111
+ Sequence[Tuple[str, Union[str, bytes]]],
112
+ ]:
113
+ """Pre-rpc interceptor for batch_get_documents
114
+
115
+ Override in a subclass to manipulate the request or metadata
116
+ before they are sent to the DeveloperKnowledge server.
117
+ """
118
+ return request, metadata
119
+
120
+ def post_batch_get_documents(
121
+ self, response: developerknowledge.BatchGetDocumentsResponse
122
+ ) -> developerknowledge.BatchGetDocumentsResponse:
123
+ """Post-rpc interceptor for batch_get_documents
124
+
125
+ DEPRECATED. Please use the `post_batch_get_documents_with_metadata`
126
+ interceptor instead.
127
+
128
+ Override in a subclass to read or manipulate the response
129
+ after it is returned by the DeveloperKnowledge server but before
130
+ it is returned to user code. This `post_batch_get_documents` interceptor runs
131
+ before the `post_batch_get_documents_with_metadata` interceptor.
132
+ """
133
+ return response
134
+
135
+ def post_batch_get_documents_with_metadata(
136
+ self,
137
+ response: developerknowledge.BatchGetDocumentsResponse,
138
+ metadata: Sequence[Tuple[str, Union[str, bytes]]],
139
+ ) -> Tuple[
140
+ developerknowledge.BatchGetDocumentsResponse,
141
+ Sequence[Tuple[str, Union[str, bytes]]],
142
+ ]:
143
+ """Post-rpc interceptor for batch_get_documents
144
+
145
+ Override in a subclass to read or manipulate the response or metadata after it
146
+ is returned by the DeveloperKnowledge server but before it is returned to user code.
147
+
148
+ We recommend only using this `post_batch_get_documents_with_metadata`
149
+ interceptor in new development instead of the `post_batch_get_documents` interceptor.
150
+ When both interceptors are used, this `post_batch_get_documents_with_metadata` interceptor runs after the
151
+ `post_batch_get_documents` interceptor. The (possibly modified) response returned by
152
+ `post_batch_get_documents` will be passed to
153
+ `post_batch_get_documents_with_metadata`.
154
+ """
155
+ return response, metadata
156
+
157
+ def pre_get_document(
158
+ self,
159
+ request: developerknowledge.GetDocumentRequest,
160
+ metadata: Sequence[Tuple[str, Union[str, bytes]]],
161
+ ) -> Tuple[
162
+ developerknowledge.GetDocumentRequest, Sequence[Tuple[str, Union[str, bytes]]]
163
+ ]:
164
+ """Pre-rpc interceptor for get_document
165
+
166
+ Override in a subclass to manipulate the request or metadata
167
+ before they are sent to the DeveloperKnowledge server.
168
+ """
169
+ return request, metadata
170
+
171
+ def post_get_document(
172
+ self, response: developerknowledge.Document
173
+ ) -> developerknowledge.Document:
174
+ """Post-rpc interceptor for get_document
175
+
176
+ DEPRECATED. Please use the `post_get_document_with_metadata`
177
+ interceptor instead.
178
+
179
+ Override in a subclass to read or manipulate the response
180
+ after it is returned by the DeveloperKnowledge server but before
181
+ it is returned to user code. This `post_get_document` interceptor runs
182
+ before the `post_get_document_with_metadata` interceptor.
183
+ """
184
+ return response
185
+
186
+ def post_get_document_with_metadata(
187
+ self,
188
+ response: developerknowledge.Document,
189
+ metadata: Sequence[Tuple[str, Union[str, bytes]]],
190
+ ) -> Tuple[developerknowledge.Document, Sequence[Tuple[str, Union[str, bytes]]]]:
191
+ """Post-rpc interceptor for get_document
192
+
193
+ Override in a subclass to read or manipulate the response or metadata after it
194
+ is returned by the DeveloperKnowledge server but before it is returned to user code.
195
+
196
+ We recommend only using this `post_get_document_with_metadata`
197
+ interceptor in new development instead of the `post_get_document` interceptor.
198
+ When both interceptors are used, this `post_get_document_with_metadata` interceptor runs after the
199
+ `post_get_document` interceptor. The (possibly modified) response returned by
200
+ `post_get_document` will be passed to
201
+ `post_get_document_with_metadata`.
202
+ """
203
+ return response, metadata
204
+
205
+ def pre_search_document_chunks(
206
+ self,
207
+ request: developerknowledge.SearchDocumentChunksRequest,
208
+ metadata: Sequence[Tuple[str, Union[str, bytes]]],
209
+ ) -> Tuple[
210
+ developerknowledge.SearchDocumentChunksRequest,
211
+ Sequence[Tuple[str, Union[str, bytes]]],
212
+ ]:
213
+ """Pre-rpc interceptor for search_document_chunks
214
+
215
+ Override in a subclass to manipulate the request or metadata
216
+ before they are sent to the DeveloperKnowledge server.
217
+ """
218
+ return request, metadata
219
+
220
+ def post_search_document_chunks(
221
+ self, response: developerknowledge.SearchDocumentChunksResponse
222
+ ) -> developerknowledge.SearchDocumentChunksResponse:
223
+ """Post-rpc interceptor for search_document_chunks
224
+
225
+ DEPRECATED. Please use the `post_search_document_chunks_with_metadata`
226
+ interceptor instead.
227
+
228
+ Override in a subclass to read or manipulate the response
229
+ after it is returned by the DeveloperKnowledge server but before
230
+ it is returned to user code. This `post_search_document_chunks` interceptor runs
231
+ before the `post_search_document_chunks_with_metadata` interceptor.
232
+ """
233
+ return response
234
+
235
+ def post_search_document_chunks_with_metadata(
236
+ self,
237
+ response: developerknowledge.SearchDocumentChunksResponse,
238
+ metadata: Sequence[Tuple[str, Union[str, bytes]]],
239
+ ) -> Tuple[
240
+ developerknowledge.SearchDocumentChunksResponse,
241
+ Sequence[Tuple[str, Union[str, bytes]]],
242
+ ]:
243
+ """Post-rpc interceptor for search_document_chunks
244
+
245
+ Override in a subclass to read or manipulate the response or metadata after it
246
+ is returned by the DeveloperKnowledge server but before it is returned to user code.
247
+
248
+ We recommend only using this `post_search_document_chunks_with_metadata`
249
+ interceptor in new development instead of the `post_search_document_chunks` interceptor.
250
+ When both interceptors are used, this `post_search_document_chunks_with_metadata` interceptor runs after the
251
+ `post_search_document_chunks` interceptor. The (possibly modified) response returned by
252
+ `post_search_document_chunks` will be passed to
253
+ `post_search_document_chunks_with_metadata`.
254
+ """
255
+ return response, metadata
256
+
257
+
258
+ @dataclasses.dataclass
259
+ class DeveloperKnowledgeRestStub:
260
+ _session: AuthorizedSession
261
+ _host: str
262
+ _interceptor: DeveloperKnowledgeRestInterceptor
263
+
264
+
265
+ class DeveloperKnowledgeRestTransport(_BaseDeveloperKnowledgeRestTransport):
266
+ """REST backend synchronous transport for DeveloperKnowledge.
267
+
268
+ The Developer Knowledge API provides programmatic access to Google's
269
+ public developer documentation, enabling you to integrate this
270
+ knowledge base into your own applications and workflows.
271
+
272
+ The API is designed to be the canonical source for machine-readable
273
+ access to Google's developer documentation.
274
+
275
+ A typical use case is to first use
276
+ [DeveloperKnowledge.SearchDocumentChunks][google.developers.knowledge.v1.DeveloperKnowledge.SearchDocumentChunks]
277
+ to find relevant page URIs based on a query, and then use
278
+ [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument]
279
+ or
280
+ [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments]
281
+ to fetch the full content of the top results.
282
+
283
+ All document content is provided in Markdown format.
284
+
285
+ This class defines the same methods as the primary client, so the
286
+ primary client can load the underlying transport implementation
287
+ and call it.
288
+
289
+ It sends JSON representations of protocol buffers over HTTP/1.1
290
+ """
291
+
292
+ def __init__(
293
+ self,
294
+ *,
295
+ host: str = "developerknowledge.googleapis.com",
296
+ credentials: Optional[ga_credentials.Credentials] = None,
297
+ credentials_file: Optional[str] = None,
298
+ scopes: Optional[Sequence[str]] = None,
299
+ client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
300
+ quota_project_id: Optional[str] = None,
301
+ client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
302
+ always_use_jwt_access: Optional[bool] = False,
303
+ url_scheme: str = "https",
304
+ interceptor: Optional[DeveloperKnowledgeRestInterceptor] = None,
305
+ api_audience: Optional[str] = None,
306
+ ) -> None:
307
+ """Instantiate the transport.
308
+
309
+ Args:
310
+ host (Optional[str]):
311
+ The hostname to connect to (default: 'developerknowledge.googleapis.com').
312
+ credentials (Optional[google.auth.credentials.Credentials]): The
313
+ authorization credentials to attach to requests. These
314
+ credentials identify the application to the service; if none
315
+ are specified, the client will attempt to ascertain the
316
+ credentials from the environment.
317
+
318
+ credentials_file (Optional[str]): Deprecated. A file with credentials that can
319
+ be loaded with :func:`google.auth.load_credentials_from_file`.
320
+ This argument is ignored if ``channel`` is provided. This argument will be
321
+ removed in the next major version of this library.
322
+ scopes (Optional(Sequence[str])): A list of scopes. This argument is
323
+ ignored if ``channel`` is provided.
324
+ client_cert_source_for_mtls (Callable[[], Tuple[bytes, bytes]]): Client
325
+ certificate to configure mutual TLS HTTP channel. It is ignored
326
+ if ``channel`` is provided.
327
+ quota_project_id (Optional[str]): An optional project to use for billing
328
+ and quota.
329
+ client_info (google.api_core.gapic_v1.client_info.ClientInfo):
330
+ The client info used to send a user-agent string along with
331
+ API requests. If ``None``, then default info will be used.
332
+ Generally, you only need to set this if you are developing
333
+ your own client library.
334
+ always_use_jwt_access (Optional[bool]): Whether self signed JWT should
335
+ be used for service account credentials.
336
+ url_scheme: the protocol scheme for the API endpoint. Normally
337
+ "https", but for testing or local servers,
338
+ "http" can be specified.
339
+ interceptor (Optional[DeveloperKnowledgeRestInterceptor]): Interceptor used
340
+ to manipulate requests, request metadata, and responses.
341
+ api_audience (Optional[str]): The intended audience for the API calls
342
+ to the service that will be set when using certain 3rd party
343
+ authentication flows. Audience is typically a resource identifier.
344
+ If not set, the host value will be used as a default.
345
+ """
346
+ # Run the base constructor
347
+ # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc.
348
+ # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the
349
+ # credentials object
350
+ super().__init__(
351
+ host=host,
352
+ credentials=credentials,
353
+ client_info=client_info,
354
+ always_use_jwt_access=always_use_jwt_access,
355
+ url_scheme=url_scheme,
356
+ api_audience=api_audience,
357
+ )
358
+ self._session = AuthorizedSession(
359
+ self._credentials, default_host=self.DEFAULT_HOST
360
+ )
361
+ if client_cert_source_for_mtls:
362
+ self._session.configure_mtls_channel(client_cert_source_for_mtls)
363
+ self._interceptor = interceptor or DeveloperKnowledgeRestInterceptor()
364
+ self._prep_wrapped_messages(client_info)
365
+
366
+ class _BatchGetDocuments(
367
+ _BaseDeveloperKnowledgeRestTransport._BaseBatchGetDocuments,
368
+ DeveloperKnowledgeRestStub,
369
+ ):
370
+ def __hash__(self):
371
+ return hash("DeveloperKnowledgeRestTransport.BatchGetDocuments")
372
+
373
+ @staticmethod
374
+ def _get_response(
375
+ host,
376
+ metadata,
377
+ query_params,
378
+ session,
379
+ timeout,
380
+ transcoded_request,
381
+ body=None,
382
+ ):
383
+ uri = transcoded_request["uri"]
384
+ method = transcoded_request["method"]
385
+ headers = dict(metadata)
386
+ headers["Content-Type"] = "application/json"
387
+ response = getattr(session, method)(
388
+ "{host}{uri}".format(host=host, uri=uri),
389
+ timeout=timeout,
390
+ headers=headers,
391
+ params=rest_helpers.flatten_query_params(query_params, strict=True),
392
+ )
393
+ return response
394
+
395
+ def __call__(
396
+ self,
397
+ request: developerknowledge.BatchGetDocumentsRequest,
398
+ *,
399
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
400
+ timeout: Optional[float] = None,
401
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
402
+ ) -> developerknowledge.BatchGetDocumentsResponse:
403
+ r"""Call the batch get documents method over HTTP.
404
+
405
+ Args:
406
+ request (~.developerknowledge.BatchGetDocumentsRequest):
407
+ The request object. Request message for
408
+ [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments].
409
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
410
+ should be retried.
411
+ timeout (float): The timeout for this request.
412
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
413
+ sent along with the request as metadata. Normally, each value must be of type `str`,
414
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
415
+ be of type `bytes`.
416
+
417
+ Returns:
418
+ ~.developerknowledge.BatchGetDocumentsResponse:
419
+ Response message for
420
+ [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments].
421
+
422
+ """
423
+
424
+ http_options = _BaseDeveloperKnowledgeRestTransport._BaseBatchGetDocuments._get_http_options()
425
+
426
+ request, metadata = self._interceptor.pre_batch_get_documents(
427
+ request, metadata
428
+ )
429
+ transcoded_request = _BaseDeveloperKnowledgeRestTransport._BaseBatchGetDocuments._get_transcoded_request(
430
+ http_options, request
431
+ )
432
+
433
+ # Jsonify the query params
434
+ query_params = _BaseDeveloperKnowledgeRestTransport._BaseBatchGetDocuments._get_query_params_json(
435
+ transcoded_request
436
+ )
437
+
438
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
439
+ logging.DEBUG
440
+ ): # pragma: NO COVER
441
+ request_url = "{host}{uri}".format(
442
+ host=self._host, uri=transcoded_request["uri"]
443
+ )
444
+ method = transcoded_request["method"]
445
+ try:
446
+ request_payload = type(request).to_json(request)
447
+ except:
448
+ request_payload = None
449
+ http_request = {
450
+ "payload": request_payload,
451
+ "requestMethod": method,
452
+ "requestUrl": request_url,
453
+ "headers": dict(metadata),
454
+ }
455
+ _LOGGER.debug(
456
+ f"Sending request for google.developers.knowledge_v1.DeveloperKnowledgeClient.BatchGetDocuments",
457
+ extra={
458
+ "serviceName": "google.developers.knowledge.v1.DeveloperKnowledge",
459
+ "rpcName": "BatchGetDocuments",
460
+ "httpRequest": http_request,
461
+ "metadata": http_request["headers"],
462
+ },
463
+ )
464
+
465
+ # Send the request
466
+ response = DeveloperKnowledgeRestTransport._BatchGetDocuments._get_response(
467
+ self._host,
468
+ metadata,
469
+ query_params,
470
+ self._session,
471
+ timeout,
472
+ transcoded_request,
473
+ )
474
+
475
+ # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
476
+ # subclass.
477
+ if response.status_code >= 400:
478
+ raise core_exceptions.from_http_response(response)
479
+
480
+ # Return the response
481
+ resp = developerknowledge.BatchGetDocumentsResponse()
482
+ pb_resp = developerknowledge.BatchGetDocumentsResponse.pb(resp)
483
+
484
+ json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
485
+
486
+ resp = self._interceptor.post_batch_get_documents(resp)
487
+ response_metadata = [(k, str(v)) for k, v in response.headers.items()]
488
+ resp, _ = self._interceptor.post_batch_get_documents_with_metadata(
489
+ resp, response_metadata
490
+ )
491
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
492
+ logging.DEBUG
493
+ ): # pragma: NO COVER
494
+ try:
495
+ response_payload = (
496
+ developerknowledge.BatchGetDocumentsResponse.to_json(response)
497
+ )
498
+ except:
499
+ response_payload = None
500
+ http_response = {
501
+ "payload": response_payload,
502
+ "headers": dict(response.headers),
503
+ "status": response.status_code,
504
+ }
505
+ _LOGGER.debug(
506
+ "Received response for google.developers.knowledge_v1.DeveloperKnowledgeClient.batch_get_documents",
507
+ extra={
508
+ "serviceName": "google.developers.knowledge.v1.DeveloperKnowledge",
509
+ "rpcName": "BatchGetDocuments",
510
+ "metadata": http_response["headers"],
511
+ "httpResponse": http_response,
512
+ },
513
+ )
514
+ return resp
515
+
516
+ class _GetDocument(
517
+ _BaseDeveloperKnowledgeRestTransport._BaseGetDocument,
518
+ DeveloperKnowledgeRestStub,
519
+ ):
520
+ def __hash__(self):
521
+ return hash("DeveloperKnowledgeRestTransport.GetDocument")
522
+
523
+ @staticmethod
524
+ def _get_response(
525
+ host,
526
+ metadata,
527
+ query_params,
528
+ session,
529
+ timeout,
530
+ transcoded_request,
531
+ body=None,
532
+ ):
533
+ uri = transcoded_request["uri"]
534
+ method = transcoded_request["method"]
535
+ headers = dict(metadata)
536
+ headers["Content-Type"] = "application/json"
537
+ response = getattr(session, method)(
538
+ "{host}{uri}".format(host=host, uri=uri),
539
+ timeout=timeout,
540
+ headers=headers,
541
+ params=rest_helpers.flatten_query_params(query_params, strict=True),
542
+ )
543
+ return response
544
+
545
+ def __call__(
546
+ self,
547
+ request: developerknowledge.GetDocumentRequest,
548
+ *,
549
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
550
+ timeout: Optional[float] = None,
551
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
552
+ ) -> developerknowledge.Document:
553
+ r"""Call the get document method over HTTP.
554
+
555
+ Args:
556
+ request (~.developerknowledge.GetDocumentRequest):
557
+ The request object. Request message for
558
+ [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument].
559
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
560
+ should be retried.
561
+ timeout (float): The timeout for this request.
562
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
563
+ sent along with the request as metadata. Normally, each value must be of type `str`,
564
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
565
+ be of type `bytes`.
566
+
567
+ Returns:
568
+ ~.developerknowledge.Document:
569
+ A Document represents a piece of
570
+ content from the Developer Knowledge
571
+ corpus.
572
+
573
+ """
574
+
575
+ http_options = _BaseDeveloperKnowledgeRestTransport._BaseGetDocument._get_http_options()
576
+
577
+ request, metadata = self._interceptor.pre_get_document(request, metadata)
578
+ transcoded_request = _BaseDeveloperKnowledgeRestTransport._BaseGetDocument._get_transcoded_request(
579
+ http_options, request
580
+ )
581
+
582
+ # Jsonify the query params
583
+ query_params = _BaseDeveloperKnowledgeRestTransport._BaseGetDocument._get_query_params_json(
584
+ transcoded_request
585
+ )
586
+
587
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
588
+ logging.DEBUG
589
+ ): # pragma: NO COVER
590
+ request_url = "{host}{uri}".format(
591
+ host=self._host, uri=transcoded_request["uri"]
592
+ )
593
+ method = transcoded_request["method"]
594
+ try:
595
+ request_payload = type(request).to_json(request)
596
+ except:
597
+ request_payload = None
598
+ http_request = {
599
+ "payload": request_payload,
600
+ "requestMethod": method,
601
+ "requestUrl": request_url,
602
+ "headers": dict(metadata),
603
+ }
604
+ _LOGGER.debug(
605
+ f"Sending request for google.developers.knowledge_v1.DeveloperKnowledgeClient.GetDocument",
606
+ extra={
607
+ "serviceName": "google.developers.knowledge.v1.DeveloperKnowledge",
608
+ "rpcName": "GetDocument",
609
+ "httpRequest": http_request,
610
+ "metadata": http_request["headers"],
611
+ },
612
+ )
613
+
614
+ # Send the request
615
+ response = DeveloperKnowledgeRestTransport._GetDocument._get_response(
616
+ self._host,
617
+ metadata,
618
+ query_params,
619
+ self._session,
620
+ timeout,
621
+ transcoded_request,
622
+ )
623
+
624
+ # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
625
+ # subclass.
626
+ if response.status_code >= 400:
627
+ raise core_exceptions.from_http_response(response)
628
+
629
+ # Return the response
630
+ resp = developerknowledge.Document()
631
+ pb_resp = developerknowledge.Document.pb(resp)
632
+
633
+ json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
634
+
635
+ resp = self._interceptor.post_get_document(resp)
636
+ response_metadata = [(k, str(v)) for k, v in response.headers.items()]
637
+ resp, _ = self._interceptor.post_get_document_with_metadata(
638
+ resp, response_metadata
639
+ )
640
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
641
+ logging.DEBUG
642
+ ): # pragma: NO COVER
643
+ try:
644
+ response_payload = developerknowledge.Document.to_json(response)
645
+ except:
646
+ response_payload = None
647
+ http_response = {
648
+ "payload": response_payload,
649
+ "headers": dict(response.headers),
650
+ "status": response.status_code,
651
+ }
652
+ _LOGGER.debug(
653
+ "Received response for google.developers.knowledge_v1.DeveloperKnowledgeClient.get_document",
654
+ extra={
655
+ "serviceName": "google.developers.knowledge.v1.DeveloperKnowledge",
656
+ "rpcName": "GetDocument",
657
+ "metadata": http_response["headers"],
658
+ "httpResponse": http_response,
659
+ },
660
+ )
661
+ return resp
662
+
663
+ class _SearchDocumentChunks(
664
+ _BaseDeveloperKnowledgeRestTransport._BaseSearchDocumentChunks,
665
+ DeveloperKnowledgeRestStub,
666
+ ):
667
+ def __hash__(self):
668
+ return hash("DeveloperKnowledgeRestTransport.SearchDocumentChunks")
669
+
670
+ @staticmethod
671
+ def _get_response(
672
+ host,
673
+ metadata,
674
+ query_params,
675
+ session,
676
+ timeout,
677
+ transcoded_request,
678
+ body=None,
679
+ ):
680
+ uri = transcoded_request["uri"]
681
+ method = transcoded_request["method"]
682
+ headers = dict(metadata)
683
+ headers["Content-Type"] = "application/json"
684
+ response = getattr(session, method)(
685
+ "{host}{uri}".format(host=host, uri=uri),
686
+ timeout=timeout,
687
+ headers=headers,
688
+ params=rest_helpers.flatten_query_params(query_params, strict=True),
689
+ )
690
+ return response
691
+
692
+ def __call__(
693
+ self,
694
+ request: developerknowledge.SearchDocumentChunksRequest,
695
+ *,
696
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
697
+ timeout: Optional[float] = None,
698
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
699
+ ) -> developerknowledge.SearchDocumentChunksResponse:
700
+ r"""Call the search document chunks method over HTTP.
701
+
702
+ Args:
703
+ request (~.developerknowledge.SearchDocumentChunksRequest):
704
+ The request object. Request message for
705
+ [DeveloperKnowledge.SearchDocumentChunks][google.developers.knowledge.v1.DeveloperKnowledge.SearchDocumentChunks].
706
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
707
+ should be retried.
708
+ timeout (float): The timeout for this request.
709
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
710
+ sent along with the request as metadata. Normally, each value must be of type `str`,
711
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
712
+ be of type `bytes`.
713
+
714
+ Returns:
715
+ ~.developerknowledge.SearchDocumentChunksResponse:
716
+ Response message for
717
+ [DeveloperKnowledge.SearchDocumentChunks][google.developers.knowledge.v1.DeveloperKnowledge.SearchDocumentChunks].
718
+
719
+ """
720
+
721
+ http_options = _BaseDeveloperKnowledgeRestTransport._BaseSearchDocumentChunks._get_http_options()
722
+
723
+ request, metadata = self._interceptor.pre_search_document_chunks(
724
+ request, metadata
725
+ )
726
+ transcoded_request = _BaseDeveloperKnowledgeRestTransport._BaseSearchDocumentChunks._get_transcoded_request(
727
+ http_options, request
728
+ )
729
+
730
+ # Jsonify the query params
731
+ query_params = _BaseDeveloperKnowledgeRestTransport._BaseSearchDocumentChunks._get_query_params_json(
732
+ transcoded_request
733
+ )
734
+
735
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
736
+ logging.DEBUG
737
+ ): # pragma: NO COVER
738
+ request_url = "{host}{uri}".format(
739
+ host=self._host, uri=transcoded_request["uri"]
740
+ )
741
+ method = transcoded_request["method"]
742
+ try:
743
+ request_payload = type(request).to_json(request)
744
+ except:
745
+ request_payload = None
746
+ http_request = {
747
+ "payload": request_payload,
748
+ "requestMethod": method,
749
+ "requestUrl": request_url,
750
+ "headers": dict(metadata),
751
+ }
752
+ _LOGGER.debug(
753
+ f"Sending request for google.developers.knowledge_v1.DeveloperKnowledgeClient.SearchDocumentChunks",
754
+ extra={
755
+ "serviceName": "google.developers.knowledge.v1.DeveloperKnowledge",
756
+ "rpcName": "SearchDocumentChunks",
757
+ "httpRequest": http_request,
758
+ "metadata": http_request["headers"],
759
+ },
760
+ )
761
+
762
+ # Send the request
763
+ response = (
764
+ DeveloperKnowledgeRestTransport._SearchDocumentChunks._get_response(
765
+ self._host,
766
+ metadata,
767
+ query_params,
768
+ self._session,
769
+ timeout,
770
+ transcoded_request,
771
+ )
772
+ )
773
+
774
+ # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
775
+ # subclass.
776
+ if response.status_code >= 400:
777
+ raise core_exceptions.from_http_response(response)
778
+
779
+ # Return the response
780
+ resp = developerknowledge.SearchDocumentChunksResponse()
781
+ pb_resp = developerknowledge.SearchDocumentChunksResponse.pb(resp)
782
+
783
+ json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
784
+
785
+ resp = self._interceptor.post_search_document_chunks(resp)
786
+ response_metadata = [(k, str(v)) for k, v in response.headers.items()]
787
+ resp, _ = self._interceptor.post_search_document_chunks_with_metadata(
788
+ resp, response_metadata
789
+ )
790
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
791
+ logging.DEBUG
792
+ ): # pragma: NO COVER
793
+ try:
794
+ response_payload = (
795
+ developerknowledge.SearchDocumentChunksResponse.to_json(
796
+ response
797
+ )
798
+ )
799
+ except:
800
+ response_payload = None
801
+ http_response = {
802
+ "payload": response_payload,
803
+ "headers": dict(response.headers),
804
+ "status": response.status_code,
805
+ }
806
+ _LOGGER.debug(
807
+ "Received response for google.developers.knowledge_v1.DeveloperKnowledgeClient.search_document_chunks",
808
+ extra={
809
+ "serviceName": "google.developers.knowledge.v1.DeveloperKnowledge",
810
+ "rpcName": "SearchDocumentChunks",
811
+ "metadata": http_response["headers"],
812
+ "httpResponse": http_response,
813
+ },
814
+ )
815
+ return resp
816
+
817
+ @property
818
+ def batch_get_documents(
819
+ self,
820
+ ) -> Callable[
821
+ [developerknowledge.BatchGetDocumentsRequest],
822
+ developerknowledge.BatchGetDocumentsResponse,
823
+ ]:
824
+ # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
825
+ # In C++ this would require a dynamic_cast
826
+ return self._BatchGetDocuments(self._session, self._host, self._interceptor) # type: ignore
827
+
828
+ @property
829
+ def get_document(
830
+ self,
831
+ ) -> Callable[[developerknowledge.GetDocumentRequest], developerknowledge.Document]:
832
+ # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
833
+ # In C++ this would require a dynamic_cast
834
+ return self._GetDocument(self._session, self._host, self._interceptor) # type: ignore
835
+
836
+ @property
837
+ def search_document_chunks(
838
+ self,
839
+ ) -> Callable[
840
+ [developerknowledge.SearchDocumentChunksRequest],
841
+ developerknowledge.SearchDocumentChunksResponse,
842
+ ]:
843
+ # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
844
+ # In C++ this would require a dynamic_cast
845
+ return self._SearchDocumentChunks(self._session, self._host, self._interceptor) # type: ignore
846
+
847
+ @property
848
+ def kind(self) -> str:
849
+ return "rest"
850
+
851
+ def close(self):
852
+ self._session.close()
853
+
854
+
855
+ __all__ = ("DeveloperKnowledgeRestTransport",)