google-cloud-spanner 3.55.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.
- google/cloud/spanner.py +47 -0
- google/cloud/spanner_admin_database_v1/__init__.py +146 -0
- google/cloud/spanner_admin_database_v1/gapic_metadata.json +418 -0
- google/cloud/spanner_admin_database_v1/gapic_version.py +16 -0
- google/cloud/spanner_admin_database_v1/py.typed +2 -0
- google/cloud/spanner_admin_database_v1/services/__init__.py +15 -0
- google/cloud/spanner_admin_database_v1/services/database_admin/__init__.py +22 -0
- google/cloud/spanner_admin_database_v1/services/database_admin/async_client.py +4097 -0
- google/cloud/spanner_admin_database_v1/services/database_admin/client.py +4602 -0
- google/cloud/spanner_admin_database_v1/services/database_admin/pagers.py +989 -0
- google/cloud/spanner_admin_database_v1/services/database_admin/transports/__init__.py +38 -0
- google/cloud/spanner_admin_database_v1/services/database_admin/transports/base.py +820 -0
- google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc.py +1303 -0
- google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc_asyncio.py +1688 -0
- google/cloud/spanner_admin_database_v1/services/database_admin/transports/rest.py +6512 -0
- google/cloud/spanner_admin_database_v1/services/database_admin/transports/rest_base.py +1650 -0
- google/cloud/spanner_admin_database_v1/types/__init__.py +144 -0
- google/cloud/spanner_admin_database_v1/types/backup.py +1106 -0
- google/cloud/spanner_admin_database_v1/types/backup_schedule.py +369 -0
- google/cloud/spanner_admin_database_v1/types/common.py +180 -0
- google/cloud/spanner_admin_database_v1/types/spanner_database_admin.py +1303 -0
- google/cloud/spanner_admin_instance_v1/__init__.py +110 -0
- google/cloud/spanner_admin_instance_v1/gapic_metadata.json +343 -0
- google/cloud/spanner_admin_instance_v1/gapic_version.py +16 -0
- google/cloud/spanner_admin_instance_v1/py.typed +2 -0
- google/cloud/spanner_admin_instance_v1/services/__init__.py +15 -0
- google/cloud/spanner_admin_instance_v1/services/instance_admin/__init__.py +22 -0
- google/cloud/spanner_admin_instance_v1/services/instance_admin/async_client.py +3466 -0
- google/cloud/spanner_admin_instance_v1/services/instance_admin/client.py +3881 -0
- google/cloud/spanner_admin_instance_v1/services/instance_admin/pagers.py +856 -0
- google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/__init__.py +38 -0
- google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/base.py +545 -0
- google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc.py +1347 -0
- google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc_asyncio.py +1539 -0
- google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/rest.py +4834 -0
- google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/rest_base.py +1198 -0
- google/cloud/spanner_admin_instance_v1/types/__init__.py +104 -0
- google/cloud/spanner_admin_instance_v1/types/common.py +99 -0
- google/cloud/spanner_admin_instance_v1/types/spanner_instance_admin.py +2375 -0
- google/cloud/spanner_dbapi/__init__.py +93 -0
- google/cloud/spanner_dbapi/_helpers.py +113 -0
- google/cloud/spanner_dbapi/batch_dml_executor.py +135 -0
- google/cloud/spanner_dbapi/checksum.py +80 -0
- google/cloud/spanner_dbapi/client_side_statement_executor.py +140 -0
- google/cloud/spanner_dbapi/client_side_statement_parser.py +106 -0
- google/cloud/spanner_dbapi/connection.py +818 -0
- google/cloud/spanner_dbapi/cursor.py +609 -0
- google/cloud/spanner_dbapi/exceptions.py +172 -0
- google/cloud/spanner_dbapi/parse_utils.py +392 -0
- google/cloud/spanner_dbapi/parsed_statement.py +63 -0
- google/cloud/spanner_dbapi/parser.py +258 -0
- google/cloud/spanner_dbapi/partition_helper.py +41 -0
- google/cloud/spanner_dbapi/transaction_helper.py +294 -0
- google/cloud/spanner_dbapi/types.py +106 -0
- google/cloud/spanner_dbapi/utils.py +147 -0
- google/cloud/spanner_dbapi/version.py +20 -0
- google/cloud/spanner_v1/__init__.py +154 -0
- google/cloud/spanner_v1/_helpers.py +751 -0
- google/cloud/spanner_v1/_opentelemetry_tracing.py +165 -0
- google/cloud/spanner_v1/backup.py +397 -0
- google/cloud/spanner_v1/batch.py +433 -0
- google/cloud/spanner_v1/client.py +538 -0
- google/cloud/spanner_v1/data_types.py +350 -0
- google/cloud/spanner_v1/database.py +1968 -0
- google/cloud/spanner_v1/database_sessions_manager.py +249 -0
- google/cloud/spanner_v1/gapic_metadata.json +268 -0
- google/cloud/spanner_v1/gapic_version.py +16 -0
- google/cloud/spanner_v1/instance.py +735 -0
- google/cloud/spanner_v1/keyset.py +193 -0
- google/cloud/spanner_v1/merged_result_set.py +146 -0
- google/cloud/spanner_v1/metrics/constants.py +71 -0
- google/cloud/spanner_v1/metrics/metrics_capture.py +75 -0
- google/cloud/spanner_v1/metrics/metrics_exporter.py +384 -0
- google/cloud/spanner_v1/metrics/metrics_interceptor.py +156 -0
- google/cloud/spanner_v1/metrics/metrics_tracer.py +588 -0
- google/cloud/spanner_v1/metrics/metrics_tracer_factory.py +328 -0
- google/cloud/spanner_v1/metrics/spanner_metrics_tracer_factory.py +172 -0
- google/cloud/spanner_v1/param_types.py +110 -0
- google/cloud/spanner_v1/pool.py +813 -0
- google/cloud/spanner_v1/py.typed +2 -0
- google/cloud/spanner_v1/request_id_header.py +64 -0
- google/cloud/spanner_v1/services/__init__.py +15 -0
- google/cloud/spanner_v1/services/spanner/__init__.py +22 -0
- google/cloud/spanner_v1/services/spanner/async_client.py +2205 -0
- google/cloud/spanner_v1/services/spanner/client.py +2624 -0
- google/cloud/spanner_v1/services/spanner/pagers.py +196 -0
- google/cloud/spanner_v1/services/spanner/transports/__init__.py +38 -0
- google/cloud/spanner_v1/services/spanner/transports/base.py +520 -0
- google/cloud/spanner_v1/services/spanner/transports/grpc.py +911 -0
- google/cloud/spanner_v1/services/spanner/transports/grpc_asyncio.py +1144 -0
- google/cloud/spanner_v1/services/spanner/transports/rest.py +3468 -0
- google/cloud/spanner_v1/services/spanner/transports/rest_base.py +981 -0
- google/cloud/spanner_v1/session.py +631 -0
- google/cloud/spanner_v1/session_options.py +133 -0
- google/cloud/spanner_v1/snapshot.py +1057 -0
- google/cloud/spanner_v1/streamed.py +402 -0
- google/cloud/spanner_v1/table.py +181 -0
- google/cloud/spanner_v1/testing/__init__.py +0 -0
- google/cloud/spanner_v1/testing/database_test.py +121 -0
- google/cloud/spanner_v1/testing/interceptors.py +118 -0
- google/cloud/spanner_v1/testing/mock_database_admin.py +38 -0
- google/cloud/spanner_v1/testing/mock_spanner.py +261 -0
- google/cloud/spanner_v1/testing/spanner_database_admin_pb2_grpc.py +1267 -0
- google/cloud/spanner_v1/testing/spanner_pb2_grpc.py +882 -0
- google/cloud/spanner_v1/transaction.py +747 -0
- google/cloud/spanner_v1/types/__init__.py +118 -0
- google/cloud/spanner_v1/types/commit_response.py +94 -0
- google/cloud/spanner_v1/types/keys.py +248 -0
- google/cloud/spanner_v1/types/mutation.py +201 -0
- google/cloud/spanner_v1/types/query_plan.py +220 -0
- google/cloud/spanner_v1/types/result_set.py +379 -0
- google/cloud/spanner_v1/types/spanner.py +1815 -0
- google/cloud/spanner_v1/types/transaction.py +818 -0
- google/cloud/spanner_v1/types/type.py +288 -0
- google_cloud_spanner-3.55.0.dist-info/LICENSE +202 -0
- google_cloud_spanner-3.55.0.dist-info/METADATA +318 -0
- google_cloud_spanner-3.55.0.dist-info/RECORD +119 -0
- google_cloud_spanner-3.55.0.dist-info/WHEEL +5 -0
- google_cloud_spanner-3.55.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# Copyright 2025 Google LLC All rights reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
import os
|
|
15
|
+
from enum import Enum
|
|
16
|
+
from logging import Logger
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class TransactionType(Enum):
|
|
20
|
+
"""Transaction types for session options."""
|
|
21
|
+
|
|
22
|
+
READ_ONLY = "read-only"
|
|
23
|
+
PARTITIONED = "partitioned"
|
|
24
|
+
READ_WRITE = "read/write"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class SessionOptions(object):
|
|
28
|
+
"""Represents the session options for the Cloud Spanner Python client.
|
|
29
|
+
We can use ::class::`SessionOptions` to determine whether multiplexed sessions
|
|
30
|
+
should be used for a specific transaction type with :meth:`use_multiplexed`. The use
|
|
31
|
+
of multiplexed session can be disabled for a specific transaction type or for all
|
|
32
|
+
transaction types with :meth:`disable_multiplexed`.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
# Environment variables for multiplexed sessions
|
|
36
|
+
ENV_VAR_ENABLE_MULTIPLEXED = "GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS"
|
|
37
|
+
ENV_VAR_ENABLE_MULTIPLEXED_FOR_PARTITIONED = (
|
|
38
|
+
"GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_PARTITIONED_OPS"
|
|
39
|
+
)
|
|
40
|
+
ENV_VAR_ENABLE_MULTIPLEXED_FOR_READ_WRITE = (
|
|
41
|
+
"GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_FOR_RW"
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
def __init__(self):
|
|
45
|
+
# Internal overrides to disable the use of multiplexed
|
|
46
|
+
# sessions in case of runtime errors.
|
|
47
|
+
self._is_multiplexed_enabled = {
|
|
48
|
+
TransactionType.READ_ONLY: True,
|
|
49
|
+
TransactionType.PARTITIONED: True,
|
|
50
|
+
TransactionType.READ_WRITE: True,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
def use_multiplexed(self, transaction_type: TransactionType) -> bool:
|
|
54
|
+
"""Returns whether to use multiplexed sessions for the given transaction type.
|
|
55
|
+
Multiplexed sessions are enabled for read-only transactions if:
|
|
56
|
+
* ENV_VAR_ENABLE_MULTIPLEXED is set to true; and
|
|
57
|
+
* multiplexed sessions have not been disabled for read-only transactions.
|
|
58
|
+
Multiplexed sessions are enabled for partitioned transactions if:
|
|
59
|
+
* ENV_VAR_ENABLE_MULTIPLEXED is set to true;
|
|
60
|
+
* ENV_VAR_ENABLE_MULTIPLEXED_FOR_PARTITIONED is set to true; and
|
|
61
|
+
* multiplexed sessions have not been disabled for partitioned transactions.
|
|
62
|
+
Multiplexed sessions are **currently disabled** for read / write.
|
|
63
|
+
:type transaction_type: :class:`TransactionType`
|
|
64
|
+
:param transaction_type: the type of transaction to check whether
|
|
65
|
+
multiplexed sessions should be used.
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
if transaction_type is TransactionType.READ_ONLY:
|
|
69
|
+
return self._is_multiplexed_enabled[transaction_type] and self._getenv(
|
|
70
|
+
self.ENV_VAR_ENABLE_MULTIPLEXED
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
elif transaction_type is TransactionType.PARTITIONED:
|
|
74
|
+
return (
|
|
75
|
+
self._is_multiplexed_enabled[transaction_type]
|
|
76
|
+
and self._getenv(self.ENV_VAR_ENABLE_MULTIPLEXED)
|
|
77
|
+
and self._getenv(self.ENV_VAR_ENABLE_MULTIPLEXED_FOR_PARTITIONED)
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
elif transaction_type is TransactionType.READ_WRITE:
|
|
81
|
+
return False
|
|
82
|
+
|
|
83
|
+
raise ValueError(f"Transaction type {transaction_type} is not supported.")
|
|
84
|
+
|
|
85
|
+
def disable_multiplexed(
|
|
86
|
+
self, logger: Logger = None, transaction_type: TransactionType = None
|
|
87
|
+
) -> None:
|
|
88
|
+
"""Disables the use of multiplexed sessions for the given transaction type.
|
|
89
|
+
If no transaction type is specified, disables the use of multiplexed sessions
|
|
90
|
+
for all transaction types.
|
|
91
|
+
:type logger: :class:`Logger`
|
|
92
|
+
:param logger: logger to use for logging the disabling the use of multiplexed
|
|
93
|
+
sessions.
|
|
94
|
+
:type transaction_type: :class:`TransactionType`
|
|
95
|
+
:param transaction_type: (Optional) the type of transaction for which to disable
|
|
96
|
+
the use of multiplexed sessions.
|
|
97
|
+
"""
|
|
98
|
+
|
|
99
|
+
disable_multiplexed_log_msg_fstring = (
|
|
100
|
+
"Disabling multiplexed sessions for {transaction_type_value} transactions"
|
|
101
|
+
)
|
|
102
|
+
import logging
|
|
103
|
+
|
|
104
|
+
if logger is None:
|
|
105
|
+
logger = logging.getLogger(__name__)
|
|
106
|
+
|
|
107
|
+
if transaction_type is None:
|
|
108
|
+
logger.warning(
|
|
109
|
+
disable_multiplexed_log_msg_fstring.format(transaction_type_value="all")
|
|
110
|
+
)
|
|
111
|
+
for transaction_type in TransactionType:
|
|
112
|
+
self._is_multiplexed_enabled[transaction_type] = False
|
|
113
|
+
return
|
|
114
|
+
|
|
115
|
+
elif transaction_type in self._is_multiplexed_enabled.keys():
|
|
116
|
+
logger.warning(
|
|
117
|
+
disable_multiplexed_log_msg_fstring.format(
|
|
118
|
+
transaction_type_value=transaction_type.value
|
|
119
|
+
)
|
|
120
|
+
)
|
|
121
|
+
self._is_multiplexed_enabled[transaction_type] = False
|
|
122
|
+
return
|
|
123
|
+
|
|
124
|
+
raise ValueError(f"Transaction type '{transaction_type}' is not supported.")
|
|
125
|
+
|
|
126
|
+
@staticmethod
|
|
127
|
+
def _getenv(name: str) -> bool:
|
|
128
|
+
"""Returns the value of the given environment variable as a boolean.
|
|
129
|
+
True values are '1' and 'true' (case-insensitive); all other values are
|
|
130
|
+
considered false.
|
|
131
|
+
"""
|
|
132
|
+
env_var = os.getenv(name, "").lower().strip()
|
|
133
|
+
return env_var in ["1", "true"]
|