As of January 1, 2020 this library no longer supports Python 2 on the latest released version. Library versions released prior to that date will continue to be available. For more information please visit Python 2 support on Google Cloud.

Long-Running Operations Client

Package for interacting with the google.longrunning.operations meta-API.

class google.api_core.operations_v1.OperationsClient(channel, client_config={'interfaces': {'google.longrunning.Operations': {'methods': {'CancelOperation': {'retry_codes_name': 'idempotent', 'retry_params_name': 'default', 'timeout_millis': 60000}, 'DeleteOperation': {'retry_codes_name': 'idempotent', 'retry_params_name': 'default', 'timeout_millis': 60000}, 'GetOperation': {'retry_codes_name': 'idempotent', 'retry_params_name': 'default', 'timeout_millis': 60000}, 'ListOperations': {'retry_codes_name': 'idempotent', 'retry_params_name': 'default', 'timeout_millis': 60000}}, 'retry_codes': {'idempotent': ['DEADLINE_EXCEEDED', 'UNAVAILABLE'], 'non_idempotent': []}, 'retry_params': {'default': {'initial_retry_delay_millis': 100, 'initial_rpc_timeout_millis': 20000, 'max_retry_delay_millis': 60000, 'max_rpc_timeout_millis': 600000, 'retry_delay_multiplier': 1.3, 'rpc_timeout_multiplier': 1.0, 'total_timeout_millis': 600000}}}}})[source]

Bases: object

Client for interacting with long-running operations within a service.

Parameters
  • channel (grpc.Channel) – The gRPC channel associated with the service that implements the google.longrunning.operations interface.

  • client_config (dict) – A dictionary of call options for each method. If not specified the default configuration is used.

cancel_operation(name, retry=<object object>, timeout=<object object>, metadata=None)[source]

Starts asynchronous cancellation on a long-running operation.

The server makes a best effort to cancel the operation, but success is not guaranteed. Clients can use get_operation() or service- specific methods to check whether the cancellation succeeded or whether the operation completed despite cancellation. On successful cancellation, the operation is not deleted; instead, it becomes an operation with an Operation.error value with a google.rpc.Status.code of 1, corresponding to Code.CANCELLED.

Example

>>> from google.api_core import operations_v1
>>> api = operations_v1.OperationsClient()
>>> name = ''
>>> api.cancel_operation(name)
Parameters
  • name (str) – The name of the operation resource to be cancelled.

  • retry (google.api_core.retry.Retry) – The retry strategy to use when invoking the RPC. If unspecified, the default retry from the client configuration will be used. If None, then this method will not retry the RPC at all.

  • timeout (float) – The amount of time in seconds to wait for the RPC to complete. Note that if retry is used, this timeout applies to each individual attempt and the overall time it takes for this method to complete may be longer. If unspecified, the the default timeout in the client configuration is used. If None, then the RPC method will not time out.

  • metadata (Optional[List[Tuple[str, str]]]) – Additional gRPC metadata.

Raises
delete_operation(name, retry=<object object>, timeout=<object object>, metadata=None)[source]

Deletes a long-running operation.

This method indicates that the client is no longer interested in the operation result. It does not cancel the operation.

Example

>>> from google.api_core import operations_v1
>>> api = operations_v1.OperationsClient()
>>> name = ''
>>> api.delete_operation(name)
Parameters
  • name (str) – The name of the operation resource to be deleted.

  • retry (google.api_core.retry.Retry) – The retry strategy to use when invoking the RPC. If unspecified, the default retry from the client configuration will be used. If None, then this method will not retry the RPC at all.

  • timeout (float) – The amount of time in seconds to wait for the RPC to complete. Note that if retry is used, this timeout applies to each individual attempt and the overall time it takes for this method to complete may be longer. If unspecified, the the default timeout in the client configuration is used. If None, then the RPC method will not time out.

  • metadata (Optional[List[Tuple[str, str]]]) – Additional gRPC metadata.

Raises
get_operation(name, retry=<object object>, timeout=<object object>, metadata=None)[source]

Gets the latest state of a long-running operation.

Clients can use this method to poll the operation result at intervals as recommended by the API service.

Example

>>> from google.api_core import operations_v1
>>> api = operations_v1.OperationsClient()
>>> name = ''
>>> response = api.get_operation(name)
Parameters
  • name (str) – The name of the operation resource.

  • retry (google.api_core.retry.Retry) – The retry strategy to use when invoking the RPC. If unspecified, the default retry from the client configuration will be used. If None, then this method will not retry the RPC at all.

  • timeout (float) – The amount of time in seconds to wait for the RPC to complete. Note that if retry is used, this timeout applies to each individual attempt and the overall time it takes for this method to complete may be longer. If unspecified, the the default timeout in the client configuration is used. If None, then the RPC method will not time out.

  • metadata (Optional[List[Tuple[str, str]]]) – Additional gRPC metadata.

Returns

The state of the

operation.

Return type

google.longrunning.operations_pb2.Operation

Raises

google.api_core.exceptions.GoogleAPICallError – If an error occurred while invoking the RPC, the appropriate GoogleAPICallError subclass will be raised.

list_operations(name, filter_, retry=<object object>, timeout=<object object>, metadata=None)[source]

Lists operations that match the specified filter in the request.

Example

>>> from google.api_core import operations_v1
>>> api = operations_v1.OperationsClient()
>>> name = ''
>>>
>>> # Iterate over all results
>>> for operation in api.list_operations(name):
>>>   # process operation
>>>   pass
>>>
>>> # Or iterate over results one page at a time
>>> iter = api.list_operations(name)
>>> for page in iter.pages:
>>>   for operation in page:
>>>     # process operation
>>>     pass
Parameters
  • name (str) – The name of the operation collection.

  • filter_ (str) – The standard list filter.

  • retry (google.api_core.retry.Retry) – The retry strategy to use when invoking the RPC. If unspecified, the default retry from the client configuration will be used. If None, then this method will not retry the RPC at all.

  • timeout (float) – The amount of time in seconds to wait for the RPC to complete. Note that if retry is used, this timeout applies to each individual attempt and the overall time it takes for this method to complete may be longer. If unspecified, the the default timeout in the client configuration is used. If None, then the RPC method will not time out.

  • metadata (Optional[List[Tuple[str, str]]]) – Additional gRPC metadata.

Returns

An iterator that yields

google.longrunning.operations_pb2.Operation instances.

Return type

google.api_core.page_iterator.Iterator

Raises
class google.api_core.operations_v1.OperationsAsyncClient(channel, client_config={'interfaces': {'google.longrunning.Operations': {'methods': {'CancelOperation': {'retry_codes_name': 'idempotent', 'retry_params_name': 'default', 'timeout_millis': 60000}, 'DeleteOperation': {'retry_codes_name': 'idempotent', 'retry_params_name': 'default', 'timeout_millis': 60000}, 'GetOperation': {'retry_codes_name': 'idempotent', 'retry_params_name': 'default', 'timeout_millis': 60000}, 'ListOperations': {'retry_codes_name': 'idempotent', 'retry_params_name': 'default', 'timeout_millis': 60000}}, 'retry_codes': {'idempotent': ['DEADLINE_EXCEEDED', 'UNAVAILABLE'], 'non_idempotent': []}, 'retry_params': {'default': {'initial_retry_delay_millis': 100, 'initial_rpc_timeout_millis': 20000, 'max_retry_delay_millis': 60000, 'max_rpc_timeout_millis': 600000, 'retry_delay_multiplier': 1.3, 'rpc_timeout_multiplier': 1.0, 'total_timeout_millis': 600000}}}}})[source]

Bases: object

Async client for interacting with long-running operations.

Parameters
  • channel (aio.Channel) – The gRPC AsyncIO channel associated with the service that implements the google.longrunning.operations interface.

  • client_config (dict) – A dictionary of call options for each method. If not specified the default configuration is used.

async cancel_operation(name, retry=<object object>, timeout=<object object>, metadata=None)[source]

Starts asynchronous cancellation on a long-running operation.

The server makes a best effort to cancel the operation, but success is not guaranteed. Clients can use get_operation() or service- specific methods to check whether the cancellation succeeded or whether the operation completed despite cancellation. On successful cancellation, the operation is not deleted; instead, it becomes an operation with an Operation.error value with a google.rpc.Status.code of 1, corresponding to Code.CANCELLED.

Example

>>> from google.api_core import operations_v1
>>> api = operations_v1.OperationsClient()
>>> name = ''
>>> api.cancel_operation(name)
Parameters
  • name (str) – The name of the operation resource to be cancelled.

  • retry (google.api_core.retry.Retry) – The retry strategy to use when invoking the RPC. If unspecified, the default retry from the client configuration will be used. If None, then this method will not retry the RPC at all.

  • timeout (float) – The amount of time in seconds to wait for the RPC to complete. Note that if retry is used, this timeout applies to each individual attempt and the overall time it takes for this method to complete may be longer. If unspecified, the the default timeout in the client configuration is used. If None, then the RPC method will not time out.

Raises
async delete_operation(name, retry=<object object>, timeout=<object object>, metadata=None)[source]

Deletes a long-running operation.

This method indicates that the client is no longer interested in the operation result. It does not cancel the operation.

Example

>>> from google.api_core import operations_v1
>>> api = operations_v1.OperationsClient()
>>> name = ''
>>> api.delete_operation(name)
Parameters
  • name (str) – The name of the operation resource to be deleted.

  • retry (google.api_core.retry.Retry) – The retry strategy to use when invoking the RPC. If unspecified, the default retry from the client configuration will be used. If None, then this method will not retry the RPC at all.

  • timeout (float) – The amount of time in seconds to wait for the RPC to complete. Note that if retry is used, this timeout applies to each individual attempt and the overall time it takes for this method to complete may be longer. If unspecified, the the default timeout in the client configuration is used. If None, then the RPC method will not time out.

  • metadata (Optional[List[Tuple[str, str]]]) – Additional gRPC metadata.

Raises
async get_operation(name, retry=<object object>, timeout=<object object>, metadata=None)[source]

Gets the latest state of a long-running operation.

Clients can use this method to poll the operation result at intervals as recommended by the API service.

Example

>>> from google.api_core import operations_v1
>>> api = operations_v1.OperationsClient()
>>> name = ''
>>> response = await api.get_operation(name)
Parameters
  • name (str) – The name of the operation resource.

  • retry (google.api_core.retry.Retry) – The retry strategy to use when invoking the RPC. If unspecified, the default retry from the client configuration will be used. If None, then this method will not retry the RPC at all.

  • timeout (float) – The amount of time in seconds to wait for the RPC to complete. Note that if retry is used, this timeout applies to each individual attempt and the overall time it takes for this method to complete may be longer. If unspecified, the the default timeout in the client configuration is used. If None, then the RPC method will not time out.

  • metadata (Optional[List[Tuple[str, str]]]) – Additional gRPC metadata.

Returns

The state of the

operation.

Return type

google.longrunning.operations_pb2.Operation

Raises

google.api_core.exceptions.GoogleAPICallError – If an error occurred while invoking the RPC, the appropriate GoogleAPICallError subclass will be raised.

async list_operations(name, filter_, retry=<object object>, timeout=<object object>, metadata=None)[source]

Lists operations that match the specified filter in the request.

Example

>>> from google.api_core import operations_v1
>>> api = operations_v1.OperationsClient()
>>> name = ''
>>>
>>> # Iterate over all results
>>> for operation in await api.list_operations(name):
>>>   # process operation
>>>   pass
>>>
>>> # Or iterate over results one page at a time
>>> iter = await api.list_operations(name)
>>> for page in iter.pages:
>>>   for operation in page:
>>>     # process operation
>>>     pass
Parameters
  • name (str) – The name of the operation collection.

  • filter_ (str) – The standard list filter.

  • retry (google.api_core.retry.Retry) – The retry strategy to use when invoking the RPC. If unspecified, the default retry from the client configuration will be used. If None, then this method will not retry the RPC at all.

  • timeout (float) – The amount of time in seconds to wait for the RPC to complete. Note that if retry is used, this timeout applies to each individual attempt and the overall time it takes for this method to complete may be longer. If unspecified, the the default timeout in the client configuration is used. If None, then the RPC method will not time out.

  • metadata (Optional[List[Tuple[str, str]]]) – Additional gRPC metadata.

Returns

An iterator that yields

google.longrunning.operations_pb2.Operation instances.

Return type

google.api_core.page_iterator.Iterator

Raises