cloud-sql-python-connector 1.7.0__tar.gz → 1.8.0__tar.gz

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 (25) hide show
  1. {cloud-sql-python-connector-1.7.0 → cloud-sql-python-connector-1.8.0}/PKG-INFO +10 -12
  2. {cloud-sql-python-connector-1.7.0 → cloud-sql-python-connector-1.8.0}/README.md +9 -11
  3. {cloud-sql-python-connector-1.7.0 → cloud-sql-python-connector-1.8.0}/cloud_sql_python_connector.egg-info/PKG-INFO +10 -12
  4. {cloud-sql-python-connector-1.7.0 → cloud-sql-python-connector-1.8.0}/cloud_sql_python_connector.egg-info/requires.txt +1 -1
  5. {cloud-sql-python-connector-1.7.0 → cloud-sql-python-connector-1.8.0}/google/cloud/sql/connector/connector.py +60 -30
  6. {cloud-sql-python-connector-1.7.0 → cloud-sql-python-connector-1.8.0}/google/cloud/sql/connector/instance.py +14 -0
  7. {cloud-sql-python-connector-1.7.0 → cloud-sql-python-connector-1.8.0}/google/cloud/sql/connector/version.py +1 -1
  8. {cloud-sql-python-connector-1.7.0 → cloud-sql-python-connector-1.8.0}/setup.py +1 -1
  9. {cloud-sql-python-connector-1.7.0 → cloud-sql-python-connector-1.8.0}/LICENSE +0 -0
  10. {cloud-sql-python-connector-1.7.0 → cloud-sql-python-connector-1.8.0}/cloud_sql_python_connector.egg-info/SOURCES.txt +0 -0
  11. {cloud-sql-python-connector-1.7.0 → cloud-sql-python-connector-1.8.0}/cloud_sql_python_connector.egg-info/dependency_links.txt +0 -0
  12. {cloud-sql-python-connector-1.7.0 → cloud-sql-python-connector-1.8.0}/cloud_sql_python_connector.egg-info/not-zip-safe +0 -0
  13. {cloud-sql-python-connector-1.7.0 → cloud-sql-python-connector-1.8.0}/cloud_sql_python_connector.egg-info/top_level.txt +0 -0
  14. {cloud-sql-python-connector-1.7.0 → cloud-sql-python-connector-1.8.0}/google/cloud/sql/connector/__init__.py +0 -0
  15. {cloud-sql-python-connector-1.7.0 → cloud-sql-python-connector-1.8.0}/google/cloud/sql/connector/asyncpg.py +0 -0
  16. {cloud-sql-python-connector-1.7.0 → cloud-sql-python-connector-1.8.0}/google/cloud/sql/connector/client.py +0 -0
  17. {cloud-sql-python-connector-1.7.0 → cloud-sql-python-connector-1.8.0}/google/cloud/sql/connector/exceptions.py +0 -0
  18. {cloud-sql-python-connector-1.7.0 → cloud-sql-python-connector-1.8.0}/google/cloud/sql/connector/pg8000.py +0 -0
  19. {cloud-sql-python-connector-1.7.0 → cloud-sql-python-connector-1.8.0}/google/cloud/sql/connector/py.typed +0 -0
  20. {cloud-sql-python-connector-1.7.0 → cloud-sql-python-connector-1.8.0}/google/cloud/sql/connector/pymysql.py +0 -0
  21. {cloud-sql-python-connector-1.7.0 → cloud-sql-python-connector-1.8.0}/google/cloud/sql/connector/pytds.py +0 -0
  22. {cloud-sql-python-connector-1.7.0 → cloud-sql-python-connector-1.8.0}/google/cloud/sql/connector/rate_limiter.py +0 -0
  23. {cloud-sql-python-connector-1.7.0 → cloud-sql-python-connector-1.8.0}/google/cloud/sql/connector/refresh_utils.py +0 -0
  24. {cloud-sql-python-connector-1.7.0 → cloud-sql-python-connector-1.8.0}/google/cloud/sql/connector/utils.py +0 -0
  25. {cloud-sql-python-connector-1.7.0 → cloud-sql-python-connector-1.8.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cloud-sql-python-connector
3
- Version: 1.7.0
3
+ Version: 1.8.0
4
4
  Summary: The Cloud SQL Python Connector is a library that can be used alongside a database driver to allow users with sufficient permissions to connect to a Cloud SQL database without having to manually allowlist IPs or manage SSL certificates.
5
5
  Home-page: https://github.com/GoogleCloudPlatform/cloud-sql-python-connector
6
6
  Author: Google LLC
@@ -214,7 +214,7 @@ from google.cloud.sql.connector import Connector, IPTypes
214
214
 
215
215
  # Note: all parameters below are optional
216
216
  connector = Connector(
217
- ip_type=IPTypes.PUBLIC,
217
+ ip_type="public", # can also be "private" or "psc"
218
218
  enable_iam_auth=False,
219
219
  timeout=30,
220
220
  credentials=custom_creds # google.auth.credentials.Credentials
@@ -287,18 +287,16 @@ using both public and private IP addresses, as well as
287
287
  with, set the `ip_type` keyword argument when initializing a `Connector()` or when
288
288
  calling `connector.connect()`.
289
289
 
290
- Possible values for `ip_type` are `IPTypes.PUBLIC` (default value),
291
- `IPTypes.PRIVATE`, and `IPTypes.PSC`.
290
+ Possible values for `ip_type` are `"public"` (default value),
291
+ `"private"`, and `"psc"`.
292
292
 
293
293
  Example:
294
294
 
295
295
  ```python
296
- from google.cloud.sql.connector import IPTypes
297
-
298
296
  conn = connector.connect(
299
297
  "project:region:instance",
300
298
  "pymysql",
301
- ip_type=IPTypes.PRIVATE # use private IP
299
+ ip_type="private" # use private IP
302
300
  ... insert other kwargs ...
303
301
  )
304
302
  ```
@@ -359,7 +357,7 @@ conn = connector.connect(
359
357
  db="my-db-name",
360
358
  active_directory_auth=True,
361
359
  server_name="private.[instance].[location].[project].cloudsql.[domain]",
362
- ip_type=IPTypes.PRIVATE
360
+ ip_type="private"
363
361
  )
364
362
  ```
365
363
 
@@ -384,7 +382,7 @@ your web application through the following:
384
382
  ```python
385
383
  from flask import Flask
386
384
  from flask_sqlalchemy import SQLAlchemy
387
- from google.cloud.sql.connector import Connector, IPTypes
385
+ from google.cloud.sql.connector import Connector
388
386
 
389
387
 
390
388
  # initialize Python Connector object
@@ -398,7 +396,7 @@ def getconn():
398
396
  user="my-user",
399
397
  password="my-password",
400
398
  db="my-database",
401
- ip_type= IPTypes.PUBLIC # IPTypes.PRIVATE for private IP
399
+ ip_type="public" # "private" for private IP
402
400
  )
403
401
  return conn
404
402
 
@@ -433,7 +431,7 @@ from sqlalchemy import create_engine
433
431
  from sqlalchemy.engine import Engine
434
432
  from sqlalchemy.ext.declarative import declarative_base
435
433
  from sqlalchemy.orm import sessionmaker
436
- from google.cloud.sql.connector import Connector, IPTypes
434
+ from google.cloud.sql.connector import Connector
437
435
 
438
436
  # helper function to return SQLAlchemy connection pool
439
437
  def init_connection_pool(connector: Connector) -> Engine:
@@ -445,7 +443,7 @@ def init_connection_pool(connector: Connector) -> Engine:
445
443
  user="my-user",
446
444
  password="my-password",
447
445
  db="my-database",
448
- ip_type= IPTypes.PUBLIC # IPTypes.PRIVATE for private IP
446
+ ip_type="public" # "private" for private IP
449
447
  )
450
448
  return conn
451
449
 
@@ -188,7 +188,7 @@ from google.cloud.sql.connector import Connector, IPTypes
188
188
 
189
189
  # Note: all parameters below are optional
190
190
  connector = Connector(
191
- ip_type=IPTypes.PUBLIC,
191
+ ip_type="public", # can also be "private" or "psc"
192
192
  enable_iam_auth=False,
193
193
  timeout=30,
194
194
  credentials=custom_creds # google.auth.credentials.Credentials
@@ -261,18 +261,16 @@ using both public and private IP addresses, as well as
261
261
  with, set the `ip_type` keyword argument when initializing a `Connector()` or when
262
262
  calling `connector.connect()`.
263
263
 
264
- Possible values for `ip_type` are `IPTypes.PUBLIC` (default value),
265
- `IPTypes.PRIVATE`, and `IPTypes.PSC`.
264
+ Possible values for `ip_type` are `"public"` (default value),
265
+ `"private"`, and `"psc"`.
266
266
 
267
267
  Example:
268
268
 
269
269
  ```python
270
- from google.cloud.sql.connector import IPTypes
271
-
272
270
  conn = connector.connect(
273
271
  "project:region:instance",
274
272
  "pymysql",
275
- ip_type=IPTypes.PRIVATE # use private IP
273
+ ip_type="private" # use private IP
276
274
  ... insert other kwargs ...
277
275
  )
278
276
  ```
@@ -333,7 +331,7 @@ conn = connector.connect(
333
331
  db="my-db-name",
334
332
  active_directory_auth=True,
335
333
  server_name="private.[instance].[location].[project].cloudsql.[domain]",
336
- ip_type=IPTypes.PRIVATE
334
+ ip_type="private"
337
335
  )
338
336
  ```
339
337
 
@@ -358,7 +356,7 @@ your web application through the following:
358
356
  ```python
359
357
  from flask import Flask
360
358
  from flask_sqlalchemy import SQLAlchemy
361
- from google.cloud.sql.connector import Connector, IPTypes
359
+ from google.cloud.sql.connector import Connector
362
360
 
363
361
 
364
362
  # initialize Python Connector object
@@ -372,7 +370,7 @@ def getconn():
372
370
  user="my-user",
373
371
  password="my-password",
374
372
  db="my-database",
375
- ip_type= IPTypes.PUBLIC # IPTypes.PRIVATE for private IP
373
+ ip_type="public" # "private" for private IP
376
374
  )
377
375
  return conn
378
376
 
@@ -407,7 +405,7 @@ from sqlalchemy import create_engine
407
405
  from sqlalchemy.engine import Engine
408
406
  from sqlalchemy.ext.declarative import declarative_base
409
407
  from sqlalchemy.orm import sessionmaker
410
- from google.cloud.sql.connector import Connector, IPTypes
408
+ from google.cloud.sql.connector import Connector
411
409
 
412
410
  # helper function to return SQLAlchemy connection pool
413
411
  def init_connection_pool(connector: Connector) -> Engine:
@@ -419,7 +417,7 @@ def init_connection_pool(connector: Connector) -> Engine:
419
417
  user="my-user",
420
418
  password="my-password",
421
419
  db="my-database",
422
- ip_type= IPTypes.PUBLIC # IPTypes.PRIVATE for private IP
420
+ ip_type="public" # "private" for private IP
423
421
  )
424
422
  return conn
425
423
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cloud-sql-python-connector
3
- Version: 1.7.0
3
+ Version: 1.8.0
4
4
  Summary: The Cloud SQL Python Connector is a library that can be used alongside a database driver to allow users with sufficient permissions to connect to a Cloud SQL database without having to manually allowlist IPs or manage SSL certificates.
5
5
  Home-page: https://github.com/GoogleCloudPlatform/cloud-sql-python-connector
6
6
  Author: Google LLC
@@ -214,7 +214,7 @@ from google.cloud.sql.connector import Connector, IPTypes
214
214
 
215
215
  # Note: all parameters below are optional
216
216
  connector = Connector(
217
- ip_type=IPTypes.PUBLIC,
217
+ ip_type="public", # can also be "private" or "psc"
218
218
  enable_iam_auth=False,
219
219
  timeout=30,
220
220
  credentials=custom_creds # google.auth.credentials.Credentials
@@ -287,18 +287,16 @@ using both public and private IP addresses, as well as
287
287
  with, set the `ip_type` keyword argument when initializing a `Connector()` or when
288
288
  calling `connector.connect()`.
289
289
 
290
- Possible values for `ip_type` are `IPTypes.PUBLIC` (default value),
291
- `IPTypes.PRIVATE`, and `IPTypes.PSC`.
290
+ Possible values for `ip_type` are `"public"` (default value),
291
+ `"private"`, and `"psc"`.
292
292
 
293
293
  Example:
294
294
 
295
295
  ```python
296
- from google.cloud.sql.connector import IPTypes
297
-
298
296
  conn = connector.connect(
299
297
  "project:region:instance",
300
298
  "pymysql",
301
- ip_type=IPTypes.PRIVATE # use private IP
299
+ ip_type="private" # use private IP
302
300
  ... insert other kwargs ...
303
301
  )
304
302
  ```
@@ -359,7 +357,7 @@ conn = connector.connect(
359
357
  db="my-db-name",
360
358
  active_directory_auth=True,
361
359
  server_name="private.[instance].[location].[project].cloudsql.[domain]",
362
- ip_type=IPTypes.PRIVATE
360
+ ip_type="private"
363
361
  )
364
362
  ```
365
363
 
@@ -384,7 +382,7 @@ your web application through the following:
384
382
  ```python
385
383
  from flask import Flask
386
384
  from flask_sqlalchemy import SQLAlchemy
387
- from google.cloud.sql.connector import Connector, IPTypes
385
+ from google.cloud.sql.connector import Connector
388
386
 
389
387
 
390
388
  # initialize Python Connector object
@@ -398,7 +396,7 @@ def getconn():
398
396
  user="my-user",
399
397
  password="my-password",
400
398
  db="my-database",
401
- ip_type= IPTypes.PUBLIC # IPTypes.PRIVATE for private IP
399
+ ip_type="public" # "private" for private IP
402
400
  )
403
401
  return conn
404
402
 
@@ -433,7 +431,7 @@ from sqlalchemy import create_engine
433
431
  from sqlalchemy.engine import Engine
434
432
  from sqlalchemy.ext.declarative import declarative_base
435
433
  from sqlalchemy.orm import sessionmaker
436
- from google.cloud.sql.connector import Connector, IPTypes
434
+ from google.cloud.sql.connector import Connector
437
435
 
438
436
  # helper function to return SQLAlchemy connection pool
439
437
  def init_connection_pool(connector: Connector) -> Engine:
@@ -445,7 +443,7 @@ def init_connection_pool(connector: Connector) -> Engine:
445
443
  user="my-user",
446
444
  password="my-password",
447
445
  db="my-database",
448
- ip_type= IPTypes.PUBLIC # IPTypes.PRIVATE for private IP
446
+ ip_type="public" # "private" for private IP
449
447
  )
450
448
  return conn
451
449
 
@@ -7,7 +7,7 @@ google-auth
7
7
  asyncpg>=0.29.0
8
8
 
9
9
  [pg8000]
10
- pg8000>=1.30.4
10
+ pg8000>=1.30.5
11
11
 
12
12
  [pymysql]
13
13
  PyMySQL>=1.1.0
@@ -48,10 +48,10 @@ ASYNC_DRIVERS = ["asyncpg"]
48
48
  class Connector:
49
49
  """A class to configure and create connections to Cloud SQL instances.
50
50
 
51
- :type ip_type: IPTypes
51
+ :type ip_type: str | IPTypes
52
52
  :param ip_type
53
- The IP type (public or private) used to connect. IP types
54
- can be either IPTypes.PUBLIC or IPTypes.PRIVATE.
53
+ The IP type used to connect. IP types can be either IPTypes.PUBLIC
54
+ ("PUBLIC"), IPTypes.PRIVATE ("PRIVATE"), or IPTypes.PSC ("PSC").
55
55
 
56
56
  :type enable_iam_auth: bool
57
57
  :param enable_iam_auth
@@ -87,7 +87,7 @@ class Connector:
87
87
 
88
88
  def __init__(
89
89
  self,
90
- ip_type: IPTypes = IPTypes.PUBLIC,
90
+ ip_type: str | IPTypes = IPTypes.PUBLIC,
91
91
  enable_iam_auth: bool = False,
92
92
  timeout: int = 30,
93
93
  credentials: Optional[Credentials] = None,
@@ -130,10 +130,13 @@ class Connector:
130
130
  # set default params for connections
131
131
  self._timeout = timeout
132
132
  self._enable_iam_auth = enable_iam_auth
133
- self._ip_type = ip_type
134
133
  self._quota_project = quota_project
135
134
  self._sqladmin_api_endpoint = sqladmin_api_endpoint
136
135
  self._user_agent = user_agent
136
+ # if ip_type is str, convert to IPTypes enum
137
+ if isinstance(ip_type, str):
138
+ ip_type = IPTypes._from_str(ip_type)
139
+ self._ip_type = ip_type
137
140
 
138
141
  def connect(
139
142
  self, instance_connection_string: str, driver: str, **kwargs: Any
@@ -252,6 +255,9 @@ class Connector:
252
255
  raise KeyError(f"Driver '{driver}' is not supported.")
253
256
 
254
257
  ip_type = kwargs.pop("ip_type", self._ip_type)
258
+ # if ip_type is str, convert to IPTypes enum
259
+ if isinstance(ip_type, str):
260
+ ip_type = IPTypes._from_str(ip_type)
255
261
  kwargs["timeout"] = kwargs.get("timeout", self._timeout)
256
262
 
257
263
  # Host and ssl options come from the certificates and metadata, so we don't
@@ -362,36 +368,60 @@ async def create_async_connector(
362
368
  timeout: int = 30,
363
369
  credentials: Optional[Credentials] = None,
364
370
  loop: Optional[asyncio.AbstractEventLoop] = None,
371
+ quota_project: Optional[str] = None,
372
+ sqladmin_api_endpoint: str = "https://sqladmin.googleapis.com",
373
+ user_agent: Optional[str] = None,
365
374
  ) -> Connector:
366
375
  """
367
- Create Connector object for asyncio connections that can auto-detect
368
- and use current thread's running event loop.
376
+ Create Connector object for asyncio connections that can auto-detect
377
+ and use current thread's running event loop.
369
378
 
370
379
  :type ip_type: IPTypes
371
- :param ip_type
372
- The IP type (public or private) used to connect. IP types
373
- can be either IPTypes.PUBLIC or IPTypes.PRIVATE.
374
-
375
- :type enable_iam_auth: bool
376
- :param enable_iam_auth
377
- Enables automatic IAM database authentication for Postgres or MySQL
378
- instances.
379
-
380
- :type timeout: int
381
- :param timeout
382
- The time limit for a connection before raising a TimeoutError.
383
-
384
- :type credentials: google.auth.credentials.Credentials
385
- :param credentials
386
- Credentials object used to authenticate connections to Cloud SQL server.
387
- If not specified, Application Default Credentials are used.
388
-
389
- :type loop: asyncio.AbstractEventLoop
390
- :param loop
391
- Event loop to run asyncio tasks, if not specified, defaults
392
- to current thread's running event loop.
380
+ :param ip_type
381
+ The IP type (public or private) used to connect. IP types
382
+ can be either IPTypes.PUBLIC or IPTypes.PRIVATE.
383
+
384
+ :type enable_iam_auth: bool
385
+ :param enable_iam_auth
386
+ Enables automatic IAM database authentication for Postgres or MySQL
387
+ instances.
388
+
389
+ :type timeout: int
390
+ :param timeout
391
+ The time limit for a connection before raising a TimeoutError.
392
+
393
+ :type credentials: google.auth.credentials.Credentials
394
+ :param credentials
395
+ Credentials object used to authenticate connections to Cloud SQL server.
396
+ If not specified, Application Default Credentials are used.
397
+
398
+ :type quota_project: str
399
+ :param quota_project
400
+ The Project ID for an existing Google Cloud project. The project specified
401
+ is used for quota and billing purposes. If not specified, defaults to
402
+ project sourced from environment.
403
+
404
+ :type loop: asyncio.AbstractEventLoop
405
+ :param loop
406
+ Event loop to run asyncio tasks, if not specified, defaults to
407
+ creating new event loop on background thread.
408
+
409
+ :type sqladmin_api_endpoint: str
410
+ :param sqladmin_api_endpoint:
411
+ Base URL to use when calling the Cloud SQL Admin API endpoint.
412
+ Defaults to "https://sqladmin.googleapis.com", this argument should
413
+ only be used in development.
393
414
  """
394
415
  # if no loop given, automatically detect running event loop
395
416
  if loop is None:
396
417
  loop = asyncio.get_running_loop()
397
- return Connector(ip_type, enable_iam_auth, timeout, credentials, loop)
418
+ return Connector(
419
+ ip_type=ip_type,
420
+ enable_iam_auth=enable_iam_auth,
421
+ timeout=timeout,
422
+ credentials=credentials,
423
+ loop=loop,
424
+ quota_project=quota_project,
425
+ sqladmin_api_endpoint=sqladmin_api_endpoint,
426
+ user_agent=user_agent,
427
+ )
@@ -64,6 +64,20 @@ class IPTypes(Enum):
64
64
  PRIVATE: str = "PRIVATE"
65
65
  PSC: str = "PSC"
66
66
 
67
+ @classmethod
68
+ def _missing_(cls, value: object) -> None:
69
+ raise ValueError(
70
+ f"Incorrect value for ip_type, got '{value}'. Want one of: "
71
+ f"{', '.join([repr(m.value) for m in cls])}, 'PUBLIC'."
72
+ )
73
+
74
+ @classmethod
75
+ def _from_str(cls, ip_type_str: str) -> IPTypes:
76
+ """Convert IP type from a str into IPTypes."""
77
+ if ip_type_str.upper() == "PUBLIC":
78
+ ip_type_str = "PRIMARY"
79
+ return cls(ip_type_str.upper())
80
+
67
81
 
68
82
  class ConnectionInfo:
69
83
  ip_addrs: Dict[str, Any]
@@ -12,4 +12,4 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- __version__ = "1.7.0"
15
+ __version__ = "1.8.0"
@@ -77,7 +77,7 @@ setuptools.setup(
77
77
  install_requires=dependencies,
78
78
  extras_require={
79
79
  "pymysql": ["PyMySQL>=1.1.0"],
80
- "pg8000": ["pg8000>=1.30.4"],
80
+ "pg8000": ["pg8000>=1.30.5"],
81
81
  "pytds": ["python-tds>=1.15.0"],
82
82
  "asyncpg": ["asyncpg>=0.29.0"],
83
83
  },