cloud-sql-python-connector 1.21.0__py3-none-any.whl → 1.23.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cloud-sql-python-connector
3
- Version: 1.21.0
3
+ Version: 1.23.0
4
4
  Summary: Google Cloud SQL Python Connector library
5
5
  Author-email: Google LLC <googleapis-packages@google.com>
6
6
  License-Expression: Apache-2.0
@@ -12,13 +12,12 @@ Classifier: Development Status :: 5 - Production/Stable
12
12
  Classifier: Intended Audience :: Developers
13
13
  Classifier: Programming Language :: Python
14
14
  Classifier: Programming Language :: Python :: 3
15
- Classifier: Programming Language :: Python :: 3.9
16
- Classifier: Programming Language :: Python :: 3.10
17
15
  Classifier: Programming Language :: Python :: 3.11
18
16
  Classifier: Programming Language :: Python :: 3.12
19
17
  Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
20
19
  Classifier: Operating System :: OS Independent
21
- Requires-Python: >=3.9
20
+ Requires-Python: >=3.11
22
21
  Description-Content-Type: text/markdown
23
22
  License-File: LICENSE
24
23
  Requires-Dist: aiohttp
@@ -26,9 +25,7 @@ Requires-Dist: cryptography>=42.0.0
26
25
  Requires-Dist: dnspython>=2.0.0
27
26
  Requires-Dist: Requests
28
27
  Requires-Dist: google-auth>=2.28.0
29
- Requires-Dist: grpcio
30
- Requires-Dist: protobuf
31
- Requires-Dist: googleapis-common-protos
28
+ Requires-Dist: google-cloud-sql>=0.1.1
32
29
  Provides-Extra: pymysql
33
30
  Requires-Dist: PyMySQL>=1.1.0; extra == "pymysql"
34
31
  Provides-Extra: pg8000
@@ -37,6 +34,8 @@ Provides-Extra: pytds
37
34
  Requires-Dist: python-tds>=1.15.0; extra == "pytds"
38
35
  Provides-Extra: asyncpg
39
36
  Requires-Dist: asyncpg>=0.30.0; extra == "asyncpg"
37
+ Provides-Extra: psycopg
38
+ Requires-Dist: psycopg>=3.1.0; extra == "psycopg"
40
39
  Dynamic: license-file
41
40
 
42
41
  <p align="center">
@@ -82,7 +81,8 @@ providing the following benefits:
82
81
  The Cloud SQL Python Connector is a package to be used alongside a database driver.
83
82
  Currently supported drivers are:
84
83
  - [`pymysql`](https://github.com/PyMySQL/PyMySQL) (MySQL)
85
- - [`pg8000`](https://github.com/tlocke/pg8000) (PostgreSQL)
84
+ - [`pg8000`](https://codeberg.org/tlocke/pg8000) (PostgreSQL)
85
+ - [`psycopg`](https://github.com/psycopg/psycopg) (PostgreSQL)
86
86
  - [`asyncpg`](https://github.com/MagicStack/asyncpg) (PostgreSQL)
87
87
  - [`pytds`](https://github.com/denisenkom/pytds) (SQL Server)
88
88
 
@@ -97,12 +97,16 @@ based on your database dialect.
97
97
  pip install "cloud-sql-python-connector[pymysql]"
98
98
  ```
99
99
  ### Postgres
100
- There are two different database drivers that are supported for the Postgres dialect:
100
+ There are three different database drivers that are supported for the Postgres dialect:
101
101
 
102
102
  #### pg8000
103
103
  ```
104
104
  pip install "cloud-sql-python-connector[pg8000]"
105
105
  ```
106
+ #### psycopg
107
+ ```
108
+ pip install "cloud-sql-python-connector[psycopg]"
109
+ ```
106
110
  #### asyncpg
107
111
  ```
108
112
  pip install "cloud-sql-python-connector[asyncpg]"
@@ -178,6 +182,18 @@ pool = sqlalchemy.create_engine(
178
182
  db="my-db-name"
179
183
  ),
180
184
  )
185
+
186
+ # Or with Postgres (psycopg):
187
+ pool = sqlalchemy.create_engine(
188
+ "postgresql+psycopg://",
189
+ creator=lambda: connector.connect(
190
+ "project:region:instance",
191
+ "psycopg",
192
+ user="my-user",
193
+ password="my-password",
194
+ db="my-db-name"
195
+ ),
196
+ )
181
197
  ```
182
198
 
183
199
  The returned connection pool engine can then be used to query and modify the database.
@@ -225,7 +241,7 @@ from google.cloud.sql.connector import Connector
225
241
 
226
242
  # Note: all parameters below are optional
227
243
  connector = Connector(
228
- ip_type="public", # can also be "private" or "psc"
244
+ ip_type="public", # can also be "private", "psc", or "sql_data"
229
245
  enable_iam_auth=False,
230
246
  timeout=30,
231
247
  credentials=custom_creds, # google.auth.credentials.Credentials
@@ -303,7 +319,11 @@ with, set the `ip_type` keyword argument when initializing a `Connector()` or wh
303
319
  calling `connector.connect()`.
304
320
 
305
321
  Possible values for `ip_type` are `"public"` (default value),
306
- `"private"`, and `"psc"`.
322
+ `"private"`, `"psc"`, and `"sql_data"`.
323
+
324
+ > [!NOTE]
325
+ >
326
+ > Usage of the `asyncpg` driver does not currently support `ip_type="sql_data"` (`IPTypes.SQL_DATA`).
307
327
 
308
328
  Example:
309
329
 
@@ -0,0 +1,27 @@
1
+ cloud_sql_python_connector-1.23.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
2
+ google/cloud/sql/connector/__init__.py,sha256=pfa-FD-VRpYI49OUul9p6UFDp7G_yT2f6WS9rZMn8CM,1148
3
+ google/cloud/sql/connector/asyncpg.py,sha256=MpZhwFke0WXvYD3OcEF1Ok0qHl-CU7ZIPy85PCog5QY,2002
4
+ google/cloud/sql/connector/client.py,sha256=GfiZKDDBOxeA0yfqETQuaw3Nhg0BS71oQNZNxq3CooY,14991
5
+ google/cloud/sql/connector/connection_info.py,sha256=lwhrOG01efvvvR2gXiesiZ1BrXJ4iP7geoRi0zI80do,5666
6
+ google/cloud/sql/connector/connection_name.py,sha256=SCCVeWb8YN0f9My09_l9FGTr6iRbi1b_52TJQaS6xzM,2574
7
+ google/cloud/sql/connector/connector.py,sha256=at6WZJJCwQ3Ds8Ssd3ZF9bSJJYwN10Yxh-oK9UhkmFc,37843
8
+ google/cloud/sql/connector/enums.py,sha256=F_mUdwscpW2fAzw4XElSy4BWkWcGQAkBOAUG8bvd3vg,3118
9
+ google/cloud/sql/connector/exceptions.py,sha256=-QgsUq4gZaMrl3MH5KnsfJybEegAKW84-sdRmPKT-Dg,3137
10
+ google/cloud/sql/connector/instance.py,sha256=Lz4kjwBdp3IVb6xpjPEJkawR7LS89XPLZSOt-IDxunI,8677
11
+ google/cloud/sql/connector/lazy.py,sha256=MDJTAcB5iOqYYMewbzuX0RWh5PdIrY4RWpYfmFUYkr0,4918
12
+ google/cloud/sql/connector/monitored_cache.py,sha256=5YAVjdiQaywZOqzQlvx9HkPLxA8tlV0HhQDJFsa1_qc,6674
13
+ google/cloud/sql/connector/pg8000.py,sha256=tbqFSIoSguMX1hTZ4kWeBOKLhLHKX1Vq5SespfA0Y0w,1801
14
+ google/cloud/sql/connector/psycopg.py,sha256=UD7OFVJ7C_PPsiIWzpbi1k3YIkqC4rM1pQS08wPeSM0,10950
15
+ google/cloud/sql/connector/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
+ google/cloud/sql/connector/pymysql.py,sha256=MOau37nTOTesUR5Hor7lLtEckvvGThzjECEWQYHcM8U,2166
17
+ google/cloud/sql/connector/pytds.py,sha256=e-KBCqv0m3a7cRi9YmFHNuYqClhlJbf-KoF611w-1Ck,2304
18
+ google/cloud/sql/connector/rate_limiter.py,sha256=60k-r9h-nUBqovVIHnIGbW0NMgUGD4exH_rZ02ukNa0,2924
19
+ google/cloud/sql/connector/refresh_utils.py,sha256=Eghd-_uR5ndCGLsPgnyeUOoAvN7Tz4yzTlQFW4QWOjo,5228
20
+ google/cloud/sql/connector/resolver.py,sha256=4U8G0Pxwmy64qoRmP5shLnmIykxcGcGCoFSH_7tr120,6353
21
+ google/cloud/sql/connector/sqldata_client.py,sha256=gIgfgyYN5tBjYJxEWzvJkL67FCjhYxjg2Qs_2Z7QBhU,23862
22
+ google/cloud/sql/connector/utils.py,sha256=ApLG4z4H0S4lWXQ9PyclXbrEoY5VrshqN9QB6BG8lyg,4132
23
+ google/cloud/sql/connector/version.py,sha256=cbp_THzh62LsaoqJEz9Prs5EyZAWmeu6HB74bMAMqGY,598
24
+ cloud_sql_python_connector-1.23.0.dist-info/METADATA,sha256=7dGxD8x9D5bsEnn9BmzbZtSN1mMGpAmcqj8w6EFPRjo,31777
25
+ cloud_sql_python_connector-1.23.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
26
+ cloud_sql_python_connector-1.23.0.dist-info/top_level.txt,sha256=_1QvSJIhFAGfxb79D6DhB7SUw2X6T4rwnz_LLrbcD3c,7
27
+ cloud_sql_python_connector-1.23.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (83.0.0)
2
+ Generator: setuptools (84.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -51,7 +51,9 @@ async def connect(
51
51
  'Unable to import module "asyncpg." Please install and try again.'
52
52
  )
53
53
  user = kwargs.pop("user")
54
- db = kwargs.pop("db")
54
+ db = kwargs.pop("database", kwargs.pop("db", None))
55
+ if db is None:
56
+ raise KeyError("database")
55
57
  passwd = kwargs.pop("password", None)
56
58
 
57
59
  return await asyncpg.connect(
@@ -173,9 +173,13 @@ class CloudSQLClient:
173
173
  if psc_dns_names:
174
174
  ip_addresses["PSC"] = psc_dns_names
175
175
 
176
+ server_ca_cert = None
177
+ if "serverCaCert" in ret_dict and "cert" in ret_dict["serverCaCert"]:
178
+ server_ca_cert = ret_dict["serverCaCert"]["cert"]
179
+
176
180
  return {
177
181
  "ip_addresses": ip_addresses,
178
- "server_ca_cert": ret_dict["serverCaCert"]["cert"],
182
+ "server_ca_cert": server_ca_cert,
179
183
  "database_version": ret_dict["databaseVersion"],
180
184
  }
181
185
 
@@ -271,7 +275,15 @@ class CloudSQLClient:
271
275
  finally:
272
276
  resp.raise_for_status()
273
277
 
274
- ephemeral_cert: str = ret_dict["ephemeralCert"]["cert"]
278
+ try:
279
+ ephemeral_cert: str = ret_dict["ephemeralCert"]["cert"]
280
+ except KeyError as e:
281
+ logger.error(
282
+ "KeyError in _get_ephemeral parsing generateEphemeralCert: %s. Response dict: %s",
283
+ e,
284
+ ret_dict,
285
+ )
286
+ raise
275
287
 
276
288
  # decode cert to read expiration
277
289
  x509 = load_pem_x509_certificate(
@@ -285,7 +297,7 @@ class CloudSQLClient:
285
297
  # google.auth library strips timezone info for backwards compatibality
286
298
  # reasons with Python 2. Add it back to allow timezone aware datetimes.
287
299
  # Ref: https://github.com/googleapis/google-auth-library-python/blob/49a5ff7411a2ae4d32a7d11700f9f961c55406a9/google/auth/_helpers.py#L93-L99
288
- token_expiration = token_expiration.replace(tzinfo=datetime.timezone.utc)
300
+ token_expiration = token_expiration.replace(tzinfo=datetime.UTC)
289
301
 
290
302
  expiration = min(expiration, token_expiration)
291
303
  return ephemeral_cert, expiration
@@ -21,6 +21,7 @@ import ssl
21
21
  from typing import Any, TYPE_CHECKING
22
22
 
23
23
  from google.cloud.sql.connector.connection_name import ConnectionName
24
+ from google.cloud.sql.connector.exceptions import CloudSQLConnectionError
24
25
  from google.cloud.sql.connector.exceptions import CloudSQLIPTypeError
25
26
  from google.cloud.sql.connector.exceptions import TLSVersionError
26
27
  from google.cloud.sql.connector.utils import AsyncTemporaryDirectory
@@ -62,7 +63,7 @@ class ConnectionInfo:
62
63
 
63
64
  conn_name: ConnectionName
64
65
  client_cert: str
65
- server_ca_cert: str
66
+ server_ca_cert: str | None
66
67
  private_key: bytes
67
68
  ip_addrs: dict[str, Any]
68
69
  database_version: str
@@ -78,6 +79,12 @@ class ConnectionInfo:
78
79
  # if SSL context is cached, use it
79
80
  if self.context is not None:
80
81
  return self.context
82
+
83
+ if self.server_ca_cert is None:
84
+ raise CloudSQLConnectionError(
85
+ "Cannot create SSL context: server CA certificate is missing."
86
+ )
87
+
81
88
  context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
82
89
 
83
90
  # update ssl.PROTOCOL_TLS_CLIENT default