Skip to content

Commit 14509e8

Browse files
feat: create alias alloydbconnector package (#451)
This PR creates a new package: google.cloud.alloydbconnector, which is an alias to google.cloud.alloydb.connector. The implementation resides in google.cloud.alloydbconnector, and google.cloud.alloydb.connector points to it. So importing google.cloud.alloydbconnector is the same as importing google.cloud.alloydb.connector. This PR aims to fix googleapis/google-cloud-python#13871, where a PEX environment, containing google-cloud-alloydb and alloydb-python-connector packages, fails to import google.cloud.alloydb.connector, because it attempts to find a connector/ directory under the google-cloud-alloydb package, which does not exist. The fix is that the user should import the google.cloud.alloydbconnector package instead. This PR also updates the README and integration tests to mention importing google.cloud.alloydbconnector instead of google.cloud.alloydb.connector. This serves as documentation so that new users of the library will instead import google.cloud.alloydbconnector. Existing users can continue to import google.cloud.alloydb.connector without any issues.
1 parent 3b5ea2f commit 14509e8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+167
-104
lines changed

README.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,18 @@ AlloyDB private IP address.
105105

106106
Please see [Configuring AlloyDB Connectivity][alloydb-connectivity] for more details.
107107

108+
There are two ways to import this AlloyDB connector package:
109+
1. `import google.cloud.alloydbconnector`
110+
2. `import google.cloud.alloydb.connector`
111+
112+
The preferred way is `import google.cloud.alloydbconnector` to avoid namespace
113+
collisions with the [google-cloud-alloydb][alloydb-py-lib] package. Meanwhile,
114+
`import google.cloud.alloydb.connector` will continue to work forever.
115+
108116
[vpc]: https://cloud.google.com/vpc/docs/vpc
109117
[alloydb-connectivity]: https://cloud.google.com/alloydb/docs/configure-connectivity
110118
[psc]: https://cloud.google.com/vpc/docs/private-service-connect
119+
[alloydb-py-lib]: https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-alloydb
111120

112121
### Synchronous Driver Usage
113122

@@ -128,7 +137,7 @@ like `user`, `password` and `db` etc.
128137
To use this connector with SQLAlchemy, use the `creator` argument for `sqlalchemy.create_engine`:
129138

130139
```python
131-
from google.cloud.alloydb.connector import Connector
140+
from google.cloud.alloydbconnector import Connector
132141
import sqlalchemy
133142

134143
# initialize Connector object
@@ -188,7 +197,7 @@ calls to `connector.close()`.
188197
Connector as a context manager:
189198

190199
```python
191-
from google.cloud.alloydb.connector import Connector
200+
from google.cloud.alloydbconnector import Connector
192201
import sqlalchemy
193202

194203
# initialize Connector as context manager
@@ -239,7 +248,7 @@ currently supports the following asyncio database drivers:
239248

240249
```python
241250
import asyncpg
242-
from google.cloud.alloydb.connector import AsyncConnector
251+
from google.cloud.alloydbconnector import AsyncConnector
243252

244253
async def main():
245254
# initialize AsyncConnector object for connections to AlloyDB
@@ -273,7 +282,7 @@ import asyncpg
273282
import sqlalchemy
274283
from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine
275284

276-
from google.cloud.alloydb.connector import AsyncConnector
285+
from google.cloud.alloydbconnector import AsyncConnector
277286

278287
async def init_connection_pool(connector: AsyncConnector) -> AsyncEngine:
279288
# The AlloyDB Python Connector can be used along with SQLAlchemy using the
@@ -326,7 +335,7 @@ need for explicit calls to `connector.close()` to cleanup resources.
326335

327336
```python
328337
import asyncpg
329-
from google.cloud.alloydb.connector import AsyncConnector
338+
from google.cloud.alloydbconnector import AsyncConnector
330339

331340
async def main():
332341
# initialize AsyncConnector object for connections to AlloyDB
@@ -358,7 +367,7 @@ import asyncpg
358367
import sqlalchemy
359368
from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine
360369

361-
from google.cloud.alloydb.connector import AsyncConnector
370+
from google.cloud.alloydbconnector import AsyncConnector
362371

363372
async def init_connection_pool(connector: AsyncConnector) -> AsyncEngine:
364373
# The AlloyDB Python Connector can be used along with SQLAlchemy using the
@@ -453,7 +462,7 @@ and `"PSC"`.
453462
Example:
454463

455464
```python
456-
from google.cloud.alloydb.connector import Connector
465+
from google.cloud.alloydbconnector import Connector
457466

458467
import sqlalchemy
459468

@@ -489,7 +498,7 @@ Python Connector:
489498
import logging
490499

491500
logging.basicConfig(format="%(asctime)s [%(levelname)s]: %(message)s")
492-
logger = logging.getLogger(name="google.cloud.alloydb.connector")
501+
logger = logging.getLogger(name="google.cloud.alloydbconnector")
493502
logger.setLevel(logging.DEBUG)
494503
```
495504

google/cloud/alloydb/connector/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from google.cloud.alloydb.connector.async_connector import AsyncConnector
15-
from google.cloud.alloydb.connector.connector import Connector
16-
from google.cloud.alloydb.connector.enums import IPTypes
17-
from google.cloud.alloydb.connector.enums import RefreshStrategy
18-
from google.cloud.alloydb.connector.version import __version__
14+
from google.cloud.alloydbconnector import __version__
15+
from google.cloud.alloydbconnector import AsyncConnector
16+
from google.cloud.alloydbconnector import Connector
17+
from google.cloud.alloydbconnector import IPTypes
18+
from google.cloud.alloydbconnector import RefreshStrategy
1919

2020
__all__ = [
2121
"__version__",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2025 Google LLC
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+
from google.cloud.alloydbconnector.async_connector import AsyncConnector
15+
from google.cloud.alloydbconnector.connector import Connector
16+
from google.cloud.alloydbconnector.enums import IPTypes
17+
from google.cloud.alloydbconnector.enums import RefreshStrategy
18+
from google.cloud.alloydbconnector.version import __version__
19+
20+
__all__ = [
21+
"__version__",
22+
"Connector",
23+
"AsyncConnector",
24+
"IPTypes",
25+
"RefreshStrategy",
26+
]

google/cloud/alloydb/connector/async_connector.py renamed to google/cloud/alloydbconnector/async_connector.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@
2323
from google.auth.credentials import with_scopes_if_required
2424
import google.auth.transport.requests
2525

26-
import google.cloud.alloydb.connector.asyncpg as asyncpg
27-
from google.cloud.alloydb.connector.client import AlloyDBClient
28-
from google.cloud.alloydb.connector.enums import IPTypes
29-
from google.cloud.alloydb.connector.enums import RefreshStrategy
30-
from google.cloud.alloydb.connector.exceptions import ClosedConnectorError
31-
from google.cloud.alloydb.connector.instance import RefreshAheadCache
32-
from google.cloud.alloydb.connector.lazy import LazyRefreshCache
33-
from google.cloud.alloydb.connector.types import CacheTypes
34-
from google.cloud.alloydb.connector.utils import generate_keys
35-
from google.cloud.alloydb.connector.utils import strip_http_prefix
26+
import google.cloud.alloydbconnector.asyncpg as asyncpg
27+
from google.cloud.alloydbconnector.client import AlloyDBClient
28+
from google.cloud.alloydbconnector.enums import IPTypes
29+
from google.cloud.alloydbconnector.enums import RefreshStrategy
30+
from google.cloud.alloydbconnector.exceptions import ClosedConnectorError
31+
from google.cloud.alloydbconnector.instance import RefreshAheadCache
32+
from google.cloud.alloydbconnector.lazy import LazyRefreshCache
33+
from google.cloud.alloydbconnector.types import CacheTypes
34+
from google.cloud.alloydbconnector.utils import generate_keys
35+
from google.cloud.alloydbconnector.utils import strip_http_prefix
3636

3737
if TYPE_CHECKING:
3838
from google.auth.credentials import Credentials

google/cloud/alloydb/connector/client.py renamed to google/cloud/alloydbconnector/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
import google.cloud.alloydb_v1beta as v1beta
2727
from google.protobuf import duration_pb2
2828

29-
from google.cloud.alloydb.connector.connection_info import ConnectionInfo
30-
from google.cloud.alloydb.connector.version import __version__ as version
29+
from google.cloud.alloydbconnector.connection_info import ConnectionInfo
30+
from google.cloud.alloydbconnector.version import __version__ as version
3131

3232
if TYPE_CHECKING:
3333
from google.auth.credentials import Credentials

google/cloud/alloydb/connector/connection_info.py renamed to google/cloud/alloydbconnector/connection_info.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121

2222
from aiofiles.tempfile import TemporaryDirectory
2323

24-
from google.cloud.alloydb.connector.exceptions import IPTypeNotFoundError
25-
from google.cloud.alloydb.connector.utils import _write_to_file
24+
from google.cloud.alloydbconnector.exceptions import IPTypeNotFoundError
25+
from google.cloud.alloydbconnector.utils import _write_to_file
2626

2727
if TYPE_CHECKING:
2828
import datetime
2929

3030
from cryptography.hazmat.primitives.asymmetric.types import PrivateKeyTypes
3131

32-
from google.cloud.alloydb.connector.enums import IPTypes
32+
from google.cloud.alloydbconnector.enums import IPTypes
3333

3434
logger = logging.getLogger(name=__name__)
3535

google/cloud/alloydb/connector/connector.py renamed to google/cloud/alloydbconnector/connector.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@
2929
from google.auth.credentials import with_scopes_if_required
3030
from google.auth.transport import requests
3131

32-
from google.cloud.alloydb.connector.client import AlloyDBClient
33-
from google.cloud.alloydb.connector.enums import IPTypes
34-
from google.cloud.alloydb.connector.enums import RefreshStrategy
35-
from google.cloud.alloydb.connector.exceptions import ClosedConnectorError
36-
from google.cloud.alloydb.connector.instance import RefreshAheadCache
37-
from google.cloud.alloydb.connector.lazy import LazyRefreshCache
38-
import google.cloud.alloydb.connector.pg8000 as pg8000
39-
from google.cloud.alloydb.connector.types import CacheTypes
40-
from google.cloud.alloydb.connector.utils import generate_keys
41-
from google.cloud.alloydb.connector.utils import strip_http_prefix
4232
import google.cloud.alloydb_connectors_v1.proto.resources_pb2 as connectorspb
33+
from google.cloud.alloydbconnector.client import AlloyDBClient
34+
from google.cloud.alloydbconnector.enums import IPTypes
35+
from google.cloud.alloydbconnector.enums import RefreshStrategy
36+
from google.cloud.alloydbconnector.exceptions import ClosedConnectorError
37+
from google.cloud.alloydbconnector.instance import RefreshAheadCache
38+
from google.cloud.alloydbconnector.lazy import LazyRefreshCache
39+
import google.cloud.alloydbconnector.pg8000 as pg8000
40+
from google.cloud.alloydbconnector.types import CacheTypes
41+
from google.cloud.alloydbconnector.utils import generate_keys
42+
from google.cloud.alloydbconnector.utils import strip_http_prefix
4343

4444
if TYPE_CHECKING:
4545
import ssl

google/cloud/alloydb/connector/instance.py renamed to google/cloud/alloydbconnector/instance.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@
2222
import re
2323
from typing import TYPE_CHECKING
2424

25-
from google.cloud.alloydb.connector.connection_info import ConnectionInfo
26-
from google.cloud.alloydb.connector.exceptions import RefreshError
27-
from google.cloud.alloydb.connector.rate_limiter import AsyncRateLimiter
28-
from google.cloud.alloydb.connector.refresh_utils import _is_valid
29-
from google.cloud.alloydb.connector.refresh_utils import _seconds_until_refresh
25+
from google.cloud.alloydbconnector.connection_info import ConnectionInfo
26+
from google.cloud.alloydbconnector.exceptions import RefreshError
27+
from google.cloud.alloydbconnector.rate_limiter import AsyncRateLimiter
28+
from google.cloud.alloydbconnector.refresh_utils import _is_valid
29+
from google.cloud.alloydbconnector.refresh_utils import _seconds_until_refresh
3030

3131
if TYPE_CHECKING:
3232
from cryptography.hazmat.primitives.asymmetric import rsa
3333

34-
from google.cloud.alloydb.connector.client import AlloyDBClient
34+
from google.cloud.alloydbconnector.client import AlloyDBClient
3535

3636
logger = logging.getLogger(name=__name__)
3737

google/cloud/alloydb/connector/lazy.py renamed to google/cloud/alloydbconnector/lazy.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
import logging
2020
from typing import Optional
2121

22-
from google.cloud.alloydb.connector.client import AlloyDBClient
23-
from google.cloud.alloydb.connector.connection_info import ConnectionInfo
24-
from google.cloud.alloydb.connector.instance import _parse_instance_uri
25-
from google.cloud.alloydb.connector.refresh_utils import _refresh_buffer
22+
from google.cloud.alloydbconnector.client import AlloyDBClient
23+
from google.cloud.alloydbconnector.connection_info import ConnectionInfo
24+
from google.cloud.alloydbconnector.instance import _parse_instance_uri
25+
from google.cloud.alloydbconnector.refresh_utils import _refresh_buffer
2626

2727
logger = logging.getLogger(name=__name__)
2828

google/cloud/alloydb/connector/static.py renamed to google/cloud/alloydbconnector/static.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
from cryptography.hazmat.primitives import serialization
2222

23-
from google.cloud.alloydb.connector.connection_info import ConnectionInfo
23+
from google.cloud.alloydbconnector.connection_info import ConnectionInfo
2424

2525

2626
class StaticConnectionInfoCache:

google/cloud/alloydb/connector/types.py renamed to google/cloud/alloydbconnector/types.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
import typing
1616

17-
from google.cloud.alloydb.connector.instance import RefreshAheadCache
18-
from google.cloud.alloydb.connector.lazy import LazyRefreshCache
19-
from google.cloud.alloydb.connector.static import StaticConnectionInfoCache
17+
from google.cloud.alloydbconnector.instance import RefreshAheadCache
18+
from google.cloud.alloydbconnector.lazy import LazyRefreshCache
19+
from google.cloud.alloydbconnector.static import StaticConnectionInfoCache
2020

2121
CacheTypes = typing.Union[
2222
RefreshAheadCache, LazyRefreshCache, StaticConnectionInfoCache

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def default(session, path):
137137
session.run(
138138
"coverage",
139139
"run",
140-
"--include=*/google/cloud/alloydb/connector/*.py",
140+
"--include=*/google/cloud/alloydbconnector/*.py",
141141
"-m",
142142
"pytest",
143143
"-v",

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ pg8000 = ["pg8000>=1.31.1"]
6363
asyncpg = ["asyncpg>=0.30.0"]
6464

6565
[tool.setuptools.dynamic]
66-
version = { attr = "google.cloud.alloydb.connector.version.__version__" }
66+
version = { attr = "google.cloud.alloydbconnector.version.__version__" }
6767

6868
[tool.setuptools.package-data]
69-
"google.cloud.alloydb.connector" = ["py.typed"]
69+
"google.cloud.alloydbconnector" = ["py.typed"]
7070

7171
[tool.setuptools.packages.find]
7272
# Only include packages under the 'google' namespace. Do not include tests,
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2025 Google LLC
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 google.cloud.alloydb.connector as conn_old
16+
import google.cloud.alloydbconnector as conn_new
17+
18+
19+
def test_alloydbconnector_package() -> None:
20+
"""
21+
Test imported objects are same in google.cloud.alloydb.connector and
22+
google.cloud.alloydbconnector packages.
23+
"""
24+
assert conn_old.AsyncConnector == conn_new.AsyncConnector
25+
assert conn_old.Connector == conn_new.Connector
26+
assert conn_old.IPTypes == conn_new.IPTypes
27+
assert conn_old.RefreshStrategy == conn_new.RefreshStrategy
28+
assert conn_old.__version__ == conn_new.__version__

tests/system/test_asyncpg_connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import sqlalchemy
2020
import sqlalchemy.ext.asyncio
2121

22-
from google.cloud.alloydb.connector import AsyncConnector
22+
from google.cloud.alloydbconnector import AsyncConnector
2323

2424

2525
async def create_sqlalchemy_engine(

tests/system/test_asyncpg_iam_authn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import sqlalchemy
2020
import sqlalchemy.ext.asyncio
2121

22-
from google.cloud.alloydb.connector import AsyncConnector
22+
from google.cloud.alloydbconnector import AsyncConnector
2323

2424

2525
async def create_sqlalchemy_engine(

tests/system/test_asyncpg_psc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import sqlalchemy
1919
import sqlalchemy.ext.asyncio
2020

21-
from google.cloud.alloydb.connector import AsyncConnector
21+
from google.cloud.alloydbconnector import AsyncConnector
2222

2323

2424
async def create_sqlalchemy_engine(

tests/system/test_asyncpg_public_ip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import sqlalchemy
2020
import sqlalchemy.ext.asyncio
2121

22-
from google.cloud.alloydb.connector import AsyncConnector
22+
from google.cloud.alloydbconnector import AsyncConnector
2323

2424

2525
async def create_sqlalchemy_engine(

tests/system/test_pg8000_connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# [START alloydb_sqlalchemy_connect_connector]
1919
import sqlalchemy
2020

21-
from google.cloud.alloydb.connector import Connector
21+
from google.cloud.alloydbconnector import Connector
2222

2323

2424
def create_sqlalchemy_engine(

tests/system/test_pg8000_iam_authn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# [START alloydb_sqlalchemy_connect_connector_iam_authn]
1919
import sqlalchemy
2020

21-
from google.cloud.alloydb.connector import Connector
21+
from google.cloud.alloydbconnector import Connector
2222

2323

2424
def create_sqlalchemy_engine(

tests/system/test_pg8000_psc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import sqlalchemy
1919

20-
from google.cloud.alloydb.connector import Connector
20+
from google.cloud.alloydbconnector import Connector
2121

2222

2323
def create_sqlalchemy_engine(

0 commit comments

Comments
 (0)