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.
Files changed (119) hide show
  1. google/cloud/spanner.py +47 -0
  2. google/cloud/spanner_admin_database_v1/__init__.py +146 -0
  3. google/cloud/spanner_admin_database_v1/gapic_metadata.json +418 -0
  4. google/cloud/spanner_admin_database_v1/gapic_version.py +16 -0
  5. google/cloud/spanner_admin_database_v1/py.typed +2 -0
  6. google/cloud/spanner_admin_database_v1/services/__init__.py +15 -0
  7. google/cloud/spanner_admin_database_v1/services/database_admin/__init__.py +22 -0
  8. google/cloud/spanner_admin_database_v1/services/database_admin/async_client.py +4097 -0
  9. google/cloud/spanner_admin_database_v1/services/database_admin/client.py +4602 -0
  10. google/cloud/spanner_admin_database_v1/services/database_admin/pagers.py +989 -0
  11. google/cloud/spanner_admin_database_v1/services/database_admin/transports/__init__.py +38 -0
  12. google/cloud/spanner_admin_database_v1/services/database_admin/transports/base.py +820 -0
  13. google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc.py +1303 -0
  14. google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc_asyncio.py +1688 -0
  15. google/cloud/spanner_admin_database_v1/services/database_admin/transports/rest.py +6512 -0
  16. google/cloud/spanner_admin_database_v1/services/database_admin/transports/rest_base.py +1650 -0
  17. google/cloud/spanner_admin_database_v1/types/__init__.py +144 -0
  18. google/cloud/spanner_admin_database_v1/types/backup.py +1106 -0
  19. google/cloud/spanner_admin_database_v1/types/backup_schedule.py +369 -0
  20. google/cloud/spanner_admin_database_v1/types/common.py +180 -0
  21. google/cloud/spanner_admin_database_v1/types/spanner_database_admin.py +1303 -0
  22. google/cloud/spanner_admin_instance_v1/__init__.py +110 -0
  23. google/cloud/spanner_admin_instance_v1/gapic_metadata.json +343 -0
  24. google/cloud/spanner_admin_instance_v1/gapic_version.py +16 -0
  25. google/cloud/spanner_admin_instance_v1/py.typed +2 -0
  26. google/cloud/spanner_admin_instance_v1/services/__init__.py +15 -0
  27. google/cloud/spanner_admin_instance_v1/services/instance_admin/__init__.py +22 -0
  28. google/cloud/spanner_admin_instance_v1/services/instance_admin/async_client.py +3466 -0
  29. google/cloud/spanner_admin_instance_v1/services/instance_admin/client.py +3881 -0
  30. google/cloud/spanner_admin_instance_v1/services/instance_admin/pagers.py +856 -0
  31. google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/__init__.py +38 -0
  32. google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/base.py +545 -0
  33. google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc.py +1347 -0
  34. google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc_asyncio.py +1539 -0
  35. google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/rest.py +4834 -0
  36. google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/rest_base.py +1198 -0
  37. google/cloud/spanner_admin_instance_v1/types/__init__.py +104 -0
  38. google/cloud/spanner_admin_instance_v1/types/common.py +99 -0
  39. google/cloud/spanner_admin_instance_v1/types/spanner_instance_admin.py +2375 -0
  40. google/cloud/spanner_dbapi/__init__.py +93 -0
  41. google/cloud/spanner_dbapi/_helpers.py +113 -0
  42. google/cloud/spanner_dbapi/batch_dml_executor.py +135 -0
  43. google/cloud/spanner_dbapi/checksum.py +80 -0
  44. google/cloud/spanner_dbapi/client_side_statement_executor.py +140 -0
  45. google/cloud/spanner_dbapi/client_side_statement_parser.py +106 -0
  46. google/cloud/spanner_dbapi/connection.py +818 -0
  47. google/cloud/spanner_dbapi/cursor.py +609 -0
  48. google/cloud/spanner_dbapi/exceptions.py +172 -0
  49. google/cloud/spanner_dbapi/parse_utils.py +392 -0
  50. google/cloud/spanner_dbapi/parsed_statement.py +63 -0
  51. google/cloud/spanner_dbapi/parser.py +258 -0
  52. google/cloud/spanner_dbapi/partition_helper.py +41 -0
  53. google/cloud/spanner_dbapi/transaction_helper.py +294 -0
  54. google/cloud/spanner_dbapi/types.py +106 -0
  55. google/cloud/spanner_dbapi/utils.py +147 -0
  56. google/cloud/spanner_dbapi/version.py +20 -0
  57. google/cloud/spanner_v1/__init__.py +154 -0
  58. google/cloud/spanner_v1/_helpers.py +751 -0
  59. google/cloud/spanner_v1/_opentelemetry_tracing.py +165 -0
  60. google/cloud/spanner_v1/backup.py +397 -0
  61. google/cloud/spanner_v1/batch.py +433 -0
  62. google/cloud/spanner_v1/client.py +538 -0
  63. google/cloud/spanner_v1/data_types.py +350 -0
  64. google/cloud/spanner_v1/database.py +1968 -0
  65. google/cloud/spanner_v1/database_sessions_manager.py +249 -0
  66. google/cloud/spanner_v1/gapic_metadata.json +268 -0
  67. google/cloud/spanner_v1/gapic_version.py +16 -0
  68. google/cloud/spanner_v1/instance.py +735 -0
  69. google/cloud/spanner_v1/keyset.py +193 -0
  70. google/cloud/spanner_v1/merged_result_set.py +146 -0
  71. google/cloud/spanner_v1/metrics/constants.py +71 -0
  72. google/cloud/spanner_v1/metrics/metrics_capture.py +75 -0
  73. google/cloud/spanner_v1/metrics/metrics_exporter.py +384 -0
  74. google/cloud/spanner_v1/metrics/metrics_interceptor.py +156 -0
  75. google/cloud/spanner_v1/metrics/metrics_tracer.py +588 -0
  76. google/cloud/spanner_v1/metrics/metrics_tracer_factory.py +328 -0
  77. google/cloud/spanner_v1/metrics/spanner_metrics_tracer_factory.py +172 -0
  78. google/cloud/spanner_v1/param_types.py +110 -0
  79. google/cloud/spanner_v1/pool.py +813 -0
  80. google/cloud/spanner_v1/py.typed +2 -0
  81. google/cloud/spanner_v1/request_id_header.py +64 -0
  82. google/cloud/spanner_v1/services/__init__.py +15 -0
  83. google/cloud/spanner_v1/services/spanner/__init__.py +22 -0
  84. google/cloud/spanner_v1/services/spanner/async_client.py +2205 -0
  85. google/cloud/spanner_v1/services/spanner/client.py +2624 -0
  86. google/cloud/spanner_v1/services/spanner/pagers.py +196 -0
  87. google/cloud/spanner_v1/services/spanner/transports/__init__.py +38 -0
  88. google/cloud/spanner_v1/services/spanner/transports/base.py +520 -0
  89. google/cloud/spanner_v1/services/spanner/transports/grpc.py +911 -0
  90. google/cloud/spanner_v1/services/spanner/transports/grpc_asyncio.py +1144 -0
  91. google/cloud/spanner_v1/services/spanner/transports/rest.py +3468 -0
  92. google/cloud/spanner_v1/services/spanner/transports/rest_base.py +981 -0
  93. google/cloud/spanner_v1/session.py +631 -0
  94. google/cloud/spanner_v1/session_options.py +133 -0
  95. google/cloud/spanner_v1/snapshot.py +1057 -0
  96. google/cloud/spanner_v1/streamed.py +402 -0
  97. google/cloud/spanner_v1/table.py +181 -0
  98. google/cloud/spanner_v1/testing/__init__.py +0 -0
  99. google/cloud/spanner_v1/testing/database_test.py +121 -0
  100. google/cloud/spanner_v1/testing/interceptors.py +118 -0
  101. google/cloud/spanner_v1/testing/mock_database_admin.py +38 -0
  102. google/cloud/spanner_v1/testing/mock_spanner.py +261 -0
  103. google/cloud/spanner_v1/testing/spanner_database_admin_pb2_grpc.py +1267 -0
  104. google/cloud/spanner_v1/testing/spanner_pb2_grpc.py +882 -0
  105. google/cloud/spanner_v1/transaction.py +747 -0
  106. google/cloud/spanner_v1/types/__init__.py +118 -0
  107. google/cloud/spanner_v1/types/commit_response.py +94 -0
  108. google/cloud/spanner_v1/types/keys.py +248 -0
  109. google/cloud/spanner_v1/types/mutation.py +201 -0
  110. google/cloud/spanner_v1/types/query_plan.py +220 -0
  111. google/cloud/spanner_v1/types/result_set.py +379 -0
  112. google/cloud/spanner_v1/types/spanner.py +1815 -0
  113. google/cloud/spanner_v1/types/transaction.py +818 -0
  114. google/cloud/spanner_v1/types/type.py +288 -0
  115. google_cloud_spanner-3.55.0.dist-info/LICENSE +202 -0
  116. google_cloud_spanner-3.55.0.dist-info/METADATA +318 -0
  117. google_cloud_spanner-3.55.0.dist-info/RECORD +119 -0
  118. google_cloud_spanner-3.55.0.dist-info/WHEEL +5 -0
  119. google_cloud_spanner-3.55.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,147 @@
1
+ # Copyright 2020 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
+
15
+ import re
16
+
17
+ re_UNICODE_POINTS = re.compile(r"([^\s]*[\u0080-\uFFFF]+[^\s]*)")
18
+
19
+
20
+ class PeekIterator:
21
+ """
22
+ Peek at the first element out of an iterator for the sake of operations
23
+ like auto-population of fields on reading the first element.
24
+ If next's result is an instance of list, it'll be converted into a tuple to
25
+ conform with DBAPI v2's sequence expectations.
26
+
27
+ :type source: list
28
+ :param source: A list of source for the Iterator.
29
+ """
30
+
31
+ def __init__(self, source):
32
+ itr_src = iter(source)
33
+
34
+ self.__iters = []
35
+ self.__index = 0
36
+
37
+ try:
38
+ head = next(itr_src)
39
+ # Restitch and prepare to read from multiple iterators.
40
+ self.__iters = [iter(itr) for itr in [[head], itr_src]]
41
+ except StopIteration:
42
+ pass
43
+
44
+ def __next__(self):
45
+ if self.__index >= len(self.__iters):
46
+ raise StopIteration
47
+
48
+ iterator = self.__iters[self.__index]
49
+ try:
50
+ head = next(iterator)
51
+ except StopIteration:
52
+ # That iterator has been exhausted, try with the next one.
53
+ self.__index += 1
54
+ return self.__next__()
55
+ else:
56
+ return tuple(head) if isinstance(head, list) else head
57
+
58
+ def __iter__(self):
59
+ return self
60
+
61
+
62
+ class StreamedManyResultSets:
63
+ """Iterator to walk through several `StreamedResultsSet` iterators.
64
+ This type of iterator is used by `Cursor.executemany()`
65
+ method to iterate through several `StreamedResultsSet`
66
+ iterators like they all are merged into single iterator.
67
+ """
68
+
69
+ def __init__(self):
70
+ self._iterators = []
71
+ self._index = 0
72
+
73
+ def add_iter(self, iterator):
74
+ """Add new iterator into this one.
75
+ :type iterator: :class:`google.cloud.spanner_v1.streamed.StreamedResultSet`
76
+ :param iterator: Iterator to merge into this one.
77
+ """
78
+ self._iterators.append(iterator)
79
+
80
+ def __next__(self):
81
+ """Return the next value from the currently streamed iterator.
82
+ If the current iterator is streamed to the end,
83
+ start to stream the next one.
84
+ :rtype: list
85
+ :returns: The next result row.
86
+ """
87
+ try:
88
+ res = next(self._iterators[self._index])
89
+ except StopIteration:
90
+ self._index += 1
91
+ res = self.__next__()
92
+ except IndexError:
93
+ raise StopIteration
94
+
95
+ return res
96
+
97
+ def __iter__(self):
98
+ return self
99
+
100
+
101
+ def backtick_unicode(sql):
102
+ """Check the SQL to be valid and split it by segments.
103
+
104
+ :type sql: str
105
+ :param sql: A SQL request.
106
+
107
+ :rtype: str
108
+ :returns: A SQL parsed by segments in unicode if initial SQL is valid,
109
+ initial string otherwise.
110
+ """
111
+ matches = list(re_UNICODE_POINTS.finditer(sql))
112
+ if not matches:
113
+ return sql
114
+
115
+ segments = []
116
+
117
+ last_end = 0
118
+ for match in matches:
119
+ start, end = match.span()
120
+ if sql[start] != "`" and sql[end - 1] != "`":
121
+ segments.append(sql[last_end:start] + "`" + sql[start:end] + "`")
122
+ else:
123
+ segments.append(sql[last_end:end])
124
+
125
+ last_end = end
126
+
127
+ return "".join(segments)
128
+
129
+
130
+ def sanitize_literals_for_upload(s):
131
+ """Convert literals in s, to be fit for consumption by Cloud Spanner.
132
+
133
+ * Convert %% (escaped percent literals) to %. Percent signs must be escaped
134
+ when values like %s are used as SQL parameter placeholders but Spanner's
135
+ query language uses placeholders like @a0 and doesn't expect percent
136
+ signs to be escaped.
137
+ * Quote words containing non-ASCII, with backticks, for example föö to
138
+ `föö`.
139
+
140
+ :type s: str
141
+ :param s: A string with literals to escaped for consumption by Cloud
142
+ Spanner.
143
+
144
+ :rtype: str
145
+ :returns: A sanitized string for uploading.
146
+ """
147
+ return backtick_unicode(s.replace("%%", "%"))
@@ -0,0 +1,20 @@
1
+ # Copyright 2020 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
+
15
+ import platform
16
+ from google.cloud.spanner_v1 import gapic_version as package_version
17
+
18
+ PY_VERSION = platform.python_version()
19
+ VERSION = package_version.__version__
20
+ DEFAULT_USER_AGENT = "gl-dbapi/" + VERSION
@@ -0,0 +1,154 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # Copyright 2020 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ from __future__ import absolute_import
18
+
19
+ from google.cloud.spanner_v1 import gapic_version as package_version
20
+
21
+ __version__: str = package_version.__version__
22
+
23
+ from .services.spanner import SpannerClient
24
+ from .services.spanner import SpannerAsyncClient
25
+ from .types.commit_response import CommitResponse
26
+ from .types.keys import KeyRange as KeyRangePB
27
+ from .types.keys import KeySet as KeySetPB
28
+ from .types.mutation import Mutation
29
+ from .types.query_plan import PlanNode
30
+ from .types.query_plan import QueryPlan
31
+ from .types.result_set import PartialResultSet
32
+ from .types import RequestOptions
33
+ from .types.result_set import ResultSet
34
+ from .types.result_set import ResultSetMetadata
35
+ from .types.result_set import ResultSetStats
36
+ from .types.spanner import BatchCreateSessionsRequest
37
+ from .types.spanner import BatchCreateSessionsResponse
38
+ from .types.spanner import BatchWriteRequest
39
+ from .types.spanner import BatchWriteResponse
40
+ from .types.spanner import BeginTransactionRequest
41
+ from .types.spanner import CommitRequest
42
+ from .types.spanner import CreateSessionRequest
43
+ from .types.spanner import DeleteSessionRequest
44
+ from .types.spanner import DirectedReadOptions
45
+ from .types.spanner import ExecuteBatchDmlRequest
46
+ from .types.spanner import ExecuteBatchDmlResponse
47
+ from .types.spanner import ExecuteSqlRequest
48
+ from .types.spanner import GetSessionRequest
49
+ from .types.spanner import ListSessionsRequest
50
+ from .types.spanner import ListSessionsResponse
51
+ from .types.spanner import Partition
52
+ from .types.spanner import PartitionOptions
53
+ from .types.spanner import PartitionQueryRequest
54
+ from .types.spanner import PartitionReadRequest
55
+ from .types.spanner import PartitionResponse
56
+ from .types.spanner import ReadRequest
57
+ from .types.spanner import RollbackRequest
58
+ from .types.spanner import Session
59
+ from .types.transaction import Transaction
60
+ from .types.transaction import TransactionOptions
61
+ from .types.transaction import TransactionSelector
62
+ from .types.type import StructType
63
+ from .types.type import Type
64
+ from .types.type import TypeAnnotationCode
65
+ from .types.type import TypeCode
66
+ from .data_types import JsonObject, Interval
67
+ from .transaction import BatchTransactionId, DefaultTransactionOptions
68
+
69
+ from google.cloud.spanner_v1 import param_types
70
+ from google.cloud.spanner_v1.client import Client
71
+ from google.cloud.spanner_v1.keyset import KeyRange
72
+ from google.cloud.spanner_v1.keyset import KeySet
73
+ from google.cloud.spanner_v1.pool import AbstractSessionPool
74
+ from google.cloud.spanner_v1.pool import BurstyPool
75
+ from google.cloud.spanner_v1.pool import FixedSizePool
76
+ from google.cloud.spanner_v1.pool import PingingPool
77
+ from google.cloud.spanner_v1.pool import TransactionPingingPool
78
+
79
+
80
+ COMMIT_TIMESTAMP = "spanner.commit_timestamp()"
81
+ """Placeholder be used to store commit timestamp of a transaction in a column.
82
+ This value can only be used for timestamp columns that have set the option
83
+ ``(allow_commit_timestamp=true)`` in the schema.
84
+ """
85
+
86
+
87
+ __all__ = (
88
+ # google.cloud.spanner_v1
89
+ "__version__",
90
+ "param_types",
91
+ # google.cloud.spanner_v1.client
92
+ "Client",
93
+ # google.cloud.spanner_v1.keyset
94
+ "KeyRange",
95
+ "KeySet",
96
+ # google.cloud.spanner_v1.pool
97
+ "AbstractSessionPool",
98
+ "BurstyPool",
99
+ "FixedSizePool",
100
+ "PingingPool",
101
+ "TransactionPingingPool",
102
+ # local
103
+ "COMMIT_TIMESTAMP",
104
+ # google.cloud.spanner_v1.types
105
+ "BatchCreateSessionsRequest",
106
+ "BatchCreateSessionsResponse",
107
+ "BatchWriteRequest",
108
+ "BatchWriteResponse",
109
+ "BeginTransactionRequest",
110
+ "CommitRequest",
111
+ "CommitResponse",
112
+ "CreateSessionRequest",
113
+ "DeleteSessionRequest",
114
+ "DirectedReadOptions",
115
+ "ExecuteBatchDmlRequest",
116
+ "ExecuteBatchDmlResponse",
117
+ "ExecuteSqlRequest",
118
+ "GetSessionRequest",
119
+ "KeyRangePB",
120
+ "KeySetPB",
121
+ "ListSessionsRequest",
122
+ "ListSessionsResponse",
123
+ "Mutation",
124
+ "PartialResultSet",
125
+ "Partition",
126
+ "PartitionOptions",
127
+ "PartitionQueryRequest",
128
+ "PartitionReadRequest",
129
+ "PartitionResponse",
130
+ "PlanNode",
131
+ "QueryPlan",
132
+ "ReadRequest",
133
+ "RequestOptions",
134
+ "ResultSet",
135
+ "ResultSetMetadata",
136
+ "ResultSetStats",
137
+ "RollbackRequest",
138
+ "Session",
139
+ "StructType",
140
+ "Transaction",
141
+ "TransactionOptions",
142
+ "TransactionSelector",
143
+ "Type",
144
+ "TypeAnnotationCode",
145
+ "TypeCode",
146
+ # Custom spanner related data types
147
+ "JsonObject",
148
+ "Interval",
149
+ # google.cloud.spanner_v1.services
150
+ "SpannerClient",
151
+ "SpannerAsyncClient",
152
+ "BatchTransactionId",
153
+ "DefaultTransactionOptions",
154
+ )