1# -*- coding: utf-8 -*-
2# Copyright 2025 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#
16from google.pubsub_v1 import gapic_version as package_version
17
18import google.api_core as api_core
19import sys
20
21__version__ = package_version.__version__
22
23if sys.version_info >= (3, 8): # pragma: NO COVER
24 from importlib import metadata
25else: # pragma: NO COVER
26 # TODO(https://github.com/googleapis/python-api-core/issues/835): Remove
27 # this code path once we drop support for Python 3.7
28 import importlib_metadata as metadata
29
30
31from .services.publisher import PublisherClient
32from .services.publisher import PublisherAsyncClient
33from .services.schema_service import SchemaServiceClient
34from .services.schema_service import SchemaServiceAsyncClient
35from .services.subscriber import SubscriberClient
36from .services.subscriber import SubscriberAsyncClient
37
38from .types.pubsub import AcknowledgeRequest
39from .types.pubsub import BigQueryConfig
40from .types.pubsub import CloudStorageConfig
41from .types.pubsub import CreateSnapshotRequest
42from .types.pubsub import DeadLetterPolicy
43from .types.pubsub import DeleteSnapshotRequest
44from .types.pubsub import DeleteSubscriptionRequest
45from .types.pubsub import DeleteTopicRequest
46from .types.pubsub import DetachSubscriptionRequest
47from .types.pubsub import DetachSubscriptionResponse
48from .types.pubsub import ExpirationPolicy
49from .types.pubsub import GetSnapshotRequest
50from .types.pubsub import GetSubscriptionRequest
51from .types.pubsub import GetTopicRequest
52from .types.pubsub import IngestionDataSourceSettings
53from .types.pubsub import IngestionFailureEvent
54from .types.pubsub import JavaScriptUDF
55from .types.pubsub import ListSnapshotsRequest
56from .types.pubsub import ListSnapshotsResponse
57from .types.pubsub import ListSubscriptionsRequest
58from .types.pubsub import ListSubscriptionsResponse
59from .types.pubsub import ListTopicSnapshotsRequest
60from .types.pubsub import ListTopicSnapshotsResponse
61from .types.pubsub import ListTopicsRequest
62from .types.pubsub import ListTopicsResponse
63from .types.pubsub import ListTopicSubscriptionsRequest
64from .types.pubsub import ListTopicSubscriptionsResponse
65from .types.pubsub import MessageStoragePolicy
66from .types.pubsub import MessageTransform
67from .types.pubsub import ModifyAckDeadlineRequest
68from .types.pubsub import ModifyPushConfigRequest
69from .types.pubsub import PlatformLogsSettings
70from .types.pubsub import PublishRequest
71from .types.pubsub import PublishResponse
72from .types.pubsub import PubsubMessage
73from .types.pubsub import PullRequest
74from .types.pubsub import PullResponse
75from .types.pubsub import PushConfig
76from .types.pubsub import ReceivedMessage
77from .types.pubsub import RetryPolicy
78from .types.pubsub import SchemaSettings
79from .types.pubsub import SeekRequest
80from .types.pubsub import SeekResponse
81from .types.pubsub import Snapshot
82from .types.pubsub import StreamingPullRequest
83from .types.pubsub import StreamingPullResponse
84from .types.pubsub import Subscription
85from .types.pubsub import Topic
86from .types.pubsub import UpdateSnapshotRequest
87from .types.pubsub import UpdateSubscriptionRequest
88from .types.pubsub import UpdateTopicRequest
89from .types.schema import CommitSchemaRequest
90from .types.schema import CreateSchemaRequest
91from .types.schema import DeleteSchemaRequest
92from .types.schema import DeleteSchemaRevisionRequest
93from .types.schema import GetSchemaRequest
94from .types.schema import ListSchemaRevisionsRequest
95from .types.schema import ListSchemaRevisionsResponse
96from .types.schema import ListSchemasRequest
97from .types.schema import ListSchemasResponse
98from .types.schema import RollbackSchemaRequest
99from .types.schema import Schema
100from .types.schema import ValidateMessageRequest
101from .types.schema import ValidateMessageResponse
102from .types.schema import ValidateSchemaRequest
103from .types.schema import ValidateSchemaResponse
104from .types.schema import Encoding
105from .types.schema import SchemaView
106
107if hasattr(api_core, "check_python_version") and hasattr(
108 api_core, "check_dependency_versions"
109): # pragma: NO COVER
110 api_core.check_python_version("google.pubsub_v1") # type: ignore
111 api_core.check_dependency_versions("google.pubsub_v1") # type: ignore
112else: # pragma: NO COVER
113 # An older version of api_core is installed which does not define the
114 # functions above. We do equivalent checks manually.
115 try:
116 import warnings
117 import sys
118
119 _py_version_str = sys.version.split()[0]
120 _package_label = "google.pubsub_v1"
121 if sys.version_info < (3, 9):
122 warnings.warn(
123 "You are using a non-supported Python version "
124 + f"({_py_version_str}). Google will not post any further "
125 + f"updates to {_package_label} supporting this Python version. "
126 + "Please upgrade to the latest Python version, or at "
127 + f"least to Python 3.9, and then update {_package_label}.",
128 FutureWarning,
129 )
130 if sys.version_info[:2] == (3, 9):
131 warnings.warn(
132 f"You are using a Python version ({_py_version_str}) "
133 + f"which Google will stop supporting in {_package_label} in "
134 + "January 2026. Please "
135 + "upgrade to the latest Python version, or at "
136 + "least to Python 3.10, before then, and "
137 + f"then update {_package_label}.",
138 FutureWarning,
139 )
140
141 def parse_version_to_tuple(version_string: str):
142 """Safely converts a semantic version string to a comparable tuple of integers.
143 Example: "4.25.8" -> (4, 25, 8)
144 Ignores non-numeric parts and handles common version formats.
145 Args:
146 version_string: Version string in the format "x.y.z" or "x.y.z<suffix>"
147 Returns:
148 Tuple of integers for the parsed version string.
149 """
150 parts = []
151 for part in version_string.split("."):
152 try:
153 parts.append(int(part))
154 except ValueError:
155 # If it's a non-numeric part (e.g., '1.0.0b1' -> 'b1'), stop here.
156 # This is a simplification compared to 'packaging.parse_version', but sufficient
157 # for comparing strictly numeric semantic versions.
158 break
159 return tuple(parts)
160
161 def _get_version(dependency_name):
162 try:
163 version_string: str = metadata.version(dependency_name)
164 parsed_version = parse_version_to_tuple(version_string)
165 return (parsed_version, version_string)
166 except Exception:
167 # Catch exceptions from metadata.version() (e.g., PackageNotFoundError)
168 # or errors during parse_version_to_tuple
169 return (None, "--")
170
171 _dependency_package = "google.protobuf"
172 _next_supported_version = "4.25.8"
173 _next_supported_version_tuple = (4, 25, 8)
174 _recommendation = " (we recommend 6.x)"
175 (_version_used, _version_used_string) = _get_version(_dependency_package)
176 if _version_used and _version_used < _next_supported_version_tuple:
177 warnings.warn(
178 f"Package {_package_label} depends on "
179 + f"{_dependency_package}, currently installed at version "
180 + f"{_version_used_string}. Future updates to "
181 + f"{_package_label} will require {_dependency_package} at "
182 + f"version {_next_supported_version} or higher{_recommendation}."
183 + " Please ensure "
184 + "that either (a) your Python environment doesn't pin the "
185 + f"version of {_dependency_package}, so that updates to "
186 + f"{_package_label} can require the higher version, or "
187 + "(b) you manually update your Python environment to use at "
188 + f"least version {_next_supported_version} of "
189 + f"{_dependency_package}.",
190 FutureWarning,
191 )
192 except Exception:
193 warnings.warn(
194 "Could not determine the version of Python "
195 + "currently being used. To continue receiving "
196 + "updates for {_package_label}, ensure you are "
197 + "using a supported version of Python; see "
198 + "https://devguide.python.org/versions/"
199 )
200
201__all__ = (
202 "PublisherAsyncClient",
203 "SchemaServiceAsyncClient",
204 "SubscriberAsyncClient",
205 "AcknowledgeRequest",
206 "BigQueryConfig",
207 "CloudStorageConfig",
208 "CommitSchemaRequest",
209 "CreateSchemaRequest",
210 "CreateSnapshotRequest",
211 "DeadLetterPolicy",
212 "DeleteSchemaRequest",
213 "DeleteSchemaRevisionRequest",
214 "DeleteSnapshotRequest",
215 "DeleteSubscriptionRequest",
216 "DeleteTopicRequest",
217 "DetachSubscriptionRequest",
218 "DetachSubscriptionResponse",
219 "Encoding",
220 "ExpirationPolicy",
221 "GetSchemaRequest",
222 "GetSnapshotRequest",
223 "GetSubscriptionRequest",
224 "GetTopicRequest",
225 "IngestionDataSourceSettings",
226 "IngestionFailureEvent",
227 "JavaScriptUDF",
228 "ListSchemaRevisionsRequest",
229 "ListSchemaRevisionsResponse",
230 "ListSchemasRequest",
231 "ListSchemasResponse",
232 "ListSnapshotsRequest",
233 "ListSnapshotsResponse",
234 "ListSubscriptionsRequest",
235 "ListSubscriptionsResponse",
236 "ListTopicSnapshotsRequest",
237 "ListTopicSnapshotsResponse",
238 "ListTopicSubscriptionsRequest",
239 "ListTopicSubscriptionsResponse",
240 "ListTopicsRequest",
241 "ListTopicsResponse",
242 "MessageStoragePolicy",
243 "MessageTransform",
244 "ModifyAckDeadlineRequest",
245 "ModifyPushConfigRequest",
246 "PlatformLogsSettings",
247 "PublishRequest",
248 "PublishResponse",
249 "PublisherClient",
250 "PubsubMessage",
251 "PullRequest",
252 "PullResponse",
253 "PushConfig",
254 "ReceivedMessage",
255 "RetryPolicy",
256 "RollbackSchemaRequest",
257 "Schema",
258 "SchemaServiceClient",
259 "SchemaSettings",
260 "SchemaView",
261 "SeekRequest",
262 "SeekResponse",
263 "Snapshot",
264 "StreamingPullRequest",
265 "StreamingPullResponse",
266 "SubscriberClient",
267 "Subscription",
268 "Topic",
269 "UpdateSnapshotRequest",
270 "UpdateSubscriptionRequest",
271 "UpdateTopicRequest",
272 "ValidateMessageRequest",
273 "ValidateMessageResponse",
274 "ValidateSchemaRequest",
275 "ValidateSchemaResponse",
276)