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,449 @@
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 json
17
+ import logging as std_logging
18
+ import pickle
19
+ import warnings
20
+ from typing import Callable, Dict, Optional, Sequence, Tuple, Union
21
+
22
+ import google.auth # type: ignore
23
+ import google.protobuf.message
24
+ import grpc # type: ignore
25
+ import proto # type: ignore
26
+ from google.api_core import gapic_v1, grpc_helpers
27
+ from google.auth import credentials as ga_credentials # type: ignore
28
+ from google.auth.transport.grpc import SslCredentials # type: ignore
29
+ from google.protobuf.json_format import MessageToJson
30
+
31
+ from google.developer_knowledge_v1.types import developerknowledge
32
+
33
+ from .base import DEFAULT_CLIENT_INFO, DeveloperKnowledgeTransport
34
+
35
+ try:
36
+ from google.api_core import client_logging # type: ignore
37
+
38
+ CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
39
+ except ImportError: # pragma: NO COVER
40
+ CLIENT_LOGGING_SUPPORTED = False
41
+
42
+ _LOGGER = std_logging.getLogger(__name__)
43
+
44
+
45
+ class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER
46
+ def intercept_unary_unary(self, continuation, client_call_details, request):
47
+ logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
48
+ std_logging.DEBUG
49
+ )
50
+ if logging_enabled: # pragma: NO COVER
51
+ request_metadata = client_call_details.metadata
52
+ if isinstance(request, proto.Message):
53
+ request_payload = type(request).to_json(request)
54
+ elif isinstance(request, google.protobuf.message.Message):
55
+ request_payload = MessageToJson(request)
56
+ else:
57
+ request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}"
58
+
59
+ request_metadata = {
60
+ key: value.decode("utf-8") if isinstance(value, bytes) else value
61
+ for key, value in request_metadata
62
+ }
63
+ grpc_request = {
64
+ "payload": request_payload,
65
+ "requestMethod": "grpc",
66
+ "metadata": dict(request_metadata),
67
+ }
68
+ _LOGGER.debug(
69
+ f"Sending request for {client_call_details.method}",
70
+ extra={
71
+ "serviceName": "google.developers.knowledge.v1.DeveloperKnowledge",
72
+ "rpcName": str(client_call_details.method),
73
+ "request": grpc_request,
74
+ "metadata": grpc_request["metadata"],
75
+ },
76
+ )
77
+ response = continuation(client_call_details, request)
78
+ if logging_enabled: # pragma: NO COVER
79
+ response_metadata = response.trailing_metadata()
80
+ # Convert gRPC metadata `<class 'grpc.aio._metadata.Metadata'>` to list of tuples
81
+ metadata = (
82
+ dict([(k, str(v)) for k, v in response_metadata])
83
+ if response_metadata
84
+ else None
85
+ )
86
+ result = response.result()
87
+ if isinstance(result, proto.Message):
88
+ response_payload = type(result).to_json(result)
89
+ elif isinstance(result, google.protobuf.message.Message):
90
+ response_payload = MessageToJson(result)
91
+ else:
92
+ response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}"
93
+ grpc_response = {
94
+ "payload": response_payload,
95
+ "metadata": metadata,
96
+ "status": "OK",
97
+ }
98
+ _LOGGER.debug(
99
+ f"Received response for {client_call_details.method}.",
100
+ extra={
101
+ "serviceName": "google.developers.knowledge.v1.DeveloperKnowledge",
102
+ "rpcName": client_call_details.method,
103
+ "response": grpc_response,
104
+ "metadata": grpc_response["metadata"],
105
+ },
106
+ )
107
+ return response
108
+
109
+
110
+ class DeveloperKnowledgeGrpcTransport(DeveloperKnowledgeTransport):
111
+ """gRPC backend transport for DeveloperKnowledge.
112
+
113
+ The Developer Knowledge API provides programmatic access to Google's
114
+ public developer documentation, enabling you to integrate this
115
+ knowledge base into your own applications and workflows.
116
+
117
+ The API is designed to be the canonical source for machine-readable
118
+ access to Google's developer documentation.
119
+
120
+ A typical use case is to first use
121
+ [DeveloperKnowledge.SearchDocumentChunks][google.developers.knowledge.v1.DeveloperKnowledge.SearchDocumentChunks]
122
+ to find relevant page URIs based on a query, and then use
123
+ [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument]
124
+ or
125
+ [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments]
126
+ to fetch the full content of the top results.
127
+
128
+ All document content is provided in Markdown format.
129
+
130
+ This class defines the same methods as the primary client, so the
131
+ primary client can load the underlying transport implementation
132
+ and call it.
133
+
134
+ It sends protocol buffers over the wire using gRPC (which is built on
135
+ top of HTTP/2); the ``grpcio`` package must be installed.
136
+ """
137
+
138
+ _stubs: Dict[str, Callable]
139
+
140
+ def __init__(
141
+ self,
142
+ *,
143
+ host: str = "developerknowledge.googleapis.com",
144
+ credentials: Optional[ga_credentials.Credentials] = None,
145
+ credentials_file: Optional[str] = None,
146
+ scopes: Optional[Sequence[str]] = None,
147
+ channel: Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]] = None,
148
+ api_mtls_endpoint: Optional[str] = None,
149
+ client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
150
+ ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None,
151
+ client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
152
+ quota_project_id: Optional[str] = None,
153
+ client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
154
+ always_use_jwt_access: Optional[bool] = False,
155
+ api_audience: Optional[str] = None,
156
+ ) -> None:
157
+ """Instantiate the transport.
158
+
159
+ Args:
160
+ host (Optional[str]):
161
+ The hostname to connect to (default: 'developerknowledge.googleapis.com').
162
+ credentials (Optional[google.auth.credentials.Credentials]): The
163
+ authorization credentials to attach to requests. These
164
+ credentials identify the application to the service; if none
165
+ are specified, the client will attempt to ascertain the
166
+ credentials from the environment.
167
+ This argument is ignored if a ``channel`` instance is provided.
168
+ credentials_file (Optional[str]): Deprecated. A file with credentials that can
169
+ be loaded with :func:`google.auth.load_credentials_from_file`.
170
+ This argument is ignored if a ``channel`` instance is provided.
171
+ This argument will be removed in the next major version of this library.
172
+ scopes (Optional(Sequence[str])): A list of scopes. This argument is
173
+ ignored if a ``channel`` instance is provided.
174
+ channel (Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]]):
175
+ A ``Channel`` instance through which to make calls, or a Callable
176
+ that constructs and returns one. If set to None, ``self.create_channel``
177
+ is used to create the channel. If a Callable is given, it will be called
178
+ with the same arguments as used in ``self.create_channel``.
179
+ api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint.
180
+ If provided, it overrides the ``host`` argument and tries to create
181
+ a mutual TLS channel with client SSL credentials from
182
+ ``client_cert_source`` or application default SSL credentials.
183
+ client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]):
184
+ Deprecated. A callback to provide client SSL certificate bytes and
185
+ private key bytes, both in PEM format. It is ignored if
186
+ ``api_mtls_endpoint`` is None.
187
+ ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials
188
+ for the grpc channel. It is ignored if a ``channel`` instance is provided.
189
+ client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]):
190
+ A callback to provide client certificate bytes and private key bytes,
191
+ both in PEM format. It is used to configure a mutual TLS channel. It is
192
+ ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided.
193
+ quota_project_id (Optional[str]): An optional project to use for billing
194
+ and quota.
195
+ client_info (google.api_core.gapic_v1.client_info.ClientInfo):
196
+ The client info used to send a user-agent string along with
197
+ API requests. If ``None``, then default info will be used.
198
+ Generally, you only need to set this if you're developing
199
+ your own client library.
200
+ always_use_jwt_access (Optional[bool]): Whether self signed JWT should
201
+ be used for service account credentials.
202
+ api_audience (Optional[str]): The intended audience for the API calls
203
+ to the service that will be set when using certain 3rd party
204
+ authentication flows. Audience is typically a resource identifier.
205
+ If not set, the host value will be used as a default.
206
+
207
+ Raises:
208
+ google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
209
+ creation failed for any reason.
210
+ google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
211
+ and ``credentials_file`` are passed.
212
+ """
213
+ self._grpc_channel = None
214
+ self._ssl_channel_credentials = ssl_channel_credentials
215
+ self._stubs: Dict[str, Callable] = {}
216
+
217
+ if api_mtls_endpoint:
218
+ warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
219
+ if client_cert_source:
220
+ warnings.warn("client_cert_source is deprecated", DeprecationWarning)
221
+
222
+ if isinstance(channel, grpc.Channel):
223
+ # Ignore credentials if a channel was passed.
224
+ credentials = None
225
+ self._ignore_credentials = True
226
+ # If a channel was explicitly provided, set it.
227
+ self._grpc_channel = channel
228
+ self._ssl_channel_credentials = None
229
+
230
+ else:
231
+ if api_mtls_endpoint:
232
+ host = api_mtls_endpoint
233
+
234
+ # Create SSL credentials with client_cert_source or application
235
+ # default SSL credentials.
236
+ if client_cert_source:
237
+ cert, key = client_cert_source()
238
+ self._ssl_channel_credentials = grpc.ssl_channel_credentials(
239
+ certificate_chain=cert, private_key=key
240
+ )
241
+ else:
242
+ self._ssl_channel_credentials = SslCredentials().ssl_credentials
243
+
244
+ else:
245
+ if client_cert_source_for_mtls and not ssl_channel_credentials:
246
+ cert, key = client_cert_source_for_mtls()
247
+ self._ssl_channel_credentials = grpc.ssl_channel_credentials(
248
+ certificate_chain=cert, private_key=key
249
+ )
250
+
251
+ # The base transport sets the host, credentials and scopes
252
+ super().__init__(
253
+ host=host,
254
+ credentials=credentials,
255
+ credentials_file=credentials_file,
256
+ scopes=scopes,
257
+ quota_project_id=quota_project_id,
258
+ client_info=client_info,
259
+ always_use_jwt_access=always_use_jwt_access,
260
+ api_audience=api_audience,
261
+ )
262
+
263
+ if not self._grpc_channel:
264
+ # initialize with the provided callable or the default channel
265
+ channel_init = channel or type(self).create_channel
266
+ self._grpc_channel = channel_init(
267
+ self._host,
268
+ # use the credentials which are saved
269
+ credentials=self._credentials,
270
+ # Set ``credentials_file`` to ``None`` here as
271
+ # the credentials that we saved earlier should be used.
272
+ credentials_file=None,
273
+ scopes=self._scopes,
274
+ ssl_credentials=self._ssl_channel_credentials,
275
+ quota_project_id=quota_project_id,
276
+ options=[
277
+ ("grpc.max_send_message_length", -1),
278
+ ("grpc.max_receive_message_length", -1),
279
+ ],
280
+ )
281
+
282
+ self._interceptor = _LoggingClientInterceptor()
283
+ self._logged_channel = grpc.intercept_channel(
284
+ self._grpc_channel, self._interceptor
285
+ )
286
+
287
+ # Wrap messages. This must be done after self._logged_channel exists
288
+ self._prep_wrapped_messages(client_info)
289
+
290
+ @classmethod
291
+ def create_channel(
292
+ cls,
293
+ host: str = "developerknowledge.googleapis.com",
294
+ credentials: Optional[ga_credentials.Credentials] = None,
295
+ credentials_file: Optional[str] = None,
296
+ scopes: Optional[Sequence[str]] = None,
297
+ quota_project_id: Optional[str] = None,
298
+ **kwargs,
299
+ ) -> grpc.Channel:
300
+ """Create and return a gRPC channel object.
301
+ Args:
302
+ host (Optional[str]): The host for the channel to use.
303
+ credentials (Optional[~.Credentials]): The
304
+ authorization credentials to attach to requests. These
305
+ credentials identify this application to the service. If
306
+ none are specified, the client will attempt to ascertain
307
+ the credentials from the environment.
308
+ credentials_file (Optional[str]): Deprecated. A file with credentials that can
309
+ be loaded with :func:`google.auth.load_credentials_from_file`.
310
+ This argument is mutually exclusive with credentials. This argument will be
311
+ removed in the next major version of this library.
312
+ scopes (Optional[Sequence[str]]): A optional list of scopes needed for this
313
+ service. These are only used when credentials are not specified and
314
+ are passed to :func:`google.auth.default`.
315
+ quota_project_id (Optional[str]): An optional project to use for billing
316
+ and quota.
317
+ kwargs (Optional[dict]): Keyword arguments, which are passed to the
318
+ channel creation.
319
+ Returns:
320
+ grpc.Channel: A gRPC channel object.
321
+
322
+ Raises:
323
+ google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
324
+ and ``credentials_file`` are passed.
325
+ """
326
+
327
+ return grpc_helpers.create_channel(
328
+ host,
329
+ credentials=credentials,
330
+ credentials_file=credentials_file,
331
+ quota_project_id=quota_project_id,
332
+ default_scopes=cls.AUTH_SCOPES,
333
+ scopes=scopes,
334
+ default_host=cls.DEFAULT_HOST,
335
+ **kwargs,
336
+ )
337
+
338
+ @property
339
+ def grpc_channel(self) -> grpc.Channel:
340
+ """Return the channel designed to connect to this service."""
341
+ return self._grpc_channel
342
+
343
+ @property
344
+ def search_document_chunks(
345
+ self,
346
+ ) -> Callable[
347
+ [developerknowledge.SearchDocumentChunksRequest],
348
+ developerknowledge.SearchDocumentChunksResponse,
349
+ ]:
350
+ r"""Return a callable for the search document chunks method over gRPC.
351
+
352
+ Searches for developer knowledge across Google's developer
353
+ documentation. Returns
354
+ [DocumentChunk][google.developers.knowledge.v1.DocumentChunk]s
355
+ based on the user's query. There may be many chunks from the
356
+ same [Document][google.developers.knowledge.v1.Document]. To
357
+ retrieve full documents, use
358
+ [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument]
359
+ or
360
+ [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments]
361
+ with the
362
+ [DocumentChunk.parent][google.developers.knowledge.v1.DocumentChunk.parent]
363
+ returned in the
364
+ [SearchDocumentChunksResponse.results][google.developers.knowledge.v1.SearchDocumentChunksResponse.results].
365
+
366
+ Returns:
367
+ Callable[[~.SearchDocumentChunksRequest],
368
+ ~.SearchDocumentChunksResponse]:
369
+ A function that, when called, will call the underlying RPC
370
+ on the server.
371
+ """
372
+ # Generate a "stub function" on-the-fly which will actually make
373
+ # the request.
374
+ # gRPC handles serialization and deserialization, so we just need
375
+ # to pass in the functions for each.
376
+ if "search_document_chunks" not in self._stubs:
377
+ self._stubs["search_document_chunks"] = self._logged_channel.unary_unary(
378
+ "/google.developers.knowledge.v1.DeveloperKnowledge/SearchDocumentChunks",
379
+ request_serializer=developerknowledge.SearchDocumentChunksRequest.serialize,
380
+ response_deserializer=developerknowledge.SearchDocumentChunksResponse.deserialize,
381
+ )
382
+ return self._stubs["search_document_chunks"]
383
+
384
+ @property
385
+ def get_document(
386
+ self,
387
+ ) -> Callable[[developerknowledge.GetDocumentRequest], developerknowledge.Document]:
388
+ r"""Return a callable for the get document method over gRPC.
389
+
390
+ Retrieves a single document with its full Markdown
391
+ content.
392
+
393
+ Returns:
394
+ Callable[[~.GetDocumentRequest],
395
+ ~.Document]:
396
+ A function that, when called, will call the underlying RPC
397
+ on the server.
398
+ """
399
+ # Generate a "stub function" on-the-fly which will actually make
400
+ # the request.
401
+ # gRPC handles serialization and deserialization, so we just need
402
+ # to pass in the functions for each.
403
+ if "get_document" not in self._stubs:
404
+ self._stubs["get_document"] = self._logged_channel.unary_unary(
405
+ "/google.developers.knowledge.v1.DeveloperKnowledge/GetDocument",
406
+ request_serializer=developerknowledge.GetDocumentRequest.serialize,
407
+ response_deserializer=developerknowledge.Document.deserialize,
408
+ )
409
+ return self._stubs["get_document"]
410
+
411
+ @property
412
+ def batch_get_documents(
413
+ self,
414
+ ) -> Callable[
415
+ [developerknowledge.BatchGetDocumentsRequest],
416
+ developerknowledge.BatchGetDocumentsResponse,
417
+ ]:
418
+ r"""Return a callable for the batch get documents method over gRPC.
419
+
420
+ Retrieves multiple documents, each with its full
421
+ Markdown content.
422
+
423
+ Returns:
424
+ Callable[[~.BatchGetDocumentsRequest],
425
+ ~.BatchGetDocumentsResponse]:
426
+ A function that, when called, will call the underlying RPC
427
+ on the server.
428
+ """
429
+ # Generate a "stub function" on-the-fly which will actually make
430
+ # the request.
431
+ # gRPC handles serialization and deserialization, so we just need
432
+ # to pass in the functions for each.
433
+ if "batch_get_documents" not in self._stubs:
434
+ self._stubs["batch_get_documents"] = self._logged_channel.unary_unary(
435
+ "/google.developers.knowledge.v1.DeveloperKnowledge/BatchGetDocuments",
436
+ request_serializer=developerknowledge.BatchGetDocumentsRequest.serialize,
437
+ response_deserializer=developerknowledge.BatchGetDocumentsResponse.deserialize,
438
+ )
439
+ return self._stubs["batch_get_documents"]
440
+
441
+ def close(self):
442
+ self._logged_channel.close()
443
+
444
+ @property
445
+ def kind(self) -> str:
446
+ return "grpc"
447
+
448
+
449
+ __all__ = ("DeveloperKnowledgeGrpcTransport",)