google-maps-routeoptimization 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 (23) hide show
  1. google/maps/routeoptimization/__init__.py +85 -0
  2. google/maps/routeoptimization/gapic_version.py +16 -0
  3. google/maps/routeoptimization/py.typed +2 -0
  4. google/maps/routeoptimization_v1/__init__.py +83 -0
  5. google/maps/routeoptimization_v1/gapic_metadata.json +58 -0
  6. google/maps/routeoptimization_v1/gapic_version.py +16 -0
  7. google/maps/routeoptimization_v1/py.typed +2 -0
  8. google/maps/routeoptimization_v1/services/__init__.py +15 -0
  9. google/maps/routeoptimization_v1/services/route_optimization/__init__.py +22 -0
  10. google/maps/routeoptimization_v1/services/route_optimization/async_client.py +588 -0
  11. google/maps/routeoptimization_v1/services/route_optimization/client.py +992 -0
  12. google/maps/routeoptimization_v1/services/route_optimization/transports/__init__.py +36 -0
  13. google/maps/routeoptimization_v1/services/route_optimization/transports/base.py +200 -0
  14. google/maps/routeoptimization_v1/services/route_optimization/transports/grpc.py +381 -0
  15. google/maps/routeoptimization_v1/services/route_optimization/transports/grpc_asyncio.py +408 -0
  16. google/maps/routeoptimization_v1/services/route_optimization/transports/rest.py +631 -0
  17. google/maps/routeoptimization_v1/types/__init__.py +72 -0
  18. google/maps/routeoptimization_v1/types/route_optimization_service.py +4029 -0
  19. google_maps_routeoptimization-0.1.0.dist-info/LICENSE +202 -0
  20. google_maps_routeoptimization-0.1.0.dist-info/METADATA +137 -0
  21. google_maps_routeoptimization-0.1.0.dist-info/RECORD +23 -0
  22. google_maps_routeoptimization-0.1.0.dist-info/WHEEL +5 -0
  23. google_maps_routeoptimization-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,408 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 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
+ from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union
17
+ import warnings
18
+
19
+ from google.api_core import exceptions as core_exceptions
20
+ from google.api_core import gapic_v1, grpc_helpers_async, operations_v1
21
+ from google.api_core import retry_async as retries
22
+ from google.auth import credentials as ga_credentials # type: ignore
23
+ from google.auth.transport.grpc import SslCredentials # type: ignore
24
+ from google.longrunning import operations_pb2 # type: ignore
25
+ import grpc # type: ignore
26
+ from grpc.experimental import aio # type: ignore
27
+
28
+ from google.maps.routeoptimization_v1.types import route_optimization_service
29
+
30
+ from .base import DEFAULT_CLIENT_INFO, RouteOptimizationTransport
31
+ from .grpc import RouteOptimizationGrpcTransport
32
+
33
+
34
+ class RouteOptimizationGrpcAsyncIOTransport(RouteOptimizationTransport):
35
+ """gRPC AsyncIO backend transport for RouteOptimization.
36
+
37
+ A service for optimizing vehicle tours.
38
+
39
+ Validity of certain types of fields:
40
+
41
+ - ``google.protobuf.Timestamp``
42
+
43
+ - Times are in Unix time: seconds since
44
+ 1970-01-01T00:00:00+00:00.
45
+ - seconds must be in [0, 253402300799], i.e. in
46
+ [1970-01-01T00:00:00+00:00, 9999-12-31T23:59:59+00:00].
47
+ - nanos must be unset or set to 0.
48
+
49
+ - ``google.protobuf.Duration``
50
+
51
+ - seconds must be in [0, 253402300799], i.e. in
52
+ [1970-01-01T00:00:00+00:00, 9999-12-31T23:59:59+00:00].
53
+ - nanos must be unset or set to 0.
54
+
55
+ - ``google.type.LatLng``
56
+
57
+ - latitude must be in [-90.0, 90.0].
58
+ - longitude must be in [-180.0, 180.0].
59
+ - at least one of latitude and longitude must be non-zero.
60
+
61
+ This class defines the same methods as the primary client, so the
62
+ primary client can load the underlying transport implementation
63
+ and call it.
64
+
65
+ It sends protocol buffers over the wire using gRPC (which is built on
66
+ top of HTTP/2); the ``grpcio`` package must be installed.
67
+ """
68
+
69
+ _grpc_channel: aio.Channel
70
+ _stubs: Dict[str, Callable] = {}
71
+
72
+ @classmethod
73
+ def create_channel(
74
+ cls,
75
+ host: str = "routeoptimization.googleapis.com",
76
+ credentials: Optional[ga_credentials.Credentials] = None,
77
+ credentials_file: Optional[str] = None,
78
+ scopes: Optional[Sequence[str]] = None,
79
+ quota_project_id: Optional[str] = None,
80
+ **kwargs,
81
+ ) -> aio.Channel:
82
+ """Create and return a gRPC AsyncIO channel object.
83
+ Args:
84
+ host (Optional[str]): The host for the channel to use.
85
+ credentials (Optional[~.Credentials]): The
86
+ authorization credentials to attach to requests. These
87
+ credentials identify this application to the service. If
88
+ none are specified, the client will attempt to ascertain
89
+ the credentials from the environment.
90
+ credentials_file (Optional[str]): A file with credentials that can
91
+ be loaded with :func:`google.auth.load_credentials_from_file`.
92
+ scopes (Optional[Sequence[str]]): A optional list of scopes needed for this
93
+ service. These are only used when credentials are not specified and
94
+ are passed to :func:`google.auth.default`.
95
+ quota_project_id (Optional[str]): An optional project to use for billing
96
+ and quota.
97
+ kwargs (Optional[dict]): Keyword arguments, which are passed to the
98
+ channel creation.
99
+ Returns:
100
+ aio.Channel: A gRPC AsyncIO channel object.
101
+ """
102
+
103
+ return grpc_helpers_async.create_channel(
104
+ host,
105
+ credentials=credentials,
106
+ credentials_file=credentials_file,
107
+ quota_project_id=quota_project_id,
108
+ default_scopes=cls.AUTH_SCOPES,
109
+ scopes=scopes,
110
+ default_host=cls.DEFAULT_HOST,
111
+ **kwargs,
112
+ )
113
+
114
+ def __init__(
115
+ self,
116
+ *,
117
+ host: str = "routeoptimization.googleapis.com",
118
+ credentials: Optional[ga_credentials.Credentials] = None,
119
+ credentials_file: Optional[str] = None,
120
+ scopes: Optional[Sequence[str]] = None,
121
+ channel: Optional[Union[aio.Channel, Callable[..., aio.Channel]]] = None,
122
+ api_mtls_endpoint: Optional[str] = None,
123
+ client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
124
+ ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None,
125
+ client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
126
+ quota_project_id: Optional[str] = None,
127
+ client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
128
+ always_use_jwt_access: Optional[bool] = False,
129
+ api_audience: Optional[str] = None,
130
+ ) -> None:
131
+ """Instantiate the transport.
132
+
133
+ Args:
134
+ host (Optional[str]):
135
+ The hostname to connect to (default: 'routeoptimization.googleapis.com').
136
+ credentials (Optional[google.auth.credentials.Credentials]): The
137
+ authorization credentials to attach to requests. These
138
+ credentials identify the application to the service; if none
139
+ are specified, the client will attempt to ascertain the
140
+ credentials from the environment.
141
+ This argument is ignored if a ``channel`` instance is provided.
142
+ credentials_file (Optional[str]): A file with credentials that can
143
+ be loaded with :func:`google.auth.load_credentials_from_file`.
144
+ This argument is ignored if a ``channel`` instance is provided.
145
+ scopes (Optional[Sequence[str]]): A optional list of scopes needed for this
146
+ service. These are only used when credentials are not specified and
147
+ are passed to :func:`google.auth.default`.
148
+ channel (Optional[Union[aio.Channel, Callable[..., aio.Channel]]]):
149
+ A ``Channel`` instance through which to make calls, or a Callable
150
+ that constructs and returns one. If set to None, ``self.create_channel``
151
+ is used to create the channel. If a Callable is given, it will be called
152
+ with the same arguments as used in ``self.create_channel``.
153
+ api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint.
154
+ If provided, it overrides the ``host`` argument and tries to create
155
+ a mutual TLS channel with client SSL credentials from
156
+ ``client_cert_source`` or application default SSL credentials.
157
+ client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]):
158
+ Deprecated. A callback to provide client SSL certificate bytes and
159
+ private key bytes, both in PEM format. It is ignored if
160
+ ``api_mtls_endpoint`` is None.
161
+ ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials
162
+ for the grpc channel. It is ignored if a ``channel`` instance is provided.
163
+ client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]):
164
+ A callback to provide client certificate bytes and private key bytes,
165
+ both in PEM format. It is used to configure a mutual TLS channel. It is
166
+ ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided.
167
+ quota_project_id (Optional[str]): An optional project to use for billing
168
+ and quota.
169
+ client_info (google.api_core.gapic_v1.client_info.ClientInfo):
170
+ The client info used to send a user-agent string along with
171
+ API requests. If ``None``, then default info will be used.
172
+ Generally, you only need to set this if you're developing
173
+ your own client library.
174
+ always_use_jwt_access (Optional[bool]): Whether self signed JWT should
175
+ be used for service account credentials.
176
+
177
+ Raises:
178
+ google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
179
+ creation failed for any reason.
180
+ google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
181
+ and ``credentials_file`` are passed.
182
+ """
183
+ self._grpc_channel = None
184
+ self._ssl_channel_credentials = ssl_channel_credentials
185
+ self._stubs: Dict[str, Callable] = {}
186
+ self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None
187
+
188
+ if api_mtls_endpoint:
189
+ warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
190
+ if client_cert_source:
191
+ warnings.warn("client_cert_source is deprecated", DeprecationWarning)
192
+
193
+ if isinstance(channel, aio.Channel):
194
+ # Ignore credentials if a channel was passed.
195
+ credentials = False
196
+ # If a channel was explicitly provided, set it.
197
+ self._grpc_channel = channel
198
+ self._ssl_channel_credentials = None
199
+ else:
200
+ if api_mtls_endpoint:
201
+ host = api_mtls_endpoint
202
+
203
+ # Create SSL credentials with client_cert_source or application
204
+ # default SSL credentials.
205
+ if client_cert_source:
206
+ cert, key = client_cert_source()
207
+ self._ssl_channel_credentials = grpc.ssl_channel_credentials(
208
+ certificate_chain=cert, private_key=key
209
+ )
210
+ else:
211
+ self._ssl_channel_credentials = SslCredentials().ssl_credentials
212
+
213
+ else:
214
+ if client_cert_source_for_mtls and not ssl_channel_credentials:
215
+ cert, key = client_cert_source_for_mtls()
216
+ self._ssl_channel_credentials = grpc.ssl_channel_credentials(
217
+ certificate_chain=cert, private_key=key
218
+ )
219
+
220
+ # The base transport sets the host, credentials and scopes
221
+ super().__init__(
222
+ host=host,
223
+ credentials=credentials,
224
+ credentials_file=credentials_file,
225
+ scopes=scopes,
226
+ quota_project_id=quota_project_id,
227
+ client_info=client_info,
228
+ always_use_jwt_access=always_use_jwt_access,
229
+ api_audience=api_audience,
230
+ )
231
+
232
+ if not self._grpc_channel:
233
+ # initialize with the provided callable or the default channel
234
+ channel_init = channel or type(self).create_channel
235
+ self._grpc_channel = channel_init(
236
+ self._host,
237
+ # use the credentials which are saved
238
+ credentials=self._credentials,
239
+ # Set ``credentials_file`` to ``None`` here as
240
+ # the credentials that we saved earlier should be used.
241
+ credentials_file=None,
242
+ scopes=self._scopes,
243
+ ssl_credentials=self._ssl_channel_credentials,
244
+ quota_project_id=quota_project_id,
245
+ options=[
246
+ ("grpc.max_send_message_length", -1),
247
+ ("grpc.max_receive_message_length", -1),
248
+ ],
249
+ )
250
+
251
+ # Wrap messages. This must be done after self._grpc_channel exists
252
+ self._prep_wrapped_messages(client_info)
253
+
254
+ @property
255
+ def grpc_channel(self) -> aio.Channel:
256
+ """Create the channel designed to connect to this service.
257
+
258
+ This property caches on the instance; repeated calls return
259
+ the same channel.
260
+ """
261
+ # Return the channel from cache.
262
+ return self._grpc_channel
263
+
264
+ @property
265
+ def operations_client(self) -> operations_v1.OperationsAsyncClient:
266
+ """Create the client designed to process long-running operations.
267
+
268
+ This property caches on the instance; repeated calls return the same
269
+ client.
270
+ """
271
+ # Quick check: Only create a new client if we do not already have one.
272
+ if self._operations_client is None:
273
+ self._operations_client = operations_v1.OperationsAsyncClient(
274
+ self.grpc_channel
275
+ )
276
+
277
+ # Return the client from cache.
278
+ return self._operations_client
279
+
280
+ @property
281
+ def optimize_tours(
282
+ self,
283
+ ) -> Callable[
284
+ [route_optimization_service.OptimizeToursRequest],
285
+ Awaitable[route_optimization_service.OptimizeToursResponse],
286
+ ]:
287
+ r"""Return a callable for the optimize tours method over gRPC.
288
+
289
+ Sends an ``OptimizeToursRequest`` containing a ``ShipmentModel``
290
+ and returns an ``OptimizeToursResponse`` containing
291
+ ``ShipmentRoute``\ s, which are a set of routes to be performed
292
+ by vehicles minimizing the overall cost.
293
+
294
+ A ``ShipmentModel`` model consists mainly of ``Shipment``\ s
295
+ that need to be carried out and ``Vehicle``\ s that can be used
296
+ to transport the ``Shipment``\ s. The ``ShipmentRoute``\ s
297
+ assign ``Shipment``\ s to ``Vehicle``\ s. More specifically,
298
+ they assign a series of ``Visit``\ s to each vehicle, where a
299
+ ``Visit`` corresponds to a ``VisitRequest``, which is a pickup
300
+ or delivery for a ``Shipment``.
301
+
302
+ The goal is to provide an assignment of ``ShipmentRoute``\ s to
303
+ ``Vehicle``\ s that minimizes the total cost where cost has many
304
+ components defined in the ``ShipmentModel``.
305
+
306
+ Returns:
307
+ Callable[[~.OptimizeToursRequest],
308
+ Awaitable[~.OptimizeToursResponse]]:
309
+ A function that, when called, will call the underlying RPC
310
+ on the server.
311
+ """
312
+ # Generate a "stub function" on-the-fly which will actually make
313
+ # the request.
314
+ # gRPC handles serialization and deserialization, so we just need
315
+ # to pass in the functions for each.
316
+ if "optimize_tours" not in self._stubs:
317
+ self._stubs["optimize_tours"] = self.grpc_channel.unary_unary(
318
+ "/google.maps.routeoptimization.v1.RouteOptimization/OptimizeTours",
319
+ request_serializer=route_optimization_service.OptimizeToursRequest.serialize,
320
+ response_deserializer=route_optimization_service.OptimizeToursResponse.deserialize,
321
+ )
322
+ return self._stubs["optimize_tours"]
323
+
324
+ @property
325
+ def batch_optimize_tours(
326
+ self,
327
+ ) -> Callable[
328
+ [route_optimization_service.BatchOptimizeToursRequest],
329
+ Awaitable[operations_pb2.Operation],
330
+ ]:
331
+ r"""Return a callable for the batch optimize tours method over gRPC.
332
+
333
+ Optimizes vehicle tours for one or more ``OptimizeToursRequest``
334
+ messages as a batch.
335
+
336
+ This method is a Long Running Operation (LRO). The inputs for
337
+ optimization (``OptimizeToursRequest`` messages) and outputs
338
+ (``OptimizeToursResponse`` messages) are read/written from/to
339
+ Cloud Storage in user-specified format. Like the
340
+ ``OptimizeTours`` method, each ``OptimizeToursRequest`` contains
341
+ a ``ShipmentModel`` and returns an ``OptimizeToursResponse``
342
+ containing ``ShipmentRoute``\ s, which are a set of routes to be
343
+ performed by vehicles minimizing the overall cost.
344
+
345
+ Returns:
346
+ Callable[[~.BatchOptimizeToursRequest],
347
+ Awaitable[~.Operation]]:
348
+ A function that, when called, will call the underlying RPC
349
+ on the server.
350
+ """
351
+ # Generate a "stub function" on-the-fly which will actually make
352
+ # the request.
353
+ # gRPC handles serialization and deserialization, so we just need
354
+ # to pass in the functions for each.
355
+ if "batch_optimize_tours" not in self._stubs:
356
+ self._stubs["batch_optimize_tours"] = self.grpc_channel.unary_unary(
357
+ "/google.maps.routeoptimization.v1.RouteOptimization/BatchOptimizeTours",
358
+ request_serializer=route_optimization_service.BatchOptimizeToursRequest.serialize,
359
+ response_deserializer=operations_pb2.Operation.FromString,
360
+ )
361
+ return self._stubs["batch_optimize_tours"]
362
+
363
+ def _prep_wrapped_messages(self, client_info):
364
+ """Precompute the wrapped methods, overriding the base class method to use async wrappers."""
365
+ self._wrapped_methods = {
366
+ self.optimize_tours: gapic_v1.method_async.wrap_method(
367
+ self.optimize_tours,
368
+ default_retry=retries.AsyncRetry(
369
+ initial=1.0,
370
+ maximum=10.0,
371
+ multiplier=1.3,
372
+ predicate=retries.if_exception_type(
373
+ core_exceptions.ServiceUnavailable,
374
+ ),
375
+ deadline=3600.0,
376
+ ),
377
+ default_timeout=3600.0,
378
+ client_info=client_info,
379
+ ),
380
+ self.batch_optimize_tours: gapic_v1.method_async.wrap_method(
381
+ self.batch_optimize_tours,
382
+ default_timeout=None,
383
+ client_info=client_info,
384
+ ),
385
+ }
386
+
387
+ def close(self):
388
+ return self.grpc_channel.close()
389
+
390
+ @property
391
+ def get_operation(
392
+ self,
393
+ ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]:
394
+ r"""Return a callable for the get_operation method over gRPC."""
395
+ # Generate a "stub function" on-the-fly which will actually make
396
+ # the request.
397
+ # gRPC handles serialization and deserialization, so we just need
398
+ # to pass in the functions for each.
399
+ if "get_operation" not in self._stubs:
400
+ self._stubs["get_operation"] = self.grpc_channel.unary_unary(
401
+ "/google.longrunning.Operations/GetOperation",
402
+ request_serializer=operations_pb2.GetOperationRequest.SerializeToString,
403
+ response_deserializer=operations_pb2.Operation.FromString,
404
+ )
405
+ return self._stubs["get_operation"]
406
+
407
+
408
+ __all__ = ("RouteOptimizationGrpcAsyncIOTransport",)