cloud-sql-python-connector 1.7.0__py2.py3-none-any.whl → 1.8.0__py2.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.
- {cloud_sql_python_connector-1.7.0.dist-info → cloud_sql_python_connector-1.8.0.dist-info}/METADATA +11 -13
- {cloud_sql_python_connector-1.7.0.dist-info → cloud_sql_python_connector-1.8.0.dist-info}/RECORD +8 -8
- google/cloud/sql/connector/connector.py +60 -30
- google/cloud/sql/connector/instance.py +14 -0
- google/cloud/sql/connector/version.py +1 -1
- {cloud_sql_python_connector-1.7.0.dist-info → cloud_sql_python_connector-1.8.0.dist-info}/LICENSE +0 -0
- {cloud_sql_python_connector-1.7.0.dist-info → cloud_sql_python_connector-1.8.0.dist-info}/WHEEL +0 -0
- {cloud_sql_python_connector-1.7.0.dist-info → cloud_sql_python_connector-1.8.0.dist-info}/top_level.txt +0 -0
{cloud_sql_python_connector-1.7.0.dist-info → cloud_sql_python_connector-1.8.0.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: cloud-sql-python-connector
|
|
3
|
-
Version: 1.
|
|
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
|
|
@@ -26,7 +26,7 @@ Requires-Dist: google-auth
|
|
|
26
26
|
Provides-Extra: asyncpg
|
|
27
27
|
Requires-Dist: asyncpg (>=0.29.0) ; extra == 'asyncpg'
|
|
28
28
|
Provides-Extra: pg8000
|
|
29
|
-
Requires-Dist: pg8000 (>=1.30.
|
|
29
|
+
Requires-Dist: pg8000 (>=1.30.5) ; extra == 'pg8000'
|
|
30
30
|
Provides-Extra: pymysql
|
|
31
31
|
Requires-Dist: PyMySQL (>=1.1.0) ; extra == 'pymysql'
|
|
32
32
|
Provides-Extra: pytds
|
|
@@ -222,7 +222,7 @@ from google.cloud.sql.connector import Connector, IPTypes
|
|
|
222
222
|
|
|
223
223
|
# Note: all parameters below are optional
|
|
224
224
|
connector = Connector(
|
|
225
|
-
ip_type=
|
|
225
|
+
ip_type="public", # can also be "private" or "psc"
|
|
226
226
|
enable_iam_auth=False,
|
|
227
227
|
timeout=30,
|
|
228
228
|
credentials=custom_creds # google.auth.credentials.Credentials
|
|
@@ -295,18 +295,16 @@ using both public and private IP addresses, as well as
|
|
|
295
295
|
with, set the `ip_type` keyword argument when initializing a `Connector()` or when
|
|
296
296
|
calling `connector.connect()`.
|
|
297
297
|
|
|
298
|
-
Possible values for `ip_type` are `
|
|
299
|
-
`
|
|
298
|
+
Possible values for `ip_type` are `"public"` (default value),
|
|
299
|
+
`"private"`, and `"psc"`.
|
|
300
300
|
|
|
301
301
|
Example:
|
|
302
302
|
|
|
303
303
|
```python
|
|
304
|
-
from google.cloud.sql.connector import IPTypes
|
|
305
|
-
|
|
306
304
|
conn = connector.connect(
|
|
307
305
|
"project:region:instance",
|
|
308
306
|
"pymysql",
|
|
309
|
-
ip_type=
|
|
307
|
+
ip_type="private" # use private IP
|
|
310
308
|
... insert other kwargs ...
|
|
311
309
|
)
|
|
312
310
|
```
|
|
@@ -367,7 +365,7 @@ conn = connector.connect(
|
|
|
367
365
|
db="my-db-name",
|
|
368
366
|
active_directory_auth=True,
|
|
369
367
|
server_name="private.[instance].[location].[project].cloudsql.[domain]",
|
|
370
|
-
ip_type=
|
|
368
|
+
ip_type="private"
|
|
371
369
|
)
|
|
372
370
|
```
|
|
373
371
|
|
|
@@ -392,7 +390,7 @@ your web application through the following:
|
|
|
392
390
|
```python
|
|
393
391
|
from flask import Flask
|
|
394
392
|
from flask_sqlalchemy import SQLAlchemy
|
|
395
|
-
from google.cloud.sql.connector import Connector
|
|
393
|
+
from google.cloud.sql.connector import Connector
|
|
396
394
|
|
|
397
395
|
|
|
398
396
|
# initialize Python Connector object
|
|
@@ -406,7 +404,7 @@ def getconn():
|
|
|
406
404
|
user="my-user",
|
|
407
405
|
password="my-password",
|
|
408
406
|
db="my-database",
|
|
409
|
-
ip_type=
|
|
407
|
+
ip_type="public" # "private" for private IP
|
|
410
408
|
)
|
|
411
409
|
return conn
|
|
412
410
|
|
|
@@ -441,7 +439,7 @@ from sqlalchemy import create_engine
|
|
|
441
439
|
from sqlalchemy.engine import Engine
|
|
442
440
|
from sqlalchemy.ext.declarative import declarative_base
|
|
443
441
|
from sqlalchemy.orm import sessionmaker
|
|
444
|
-
from google.cloud.sql.connector import Connector
|
|
442
|
+
from google.cloud.sql.connector import Connector
|
|
445
443
|
|
|
446
444
|
# helper function to return SQLAlchemy connection pool
|
|
447
445
|
def init_connection_pool(connector: Connector) -> Engine:
|
|
@@ -453,7 +451,7 @@ def init_connection_pool(connector: Connector) -> Engine:
|
|
|
453
451
|
user="my-user",
|
|
454
452
|
password="my-password",
|
|
455
453
|
db="my-database",
|
|
456
|
-
ip_type=
|
|
454
|
+
ip_type="public" # "private" for private IP
|
|
457
455
|
)
|
|
458
456
|
return conn
|
|
459
457
|
|
{cloud_sql_python_connector-1.7.0.dist-info → cloud_sql_python_connector-1.8.0.dist-info}/RECORD
RENAMED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
google/cloud/sql/connector/__init__.py,sha256=Z3AkPOQwjNF1ogo2DR18GN-CnYvI4MTmhsCe8hURKUo,883
|
|
2
2
|
google/cloud/sql/connector/asyncpg.py,sha256=c4lAlvEgGf_eBq0G8MVNPRAJQQvo6DcwybiXDW36qkU,1838
|
|
3
3
|
google/cloud/sql/connector/client.py,sha256=n1v6xxtfuvNZYCUfNUWY6FdNw9uvgOnmFxpSE0NmN5M,8263
|
|
4
|
-
google/cloud/sql/connector/connector.py,sha256=
|
|
4
|
+
google/cloud/sql/connector/connector.py,sha256=nx5SVEJUF6pJt3VAmjw3-XBpWKFdWHJDEABM_pPzsvc,16867
|
|
5
5
|
google/cloud/sql/connector/exceptions.py,sha256=rTBtbCoiZ3U5IFVsyXPw5baHbCODixx2hPDQeXUzgzs,1524
|
|
6
|
-
google/cloud/sql/connector/instance.py,sha256=
|
|
6
|
+
google/cloud/sql/connector/instance.py,sha256=G7-SCqsLjZiOYZ-Ds2RIErs6oaT0ewnAN683fs7EebI,14920
|
|
7
7
|
google/cloud/sql/connector/pg8000.py,sha256=EZuO7XgCkG_Y79NQlh3Vv8Ff2w85BFJyFVO237hx1GM,1814
|
|
8
8
|
google/cloud/sql/connector/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
9
|
google/cloud/sql/connector/pymysql.py,sha256=wldUgwDPlPa8Nj5F3JaipuP8hJyvzlgOAJbRnOoaB1U,2105
|
|
@@ -11,9 +11,9 @@ google/cloud/sql/connector/pytds.py,sha256=vKJoE7E2P0GrhZojg8bGZkqCMLc8dgKAcXE4e
|
|
|
11
11
|
google/cloud/sql/connector/rate_limiter.py,sha256=bPTupfM4f5QRSCmCAWMqjQylEB7bUM-50plVBU3W2CA,2993
|
|
12
12
|
google/cloud/sql/connector/refresh_utils.py,sha256=P2ye3qDymdK1iOlGCXby4VIaqwvHdc9GEmuUsMcufxY,3680
|
|
13
13
|
google/cloud/sql/connector/utils.py,sha256=FQs7RgoViJLIFgJIynVT-_DwAVWnpyXIKu5WZ4m10Ts,3448
|
|
14
|
-
google/cloud/sql/connector/version.py,sha256=
|
|
15
|
-
cloud_sql_python_connector-1.
|
|
16
|
-
cloud_sql_python_connector-1.
|
|
17
|
-
cloud_sql_python_connector-1.
|
|
18
|
-
cloud_sql_python_connector-1.
|
|
19
|
-
cloud_sql_python_connector-1.
|
|
14
|
+
google/cloud/sql/connector/version.py,sha256=uFu1vr_bHDmu9LzGZmYfAmD9Cb7yvaTRwh3jChsfq0g,597
|
|
15
|
+
cloud_sql_python_connector-1.8.0.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
16
|
+
cloud_sql_python_connector-1.8.0.dist-info/METADATA,sha256=FUIl4XRA6VgxpVcTI0sNtdIxch7MtBumAsGZ1TwdvFA,24102
|
|
17
|
+
cloud_sql_python_connector-1.8.0.dist-info/WHEEL,sha256=bb2Ot9scclHKMOLDEHY6B2sicWOgugjFKaJsT7vwMQo,110
|
|
18
|
+
cloud_sql_python_connector-1.8.0.dist-info/top_level.txt,sha256=_1QvSJIhFAGfxb79D6DhB7SUw2X6T4rwnz_LLrbcD3c,7
|
|
19
|
+
cloud_sql_python_connector-1.8.0.dist-info/RECORD,,
|
|
@@ -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
|
|
54
|
-
|
|
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
|
-
|
|
368
|
-
|
|
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
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
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(
|
|
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]
|
{cloud_sql_python_connector-1.7.0.dist-info → cloud_sql_python_connector-1.8.0.dist-info}/LICENSE
RENAMED
|
File without changes
|
{cloud_sql_python_connector-1.7.0.dist-info → cloud_sql_python_connector-1.8.0.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|