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.

Batch API

Context manager for Cloud Spanner batched writes.

class google.cloud.spanner_v1.batch.Batch(session)[source]

Bases: google.cloud.spanner_v1.batch._BatchBase

Accumulate mutations for transmission during commit().

__enter__()[source]

Begin with block.

__exit__(exc_type, exc_val, exc_tb)[source]

End with block.

commit(return_commit_stats=False, request_options=None)[source]

Commit mutations to the database.

Parameters
  • return_commit_stats (bool) – If true, the response will return commit stats which can be accessed though commit_stats.

  • request_options (google.cloud.spanner_v1.types.RequestOptions) – (Optional) Common options for this request. If a dict is provided, it must be of the same form as the protobuf message RequestOptions.

Return type

datetime

Returns

timestamp of the committed changes.

commit_stats = None

Timestamp at which the batch was successfully committed.