mostlyai 0.6.1__tar.gz → 0.6.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mostlyai
3
- Version: 0.6.1
3
+ Version: 0.6.2
4
4
  Summary: MOSTLY AI - Python Client
5
5
  Home-page: https://app.mostly.ai/
6
6
  License: Apache-2.0
@@ -0,0 +1,18 @@
1
+ # Copyright 2024 MOSTLY AI
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
+ from mostlyai.client.api import MostlyAI
16
+
17
+ __all__ = ["MostlyAI"]
18
+ __version__ = "0.6.2" # Do not set this manually. Use poetry version [params].
@@ -0,0 +1,14 @@
1
+ # Copyright 2024 MOSTLY AI
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
+
@@ -1,3 +1,17 @@
1
+ # Copyright 2024 MOSTLY AI
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
+
1
15
  import base64
2
16
  import io
3
17
  import warnings
@@ -1,3 +1,17 @@
1
+ # Copyright 2024 MOSTLY AI
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
+
1
15
  import time
2
16
  from pathlib import Path
3
17
  from typing import Callable, Union, Any, Optional
@@ -1,3 +1,17 @@
1
+ # Copyright 2024 MOSTLY AI
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
+
1
15
  import re
2
16
  from typing import Callable
3
17
 
@@ -1,3 +1,17 @@
1
+ # Copyright 2024 MOSTLY AI
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
+
1
15
  from pathlib import Path
2
16
  from typing import Any, Optional, Union, Literal
3
17
 
@@ -19,6 +33,7 @@ from mostlyai.client.domain import (
19
33
  SourceTableConfig,
20
34
  SyntheticDatasetConfig,
21
35
  SyntheticProbeConfig,
36
+ AboutService,
22
37
  )
23
38
  from mostlyai.client.synthetic_datasets import (
24
39
  _MostlySyntheticDatasetsClient,
@@ -85,12 +100,24 @@ class MostlyAI(_MostlyBaseClient):
85
100
  self.generators = _MostlyGeneratorsClient(**client_kwargs)
86
101
  self.synthetic_datasets = _MostlySyntheticDatasetsClient(**client_kwargs)
87
102
  self.synthetic_probes = _MostlySyntheticProbesClient(**client_kwargs)
103
+ try:
104
+ version = self.about().version
105
+ email = self.me().email
106
+ rich.print(
107
+ f"Connected to {self.base_url} ({version}) as [bold]{email}[/bold]"
108
+ )
109
+ except Exception as e:
110
+ rich.print(f"Failed to connect to {self.base_url}: {e}")
88
111
 
89
112
  def __repr__(self) -> str:
90
113
  api_key = "'***'" if self.api_key else "None"
91
114
  return f"MostlyAI(base_url='{self.base_url}', api_key={api_key})"
92
115
 
93
- def connect(self, config: Union[ConnectorConfig, dict[str, Any]]) -> Connector:
116
+ def connect(
117
+ self,
118
+ config: Union[ConnectorConfig, dict[str, Any]],
119
+ test_connection: Optional[bool] = True,
120
+ ) -> Connector:
94
121
  """
95
122
  Create a connector and optionally validate the connection before saving.
96
123
 
@@ -115,6 +142,7 @@ class MostlyAI(_MostlyBaseClient):
115
142
 
116
143
  Args:
117
144
  config: Configuration for the connector. Can be either a ConnectorConfig object or an equivalent dictionary.
145
+ test_connection: Whether to validate the connection before saving.
118
146
 
119
147
  The structures of the `config`, `secrets` and `ssl` parameters depend on the connector `type`:
120
148
 
@@ -236,7 +264,7 @@ class MostlyAI(_MostlyBaseClient):
236
264
  Returns:
237
265
  Connector: The created connector.
238
266
  """
239
- c = self.connectors.create(config)
267
+ c = self.connectors.create(config=config, test_connection=test_connection)
240
268
  rich.print(
241
269
  f"Created connector [link={self.base_url}/d/connectors/{c.id} blue underline]{c.id}[/]"
242
270
  )
@@ -537,11 +565,11 @@ class MostlyAI(_MostlyBaseClient):
537
565
  ```
538
566
 
539
567
  Returns:
540
- CurrentUser: Information about the current user.
568
+ Information about the current user.
541
569
  """
542
570
  return self.request(verb=GET, path=["users", "me"], response_type=CurrentUser)
543
571
 
544
- def about(self) -> dict[str, Any]:
572
+ def about(self) -> AboutService:
545
573
  """
546
574
  Retrieve information about the platform.
547
575
 
@@ -554,9 +582,9 @@ class MostlyAI(_MostlyBaseClient):
554
582
  ```
555
583
 
556
584
  Returns:
557
- dict[str, Any]: Information about the platform.
585
+ Information about the platform.
558
586
  """
559
- return self.request(verb=GET, path=["about"])
587
+ return self.request(verb=GET, path=["about"], response_type=AboutService)
560
588
 
561
589
  def models(self, model_type: Union[str, ModelType]) -> list[str]:
562
590
  """
@@ -1,3 +1,17 @@
1
+ # Copyright 2024 MOSTLY AI
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
+
1
15
  import os
2
16
  import sys
3
17
  import warnings
@@ -121,6 +135,10 @@ class _MostlyBaseClient:
121
135
  if isinstance(kwargs["json"], BaseModel):
122
136
  kwargs["json"] = kwargs["json"].model_dump()
123
137
  kwargs["json"] = map_snake_to_camel_case(kwargs["json"])
138
+ if "params" in kwargs and do_json_camel_case:
139
+ if isinstance(kwargs["params"], BaseModel):
140
+ kwargs["params"] = kwargs["params"].model_dump()
141
+ kwargs["params"] = map_snake_to_camel_case(kwargs["params"])
124
142
 
125
143
  try:
126
144
  with httpx.Client(timeout=self.timeout, verify=self.ssl_verify) as client:
@@ -1,3 +1,17 @@
1
+ # Copyright 2024 MOSTLY AI
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
+
1
15
  from typing import Any, Iterator, Optional, List, Dict, Union
2
16
 
3
17
  from mostlyai.client.base import DELETE, GET, PATCH, POST, Paginator, _MostlyBaseClient
@@ -78,6 +92,7 @@ class _MostlyConnectorsClient(_MostlyBaseClient):
78
92
  def create(
79
93
  self,
80
94
  config: Union[ConnectorConfig, dict[str, Any]],
95
+ test_connection: Optional[bool] = True,
81
96
  ) -> Connector:
82
97
  """
83
98
  Create a connector and optionally validate the connection before saving.
@@ -86,12 +101,17 @@ class _MostlyConnectorsClient(_MostlyBaseClient):
86
101
 
87
102
  Args:
88
103
  config: Configuration for the connector.
104
+ test_connection: Whether to test the connection before saving the connector
89
105
 
90
106
  Returns:
91
107
  The created connector object.
92
108
  """
93
109
  response = self.request(
94
- verb=POST, path=[], json=config, response_type=Connector
110
+ verb=POST,
111
+ path=[],
112
+ json=config,
113
+ params={"test_connection": test_connection},
114
+ response_type=Connector,
95
115
  )
96
116
  return response
97
117