Skip to content

Commit 99e49cb

Browse files
committed
Tidy up import paths and remove _WeaviateClientBase
1 parent e791659 commit 99e49cb

7 files changed

Lines changed: 128 additions & 120 deletions

File tree

weaviate/client.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99

1010
from .auth import AuthCredentials
1111
from .backup import _BackupAsync, _Backup
12-
from .client_base import _WeaviateClientBase
12+
from weaviate.client_executor import _WeaviateClientExecutor
1313
from .collections.batch.client import _BatchClientWrapper
1414
from .collections.cluster import _Cluster, _ClusterAsync
15-
from .collections.collections.async_ import _CollectionsAsync
16-
from .collections.collections.sync import _Collections
15+
from .collections.collections import _Collections, _CollectionsAsync
1716
from .config import AdditionalConfig
1817
from .connect import executor
1918
from .connect.base import (
@@ -30,7 +29,7 @@
3029

3130

3231
@executor.wrap("async")
33-
class WeaviateAsyncClient(_WeaviateClientBase[ConnectionAsync]):
32+
class WeaviateAsyncClient(_WeaviateClientExecutor[ConnectionAsync]):
3433
"""
3534
The v4 Python-native Weaviate Client class that encapsulates Weaviate functionalities in one object.
3635
@@ -42,11 +41,17 @@ class WeaviateAsyncClient(_WeaviateClientBase[ConnectionAsync]):
4241
4342
Attributes:
4443
`backup`
45-
A `Backup` object instance connected to the same Weaviate instance as the Client.
44+
A `_BackupAsync` object instance connected to the same Weaviate instance as the Client.
4645
`cluster`
47-
A `Cluster` object instance connected to the same Weaviate instance as the Client.
46+
A `ClusterAsync` object instance connected to the same Weaviate instance as the Client.
4847
`collections`
4948
A `_CollectionsAsync` object instance connected to the same Weaviate instance as the Client.
49+
`debug`
50+
A `_DebugAsync` object instance connected to the same Weaviate instance as the Client.
51+
`roles`
52+
A `_RolesAsync` object instance connected to the same Weaviate instance as the Client.
53+
`users`
54+
A `_UsersAsync` object instance connected to the same Weaviate instance as the Client.
5055
"""
5156

5257
def __init__(
@@ -96,7 +101,7 @@ async def __aexit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None
96101

97102

98103
@executor.wrap("sync")
99-
class WeaviateClient(_WeaviateClientBase[ConnectionSync]):
104+
class WeaviateClient(_WeaviateClientExecutor[ConnectionSync]):
100105
"""
101106
The v4 Python-native Weaviate Client class that encapsulates Weaviate functionalities in one object.
102107
@@ -117,6 +122,12 @@ class WeaviateClient(_WeaviateClientBase[ConnectionSync]):
117122
A `Cluster` object instance connected to the same Weaviate instance as the Client.
118123
`collections`
119124
A `_Collections` object instance connected to the same Weaviate instance as the Client.
125+
`debug`
126+
A `_Debug` object instance connected to the same Weaviate instance as the Client.
127+
`roles`
128+
A `_Roles` object instance connected to the same Weaviate instance as the Client.
129+
`users`
130+
A `_Users` object instance connected to the same Weaviate instance as the Client.
120131
"""
121132

122133
def __init__(

weaviate/client.pyi

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,10 @@ from .types import NUMBER
2121

2222
TIMEOUT_TYPE = Union[Tuple[NUMBER, NUMBER], NUMBER]
2323

24-
from weaviate.client_base import _WeaviateClientBase
24+
from weaviate.client_executor import _WeaviateClientExecutor
2525
from weaviate.connect.v4 import ConnectionAsync, ConnectionSync
2626

27-
# Must define stubs here for WeaviateClient due to runtime patching of async -> sync methods
28-
# Cannot move Client nor WeaviateClient definitions away from client.py due to BC concerns
29-
# Must therefore duplicate the interface for all clients hiding their methods inside client.py
30-
31-
class WeaviateAsyncClient(_WeaviateClientBase[ConnectionAsync]):
27+
class WeaviateAsyncClient(_WeaviateClientExecutor[ConnectionAsync]):
3228
_connection: ConnectionAsync
3329
backup: _BackupAsync
3430
collections: _CollectionsAsync
@@ -48,7 +44,7 @@ class WeaviateAsyncClient(_WeaviateClientBase[ConnectionAsync]):
4844
async def __aenter__(self) -> "WeaviateAsyncClient": ...
4945
async def __aexit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None: ...
5046

51-
class WeaviateClient(_WeaviateClientBase[ConnectionSync]):
47+
class WeaviateClient(_WeaviateClientExecutor[ConnectionSync]):
5248
_connection: ConnectionSync
5349
backup: _Backup
5450
batch: _BatchClientWrapper
Lines changed: 96 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,102 @@
3636

3737

3838
class _WeaviateClientExecutor(Generic[ConnectionType]):
39-
def __init__(self, connection: ConnectionType):
40-
self._connection = connection
39+
_connection_type: Type[ConnectionType]
40+
41+
def __init__(
42+
self,
43+
connection_params: Optional[ConnectionParams] = None,
44+
embedded_options: Optional[EmbeddedOptions] = None,
45+
auth_client_secret: Optional[AuthCredentials] = None,
46+
additional_headers: Optional[dict] = None,
47+
additional_config: Optional[AdditionalConfig] = None,
48+
skip_init_checks: bool = False,
49+
) -> None:
50+
"""Initialise a WeaviateClient/WeaviateClientAsync class instance to use when interacting with Weaviate.
51+
52+
Use this specific initializer when you want to create a custom Client specific to your Weaviate setup.
53+
54+
To simplify connections to Weaviate Cloud or local instances, use the weaviate.connect_to_weaviate_cloud
55+
or weaviate.connect_to_local helper functions.
56+
57+
Arguments:
58+
- `connection_params`: `weaviate.connect.ConnectionParams` or None, optional
59+
- The connection parameters to use for the underlying HTTP requests.
60+
- `embedded_options`: `weaviate.EmbeddedOptions` or None, optional
61+
- The options to use when provisioning an embedded Weaviate instance.
62+
- `auth_client_secret`: `weaviate.AuthCredentials` or None, optional
63+
- Authenticate to weaviate by using one of the given authentication modes:
64+
- `weaviate.auth.AuthBearerToken` to use existing access and (optionally, but recommended) refresh tokens
65+
- `weaviate.auth.AuthClientPassword` to use username and password for oidc Resource Owner Password flow
66+
- `weaviate.auth.AuthClientCredentials` to use a client secret for oidc client credential flow
67+
- `additional_headers`: `dict` or None, optional
68+
- Additional headers to include in the requests.
69+
- Can be used to set OpenAI/HuggingFace/Cohere etc. keys.
70+
- [Here](https://weaviate.io/developers/weaviate/modules/reader-generator-modules/generative-openai#providing-the-key-to-weaviate) is an
71+
example of how to set API keys within this parameter.
72+
- `additional_config`: `weaviate.AdditionalConfig` or None, optional
73+
- Additional and advanced configuration options for Weaviate.
74+
- `skip_init_checks`: `bool`, optional
75+
- If set to `True` then the client will not perform any checks including ensuring that weaviate has started. This is useful for air-gapped environments and high-performance setups.
76+
"""
77+
connection_params, embedded_db = self.__parse_connection_params_and_embedded_db(
78+
connection_params, embedded_options
79+
)
80+
config = additional_config or AdditionalConfig()
81+
82+
self._connection = (
83+
self._connection_type( # pyright: ignore reportIncompatibleVariableOverride
84+
connection_params=connection_params,
85+
auth_client_secret=auth_client_secret,
86+
timeout_config=config.timeout,
87+
additional_headers=additional_headers,
88+
embedded_db=embedded_db,
89+
connection_config=config.connection,
90+
proxies=config.proxies,
91+
trust_env=config.trust_env,
92+
skip_init_checks=skip_init_checks,
93+
)
94+
)
95+
96+
self.integrations = _Integrations(self._connection)
97+
98+
def __parse_connection_params_and_embedded_db(
99+
self,
100+
connection_params: Optional[ConnectionParams],
101+
embedded_options: Optional[EmbeddedOptions],
102+
) -> Tuple[ConnectionParams, Optional[EmbeddedV4]]:
103+
if connection_params is None and embedded_options is None:
104+
raise TypeError("Either connection_params or embedded_options must be present.")
105+
elif connection_params is not None and embedded_options is not None:
106+
raise TypeError(
107+
f"connection_params is not expected to be set when using embedded_options but connection_params was {connection_params}"
108+
)
109+
110+
if embedded_options is not None:
111+
_validate_input(
112+
_ValidateArgument([EmbeddedOptions], "embedded_options", embedded_options)
113+
)
114+
115+
embedded_db = EmbeddedV4(options=embedded_options)
116+
embedded_db.start()
117+
return (
118+
ConnectionParams(
119+
http=ProtocolParams(
120+
host="localhost", port=embedded_db.options.port, secure=False
121+
),
122+
grpc=ProtocolParams(
123+
host="localhost", port=embedded_options.grpc_port, secure=False
124+
),
125+
),
126+
embedded_db,
127+
)
128+
129+
if not isinstance(connection_params, ConnectionParams):
130+
raise TypeError(
131+
f"connection_params is expected to be a ConnectionParams object but is {type(connection_params)}"
132+
)
133+
134+
return connection_params, None
41135

42136
async def __close_async(self) -> None:
43137
await executor.aresult(self._connection.close("async"))
@@ -184,106 +278,6 @@ def get_open_id_configuration(
184278
method=self._connection.get_open_id_configuration,
185279
)
186280

187-
188-
class _WeaviateClientBase(Generic[ConnectionType], _WeaviateClientExecutor[ConnectionType]):
189-
_connection: ConnectionType
190-
_connection_type: Type[ConnectionType]
191-
192-
def __init__(
193-
self,
194-
connection_params: Optional[ConnectionParams] = None,
195-
embedded_options: Optional[EmbeddedOptions] = None,
196-
auth_client_secret: Optional[AuthCredentials] = None,
197-
additional_headers: Optional[dict] = None,
198-
additional_config: Optional[AdditionalConfig] = None,
199-
skip_init_checks: bool = False,
200-
) -> None:
201-
"""Initialise a WeaviateClient/WeaviateClientAsync class instance to use when interacting with Weaviate.
202-
203-
Use this specific initializer when you want to create a custom Client specific to your Weaviate setup.
204-
205-
To simplify connections to Weaviate Cloud or local instances, use the weaviate.connect_to_weaviate_cloud
206-
or weaviate.connect_to_local helper functions.
207-
208-
Arguments:
209-
- `connection_params`: `weaviate.connect.ConnectionParams` or None, optional
210-
- The connection parameters to use for the underlying HTTP requests.
211-
- `embedded_options`: `weaviate.EmbeddedOptions` or None, optional
212-
- The options to use when provisioning an embedded Weaviate instance.
213-
- `auth_client_secret`: `weaviate.AuthCredentials` or None, optional
214-
- Authenticate to weaviate by using one of the given authentication modes:
215-
- `weaviate.auth.AuthBearerToken` to use existing access and (optionally, but recommended) refresh tokens
216-
- `weaviate.auth.AuthClientPassword` to use username and password for oidc Resource Owner Password flow
217-
- `weaviate.auth.AuthClientCredentials` to use a client secret for oidc client credential flow
218-
- `additional_headers`: `dict` or None, optional
219-
- Additional headers to include in the requests.
220-
- Can be used to set OpenAI/HuggingFace/Cohere etc. keys.
221-
- [Here](https://weaviate.io/developers/weaviate/modules/reader-generator-modules/generative-openai#providing-the-key-to-weaviate) is an
222-
example of how to set API keys within this parameter.
223-
- `additional_config`: `weaviate.AdditionalConfig` or None, optional
224-
- Additional and advanced configuration options for Weaviate.
225-
- `skip_init_checks`: `bool`, optional
226-
- If set to `True` then the client will not perform any checks including ensuring that weaviate has started. This is useful for air-gapped environments and high-performance setups.
227-
"""
228-
connection_params, embedded_db = self.__parse_connection_params_and_embedded_db(
229-
connection_params, embedded_options
230-
)
231-
config = additional_config or AdditionalConfig()
232-
233-
connection = self._connection_type( # pyright: ignore reportIncompatibleVariableOverride
234-
connection_params=connection_params,
235-
auth_client_secret=auth_client_secret,
236-
timeout_config=config.timeout,
237-
additional_headers=additional_headers,
238-
embedded_db=embedded_db,
239-
connection_config=config.connection,
240-
proxies=config.proxies,
241-
trust_env=config.trust_env,
242-
skip_init_checks=skip_init_checks,
243-
)
244-
245-
self.integrations = _Integrations(connection)
246-
247-
super().__init__(connection)
248-
249-
def __parse_connection_params_and_embedded_db(
250-
self,
251-
connection_params: Optional[ConnectionParams],
252-
embedded_options: Optional[EmbeddedOptions],
253-
) -> Tuple[ConnectionParams, Optional[EmbeddedV4]]:
254-
if connection_params is None and embedded_options is None:
255-
raise TypeError("Either connection_params or embedded_options must be present.")
256-
elif connection_params is not None and embedded_options is not None:
257-
raise TypeError(
258-
f"connection_params is not expected to be set when using embedded_options but connection_params was {connection_params}"
259-
)
260-
261-
if embedded_options is not None:
262-
_validate_input(
263-
_ValidateArgument([EmbeddedOptions], "embedded_options", embedded_options)
264-
)
265-
266-
embedded_db = EmbeddedV4(options=embedded_options)
267-
embedded_db.start()
268-
return (
269-
ConnectionParams(
270-
http=ProtocolParams(
271-
host="localhost", port=embedded_db.options.port, secure=False
272-
),
273-
grpc=ProtocolParams(
274-
host="localhost", port=embedded_options.grpc_port, secure=False
275-
),
276-
),
277-
embedded_db,
278-
)
279-
280-
if not isinstance(connection_params, ConnectionParams):
281-
raise TypeError(
282-
f"connection_params is expected to be a ConnectionParams object but is {type(connection_params)}"
283-
)
284-
285-
return connection_params, None
286-
287281
@executor.no_wrapping
288282
def is_connected(self) -> bool:
289283
"""Check if the client is connected to Weaviate.

weaviate/collections/cluster/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from weaviate.collections.cluster.async_ import _ClusterAsync
1+
from .async_ import _ClusterAsync
22
from .sync import _Cluster
33

44
__all__ = [
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from weaviate.collections.collection.async_ import CollectionAsync
2-
from weaviate.collections.collection.sync import Collection
1+
from .async_ import CollectionAsync
2+
from .sync import Collection
33

44
__all__ = ["CollectionAsync", "Collection"]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from .async_ import _CollectionsAsync
2+
from .sync import _Collections
3+
4+
__all__ = [
5+
"_CollectionsAsync",
6+
"_Collections",
7+
]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from weaviate.collections.data.async_ import _DataCollectionAsync
1+
from .async_ import _DataCollectionAsync
22
from .sync import _DataCollection
33

44
__all__ = ["_DataCollectionAsync", "_DataCollection"]

0 commit comments

Comments
 (0)