1# -*- coding: utf-8 -*-
2# Copyright 2023 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#
16import warnings
17from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union
18
19from google.api_core import gapic_v1
20from google.api_core import grpc_helpers_async
21from google.auth import credentials as ga_credentials # type: ignore
22from google.auth.transport.grpc import SslCredentials # type: ignore
23
24import grpc # type: ignore
25from grpc.experimental import aio # type: ignore
26
27from google.cloud.firestore_v1.types import document
28from google.cloud.firestore_v1.types import document as gf_document
29from google.cloud.firestore_v1.types import firestore
30from google.cloud.location import locations_pb2 # type: ignore
31from google.longrunning import operations_pb2 # type: ignore
32from google.protobuf import empty_pb2 # type: ignore
33from .base import FirestoreTransport, DEFAULT_CLIENT_INFO
34from .grpc import FirestoreGrpcTransport
35
36
37class FirestoreGrpcAsyncIOTransport(FirestoreTransport):
38 """gRPC AsyncIO backend transport for Firestore.
39
40 The Cloud Firestore service.
41
42 Cloud Firestore is a fast, fully managed, serverless,
43 cloud-native NoSQL document database that simplifies storing,
44 syncing, and querying data for your mobile, web, and IoT apps at
45 global scale. Its client libraries provide live synchronization
46 and offline support, while its security features and
47 integrations with Firebase and Google Cloud Platform accelerate
48 building truly serverless apps.
49
50 This class defines the same methods as the primary client, so the
51 primary client can load the underlying transport implementation
52 and call it.
53
54 It sends protocol buffers over the wire using gRPC (which is built on
55 top of HTTP/2); the ``grpcio`` package must be installed.
56 """
57
58 _grpc_channel: aio.Channel
59 _stubs: Dict[str, Callable] = {}
60
61 @classmethod
62 def create_channel(
63 cls,
64 host: str = "firestore.googleapis.com",
65 credentials: Optional[ga_credentials.Credentials] = None,
66 credentials_file: Optional[str] = None,
67 scopes: Optional[Sequence[str]] = None,
68 quota_project_id: Optional[str] = None,
69 **kwargs,
70 ) -> aio.Channel:
71 """Create and return a gRPC AsyncIO channel object.
72 Args:
73 host (Optional[str]): The host for the channel to use.
74 credentials (Optional[~.Credentials]): The
75 authorization credentials to attach to requests. These
76 credentials identify this application to the service. If
77 none are specified, the client will attempt to ascertain
78 the credentials from the environment.
79 credentials_file (Optional[str]): A file with credentials that can
80 be loaded with :func:`google.auth.load_credentials_from_file`.
81 This argument is ignored if ``channel`` is provided.
82 scopes (Optional[Sequence[str]]): A optional list of scopes needed for this
83 service. These are only used when credentials are not specified and
84 are passed to :func:`google.auth.default`.
85 quota_project_id (Optional[str]): An optional project to use for billing
86 and quota.
87 kwargs (Optional[dict]): Keyword arguments, which are passed to the
88 channel creation.
89 Returns:
90 aio.Channel: A gRPC AsyncIO channel object.
91 """
92
93 return grpc_helpers_async.create_channel(
94 host,
95 credentials=credentials,
96 credentials_file=credentials_file,
97 quota_project_id=quota_project_id,
98 default_scopes=cls.AUTH_SCOPES,
99 scopes=scopes,
100 default_host=cls.DEFAULT_HOST,
101 **kwargs,
102 )
103
104 def __init__(
105 self,
106 *,
107 host: str = "firestore.googleapis.com",
108 credentials: Optional[ga_credentials.Credentials] = None,
109 credentials_file: Optional[str] = None,
110 scopes: Optional[Sequence[str]] = None,
111 channel: Optional[aio.Channel] = None,
112 api_mtls_endpoint: Optional[str] = None,
113 client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
114 ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None,
115 client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
116 quota_project_id: Optional[str] = None,
117 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
118 always_use_jwt_access: Optional[bool] = False,
119 api_audience: Optional[str] = None,
120 ) -> None:
121 """Instantiate the transport.
122
123 Args:
124 host (Optional[str]):
125 The hostname to connect to.
126 credentials (Optional[google.auth.credentials.Credentials]): The
127 authorization credentials to attach to requests. These
128 credentials identify the application to the service; if none
129 are specified, the client will attempt to ascertain the
130 credentials from the environment.
131 This argument is ignored if ``channel`` is provided.
132 credentials_file (Optional[str]): A file with credentials that can
133 be loaded with :func:`google.auth.load_credentials_from_file`.
134 This argument is ignored if ``channel`` is provided.
135 scopes (Optional[Sequence[str]]): A optional list of scopes needed for this
136 service. These are only used when credentials are not specified and
137 are passed to :func:`google.auth.default`.
138 channel (Optional[aio.Channel]): A ``Channel`` instance through
139 which to make calls.
140 api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint.
141 If provided, it overrides the ``host`` argument and tries to create
142 a mutual TLS channel with client SSL credentials from
143 ``client_cert_source`` or application default SSL credentials.
144 client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]):
145 Deprecated. A callback to provide client SSL certificate bytes and
146 private key bytes, both in PEM format. It is ignored if
147 ``api_mtls_endpoint`` is None.
148 ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials
149 for the grpc channel. It is ignored if ``channel`` is provided.
150 client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]):
151 A callback to provide client certificate bytes and private key bytes,
152 both in PEM format. It is used to configure a mutual TLS channel. It is
153 ignored if ``channel`` or ``ssl_channel_credentials`` is provided.
154 quota_project_id (Optional[str]): An optional project to use for billing
155 and quota.
156 client_info (google.api_core.gapic_v1.client_info.ClientInfo):
157 The client info used to send a user-agent string along with
158 API requests. If ``None``, then default info will be used.
159 Generally, you only need to set this if you're developing
160 your own client library.
161 always_use_jwt_access (Optional[bool]): Whether self signed JWT should
162 be used for service account credentials.
163
164 Raises:
165 google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
166 creation failed for any reason.
167 google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
168 and ``credentials_file`` are passed.
169 """
170 self._grpc_channel = None
171 self._ssl_channel_credentials = ssl_channel_credentials
172 self._stubs: Dict[str, Callable] = {}
173
174 if api_mtls_endpoint:
175 warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
176 if client_cert_source:
177 warnings.warn("client_cert_source is deprecated", DeprecationWarning)
178
179 if channel:
180 # Ignore credentials if a channel was passed.
181 credentials = False
182 # If a channel was explicitly provided, set it.
183 self._grpc_channel = channel
184 self._ssl_channel_credentials = None
185 else:
186 if api_mtls_endpoint:
187 host = api_mtls_endpoint
188
189 # Create SSL credentials with client_cert_source or application
190 # default SSL credentials.
191 if client_cert_source:
192 cert, key = client_cert_source()
193 self._ssl_channel_credentials = grpc.ssl_channel_credentials(
194 certificate_chain=cert, private_key=key
195 )
196 else:
197 self._ssl_channel_credentials = SslCredentials().ssl_credentials
198
199 else:
200 if client_cert_source_for_mtls and not ssl_channel_credentials:
201 cert, key = client_cert_source_for_mtls()
202 self._ssl_channel_credentials = grpc.ssl_channel_credentials(
203 certificate_chain=cert, private_key=key
204 )
205
206 # The base transport sets the host, credentials and scopes
207 super().__init__(
208 host=host,
209 credentials=credentials,
210 credentials_file=credentials_file,
211 scopes=scopes,
212 quota_project_id=quota_project_id,
213 client_info=client_info,
214 always_use_jwt_access=always_use_jwt_access,
215 api_audience=api_audience,
216 )
217
218 if not self._grpc_channel:
219 self._grpc_channel = type(self).create_channel(
220 self._host,
221 # use the credentials which are saved
222 credentials=self._credentials,
223 # Set ``credentials_file`` to ``None`` here as
224 # the credentials that we saved earlier should be used.
225 credentials_file=None,
226 scopes=self._scopes,
227 ssl_credentials=self._ssl_channel_credentials,
228 quota_project_id=quota_project_id,
229 options=[
230 ("grpc.max_send_message_length", -1),
231 ("grpc.max_receive_message_length", -1),
232 ],
233 )
234
235 # Wrap messages. This must be done after self._grpc_channel exists
236 self._prep_wrapped_messages(client_info)
237
238 @property
239 def grpc_channel(self) -> aio.Channel:
240 """Create the channel designed to connect to this service.
241
242 This property caches on the instance; repeated calls return
243 the same channel.
244 """
245 # Return the channel from cache.
246 return self._grpc_channel
247
248 @property
249 def get_document(
250 self,
251 ) -> Callable[[firestore.GetDocumentRequest], Awaitable[document.Document]]:
252 r"""Return a callable for the get document method over gRPC.
253
254 Gets a single document.
255
256 Returns:
257 Callable[[~.GetDocumentRequest],
258 Awaitable[~.Document]]:
259 A function that, when called, will call the underlying RPC
260 on the server.
261 """
262 # Generate a "stub function" on-the-fly which will actually make
263 # the request.
264 # gRPC handles serialization and deserialization, so we just need
265 # to pass in the functions for each.
266 if "get_document" not in self._stubs:
267 self._stubs["get_document"] = self.grpc_channel.unary_unary(
268 "/google.firestore.v1.Firestore/GetDocument",
269 request_serializer=firestore.GetDocumentRequest.serialize,
270 response_deserializer=document.Document.deserialize,
271 )
272 return self._stubs["get_document"]
273
274 @property
275 def list_documents(
276 self,
277 ) -> Callable[
278 [firestore.ListDocumentsRequest], Awaitable[firestore.ListDocumentsResponse]
279 ]:
280 r"""Return a callable for the list documents method over gRPC.
281
282 Lists documents.
283
284 Returns:
285 Callable[[~.ListDocumentsRequest],
286 Awaitable[~.ListDocumentsResponse]]:
287 A function that, when called, will call the underlying RPC
288 on the server.
289 """
290 # Generate a "stub function" on-the-fly which will actually make
291 # the request.
292 # gRPC handles serialization and deserialization, so we just need
293 # to pass in the functions for each.
294 if "list_documents" not in self._stubs:
295 self._stubs["list_documents"] = self.grpc_channel.unary_unary(
296 "/google.firestore.v1.Firestore/ListDocuments",
297 request_serializer=firestore.ListDocumentsRequest.serialize,
298 response_deserializer=firestore.ListDocumentsResponse.deserialize,
299 )
300 return self._stubs["list_documents"]
301
302 @property
303 def update_document(
304 self,
305 ) -> Callable[[firestore.UpdateDocumentRequest], Awaitable[gf_document.Document]]:
306 r"""Return a callable for the update document method over gRPC.
307
308 Updates or inserts a document.
309
310 Returns:
311 Callable[[~.UpdateDocumentRequest],
312 Awaitable[~.Document]]:
313 A function that, when called, will call the underlying RPC
314 on the server.
315 """
316 # Generate a "stub function" on-the-fly which will actually make
317 # the request.
318 # gRPC handles serialization and deserialization, so we just need
319 # to pass in the functions for each.
320 if "update_document" not in self._stubs:
321 self._stubs["update_document"] = self.grpc_channel.unary_unary(
322 "/google.firestore.v1.Firestore/UpdateDocument",
323 request_serializer=firestore.UpdateDocumentRequest.serialize,
324 response_deserializer=gf_document.Document.deserialize,
325 )
326 return self._stubs["update_document"]
327
328 @property
329 def delete_document(
330 self,
331 ) -> Callable[[firestore.DeleteDocumentRequest], Awaitable[empty_pb2.Empty]]:
332 r"""Return a callable for the delete document method over gRPC.
333
334 Deletes a document.
335
336 Returns:
337 Callable[[~.DeleteDocumentRequest],
338 Awaitable[~.Empty]]:
339 A function that, when called, will call the underlying RPC
340 on the server.
341 """
342 # Generate a "stub function" on-the-fly which will actually make
343 # the request.
344 # gRPC handles serialization and deserialization, so we just need
345 # to pass in the functions for each.
346 if "delete_document" not in self._stubs:
347 self._stubs["delete_document"] = self.grpc_channel.unary_unary(
348 "/google.firestore.v1.Firestore/DeleteDocument",
349 request_serializer=firestore.DeleteDocumentRequest.serialize,
350 response_deserializer=empty_pb2.Empty.FromString,
351 )
352 return self._stubs["delete_document"]
353
354 @property
355 def batch_get_documents(
356 self,
357 ) -> Callable[
358 [firestore.BatchGetDocumentsRequest],
359 Awaitable[firestore.BatchGetDocumentsResponse],
360 ]:
361 r"""Return a callable for the batch get documents method over gRPC.
362
363 Gets multiple documents.
364
365 Documents returned by this method are not guaranteed to
366 be returned in the same order that they were requested.
367
368 Returns:
369 Callable[[~.BatchGetDocumentsRequest],
370 Awaitable[~.BatchGetDocumentsResponse]]:
371 A function that, when called, will call the underlying RPC
372 on the server.
373 """
374 # Generate a "stub function" on-the-fly which will actually make
375 # the request.
376 # gRPC handles serialization and deserialization, so we just need
377 # to pass in the functions for each.
378 if "batch_get_documents" not in self._stubs:
379 self._stubs["batch_get_documents"] = self.grpc_channel.unary_stream(
380 "/google.firestore.v1.Firestore/BatchGetDocuments",
381 request_serializer=firestore.BatchGetDocumentsRequest.serialize,
382 response_deserializer=firestore.BatchGetDocumentsResponse.deserialize,
383 )
384 return self._stubs["batch_get_documents"]
385
386 @property
387 def begin_transaction(
388 self,
389 ) -> Callable[
390 [firestore.BeginTransactionRequest],
391 Awaitable[firestore.BeginTransactionResponse],
392 ]:
393 r"""Return a callable for the begin transaction method over gRPC.
394
395 Starts a new transaction.
396
397 Returns:
398 Callable[[~.BeginTransactionRequest],
399 Awaitable[~.BeginTransactionResponse]]:
400 A function that, when called, will call the underlying RPC
401 on the server.
402 """
403 # Generate a "stub function" on-the-fly which will actually make
404 # the request.
405 # gRPC handles serialization and deserialization, so we just need
406 # to pass in the functions for each.
407 if "begin_transaction" not in self._stubs:
408 self._stubs["begin_transaction"] = self.grpc_channel.unary_unary(
409 "/google.firestore.v1.Firestore/BeginTransaction",
410 request_serializer=firestore.BeginTransactionRequest.serialize,
411 response_deserializer=firestore.BeginTransactionResponse.deserialize,
412 )
413 return self._stubs["begin_transaction"]
414
415 @property
416 def commit(
417 self,
418 ) -> Callable[[firestore.CommitRequest], Awaitable[firestore.CommitResponse]]:
419 r"""Return a callable for the commit method over gRPC.
420
421 Commits a transaction, while optionally updating
422 documents.
423
424 Returns:
425 Callable[[~.CommitRequest],
426 Awaitable[~.CommitResponse]]:
427 A function that, when called, will call the underlying RPC
428 on the server.
429 """
430 # Generate a "stub function" on-the-fly which will actually make
431 # the request.
432 # gRPC handles serialization and deserialization, so we just need
433 # to pass in the functions for each.
434 if "commit" not in self._stubs:
435 self._stubs["commit"] = self.grpc_channel.unary_unary(
436 "/google.firestore.v1.Firestore/Commit",
437 request_serializer=firestore.CommitRequest.serialize,
438 response_deserializer=firestore.CommitResponse.deserialize,
439 )
440 return self._stubs["commit"]
441
442 @property
443 def rollback(
444 self,
445 ) -> Callable[[firestore.RollbackRequest], Awaitable[empty_pb2.Empty]]:
446 r"""Return a callable for the rollback method over gRPC.
447
448 Rolls back a transaction.
449
450 Returns:
451 Callable[[~.RollbackRequest],
452 Awaitable[~.Empty]]:
453 A function that, when called, will call the underlying RPC
454 on the server.
455 """
456 # Generate a "stub function" on-the-fly which will actually make
457 # the request.
458 # gRPC handles serialization and deserialization, so we just need
459 # to pass in the functions for each.
460 if "rollback" not in self._stubs:
461 self._stubs["rollback"] = self.grpc_channel.unary_unary(
462 "/google.firestore.v1.Firestore/Rollback",
463 request_serializer=firestore.RollbackRequest.serialize,
464 response_deserializer=empty_pb2.Empty.FromString,
465 )
466 return self._stubs["rollback"]
467
468 @property
469 def run_query(
470 self,
471 ) -> Callable[[firestore.RunQueryRequest], Awaitable[firestore.RunQueryResponse]]:
472 r"""Return a callable for the run query method over gRPC.
473
474 Runs a query.
475
476 Returns:
477 Callable[[~.RunQueryRequest],
478 Awaitable[~.RunQueryResponse]]:
479 A function that, when called, will call the underlying RPC
480 on the server.
481 """
482 # Generate a "stub function" on-the-fly which will actually make
483 # the request.
484 # gRPC handles serialization and deserialization, so we just need
485 # to pass in the functions for each.
486 if "run_query" not in self._stubs:
487 self._stubs["run_query"] = self.grpc_channel.unary_stream(
488 "/google.firestore.v1.Firestore/RunQuery",
489 request_serializer=firestore.RunQueryRequest.serialize,
490 response_deserializer=firestore.RunQueryResponse.deserialize,
491 )
492 return self._stubs["run_query"]
493
494 @property
495 def run_aggregation_query(
496 self,
497 ) -> Callable[
498 [firestore.RunAggregationQueryRequest],
499 Awaitable[firestore.RunAggregationQueryResponse],
500 ]:
501 r"""Return a callable for the run aggregation query method over gRPC.
502
503 Runs an aggregation query.
504
505 Rather than producing [Document][google.firestore.v1.Document]
506 results like
507 [Firestore.RunQuery][google.firestore.v1.Firestore.RunQuery],
508 this API allows running an aggregation to produce a series of
509 [AggregationResult][google.firestore.v1.AggregationResult]
510 server-side.
511
512 High-Level Example:
513
514 ::
515
516 -- Return the number of documents in table given a filter.
517 SELECT COUNT(*) FROM ( SELECT * FROM k where a = true );
518
519 Returns:
520 Callable[[~.RunAggregationQueryRequest],
521 Awaitable[~.RunAggregationQueryResponse]]:
522 A function that, when called, will call the underlying RPC
523 on the server.
524 """
525 # Generate a "stub function" on-the-fly which will actually make
526 # the request.
527 # gRPC handles serialization and deserialization, so we just need
528 # to pass in the functions for each.
529 if "run_aggregation_query" not in self._stubs:
530 self._stubs["run_aggregation_query"] = self.grpc_channel.unary_stream(
531 "/google.firestore.v1.Firestore/RunAggregationQuery",
532 request_serializer=firestore.RunAggregationQueryRequest.serialize,
533 response_deserializer=firestore.RunAggregationQueryResponse.deserialize,
534 )
535 return self._stubs["run_aggregation_query"]
536
537 @property
538 def partition_query(
539 self,
540 ) -> Callable[
541 [firestore.PartitionQueryRequest], Awaitable[firestore.PartitionQueryResponse]
542 ]:
543 r"""Return a callable for the partition query method over gRPC.
544
545 Partitions a query by returning partition cursors
546 that can be used to run the query in parallel. The
547 returned partition cursors are split points that can be
548 used by RunQuery as starting/end points for the query
549 results.
550
551 Returns:
552 Callable[[~.PartitionQueryRequest],
553 Awaitable[~.PartitionQueryResponse]]:
554 A function that, when called, will call the underlying RPC
555 on the server.
556 """
557 # Generate a "stub function" on-the-fly which will actually make
558 # the request.
559 # gRPC handles serialization and deserialization, so we just need
560 # to pass in the functions for each.
561 if "partition_query" not in self._stubs:
562 self._stubs["partition_query"] = self.grpc_channel.unary_unary(
563 "/google.firestore.v1.Firestore/PartitionQuery",
564 request_serializer=firestore.PartitionQueryRequest.serialize,
565 response_deserializer=firestore.PartitionQueryResponse.deserialize,
566 )
567 return self._stubs["partition_query"]
568
569 @property
570 def write(
571 self,
572 ) -> Callable[[firestore.WriteRequest], Awaitable[firestore.WriteResponse]]:
573 r"""Return a callable for the write method over gRPC.
574
575 Streams batches of document updates and deletes, in
576 order. This method is only available via gRPC or
577 WebChannel (not REST).
578
579 Returns:
580 Callable[[~.WriteRequest],
581 Awaitable[~.WriteResponse]]:
582 A function that, when called, will call the underlying RPC
583 on the server.
584 """
585 # Generate a "stub function" on-the-fly which will actually make
586 # the request.
587 # gRPC handles serialization and deserialization, so we just need
588 # to pass in the functions for each.
589 if "write" not in self._stubs:
590 self._stubs["write"] = self.grpc_channel.stream_stream(
591 "/google.firestore.v1.Firestore/Write",
592 request_serializer=firestore.WriteRequest.serialize,
593 response_deserializer=firestore.WriteResponse.deserialize,
594 )
595 return self._stubs["write"]
596
597 @property
598 def listen(
599 self,
600 ) -> Callable[[firestore.ListenRequest], Awaitable[firestore.ListenResponse]]:
601 r"""Return a callable for the listen method over gRPC.
602
603 Listens to changes. This method is only available via
604 gRPC or WebChannel (not REST).
605
606 Returns:
607 Callable[[~.ListenRequest],
608 Awaitable[~.ListenResponse]]:
609 A function that, when called, will call the underlying RPC
610 on the server.
611 """
612 # Generate a "stub function" on-the-fly which will actually make
613 # the request.
614 # gRPC handles serialization and deserialization, so we just need
615 # to pass in the functions for each.
616 if "listen" not in self._stubs:
617 self._stubs["listen"] = self.grpc_channel.stream_stream(
618 "/google.firestore.v1.Firestore/Listen",
619 request_serializer=firestore.ListenRequest.serialize,
620 response_deserializer=firestore.ListenResponse.deserialize,
621 )
622 return self._stubs["listen"]
623
624 @property
625 def list_collection_ids(
626 self,
627 ) -> Callable[
628 [firestore.ListCollectionIdsRequest],
629 Awaitable[firestore.ListCollectionIdsResponse],
630 ]:
631 r"""Return a callable for the list collection ids method over gRPC.
632
633 Lists all the collection IDs underneath a document.
634
635 Returns:
636 Callable[[~.ListCollectionIdsRequest],
637 Awaitable[~.ListCollectionIdsResponse]]:
638 A function that, when called, will call the underlying RPC
639 on the server.
640 """
641 # Generate a "stub function" on-the-fly which will actually make
642 # the request.
643 # gRPC handles serialization and deserialization, so we just need
644 # to pass in the functions for each.
645 if "list_collection_ids" not in self._stubs:
646 self._stubs["list_collection_ids"] = self.grpc_channel.unary_unary(
647 "/google.firestore.v1.Firestore/ListCollectionIds",
648 request_serializer=firestore.ListCollectionIdsRequest.serialize,
649 response_deserializer=firestore.ListCollectionIdsResponse.deserialize,
650 )
651 return self._stubs["list_collection_ids"]
652
653 @property
654 def batch_write(
655 self,
656 ) -> Callable[
657 [firestore.BatchWriteRequest], Awaitable[firestore.BatchWriteResponse]
658 ]:
659 r"""Return a callable for the batch write method over gRPC.
660
661 Applies a batch of write operations.
662
663 The BatchWrite method does not apply the write operations
664 atomically and can apply them out of order. Method does not
665 allow more than one write per document. Each write succeeds or
666 fails independently. See the
667 [BatchWriteResponse][google.firestore.v1.BatchWriteResponse] for
668 the success status of each write.
669
670 If you require an atomically applied set of writes, use
671 [Commit][google.firestore.v1.Firestore.Commit] instead.
672
673 Returns:
674 Callable[[~.BatchWriteRequest],
675 Awaitable[~.BatchWriteResponse]]:
676 A function that, when called, will call the underlying RPC
677 on the server.
678 """
679 # Generate a "stub function" on-the-fly which will actually make
680 # the request.
681 # gRPC handles serialization and deserialization, so we just need
682 # to pass in the functions for each.
683 if "batch_write" not in self._stubs:
684 self._stubs["batch_write"] = self.grpc_channel.unary_unary(
685 "/google.firestore.v1.Firestore/BatchWrite",
686 request_serializer=firestore.BatchWriteRequest.serialize,
687 response_deserializer=firestore.BatchWriteResponse.deserialize,
688 )
689 return self._stubs["batch_write"]
690
691 @property
692 def create_document(
693 self,
694 ) -> Callable[[firestore.CreateDocumentRequest], Awaitable[document.Document]]:
695 r"""Return a callable for the create document method over gRPC.
696
697 Creates a new document.
698
699 Returns:
700 Callable[[~.CreateDocumentRequest],
701 Awaitable[~.Document]]:
702 A function that, when called, will call the underlying RPC
703 on the server.
704 """
705 # Generate a "stub function" on-the-fly which will actually make
706 # the request.
707 # gRPC handles serialization and deserialization, so we just need
708 # to pass in the functions for each.
709 if "create_document" not in self._stubs:
710 self._stubs["create_document"] = self.grpc_channel.unary_unary(
711 "/google.firestore.v1.Firestore/CreateDocument",
712 request_serializer=firestore.CreateDocumentRequest.serialize,
713 response_deserializer=document.Document.deserialize,
714 )
715 return self._stubs["create_document"]
716
717 def close(self):
718 return self.grpc_channel.close()
719
720 @property
721 def delete_operation(
722 self,
723 ) -> Callable[[operations_pb2.DeleteOperationRequest], None]:
724 r"""Return a callable for the delete_operation method over gRPC."""
725 # Generate a "stub function" on-the-fly which will actually make
726 # the request.
727 # gRPC handles serialization and deserialization, so we just need
728 # to pass in the functions for each.
729 if "delete_operation" not in self._stubs:
730 self._stubs["delete_operation"] = self.grpc_channel.unary_unary(
731 "/google.longrunning.Operations/DeleteOperation",
732 request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString,
733 response_deserializer=None,
734 )
735 return self._stubs["delete_operation"]
736
737 @property
738 def cancel_operation(
739 self,
740 ) -> Callable[[operations_pb2.CancelOperationRequest], None]:
741 r"""Return a callable for the cancel_operation method over gRPC."""
742 # Generate a "stub function" on-the-fly which will actually make
743 # the request.
744 # gRPC handles serialization and deserialization, so we just need
745 # to pass in the functions for each.
746 if "cancel_operation" not in self._stubs:
747 self._stubs["cancel_operation"] = self.grpc_channel.unary_unary(
748 "/google.longrunning.Operations/CancelOperation",
749 request_serializer=operations_pb2.CancelOperationRequest.SerializeToString,
750 response_deserializer=None,
751 )
752 return self._stubs["cancel_operation"]
753
754 @property
755 def get_operation(
756 self,
757 ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]:
758 r"""Return a callable for the get_operation method over gRPC."""
759 # Generate a "stub function" on-the-fly which will actually make
760 # the request.
761 # gRPC handles serialization and deserialization, so we just need
762 # to pass in the functions for each.
763 if "get_operation" not in self._stubs:
764 self._stubs["get_operation"] = self.grpc_channel.unary_unary(
765 "/google.longrunning.Operations/GetOperation",
766 request_serializer=operations_pb2.GetOperationRequest.SerializeToString,
767 response_deserializer=operations_pb2.Operation.FromString,
768 )
769 return self._stubs["get_operation"]
770
771 @property
772 def list_operations(
773 self,
774 ) -> Callable[
775 [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse
776 ]:
777 r"""Return a callable for the list_operations method over gRPC."""
778 # Generate a "stub function" on-the-fly which will actually make
779 # the request.
780 # gRPC handles serialization and deserialization, so we just need
781 # to pass in the functions for each.
782 if "list_operations" not in self._stubs:
783 self._stubs["list_operations"] = self.grpc_channel.unary_unary(
784 "/google.longrunning.Operations/ListOperations",
785 request_serializer=operations_pb2.ListOperationsRequest.SerializeToString,
786 response_deserializer=operations_pb2.ListOperationsResponse.FromString,
787 )
788 return self._stubs["list_operations"]
789
790
791__all__ = ("FirestoreGrpcAsyncIOTransport",)