singlestoredb 1.7.0__cp38-abi3-win_amd64.whl → 1.7.2__cp38-abi3-win_amd64.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.

Potentially problematic release.


This version of singlestoredb might be problematic. Click here for more details.

_singlestoredb_accel.pyd CHANGED
Binary file
singlestoredb/__init__.py CHANGED
@@ -13,7 +13,7 @@ Examples
13
13
 
14
14
  """
15
15
 
16
- __version__ = '1.7.0'
16
+ __version__ = '1.7.2'
17
17
 
18
18
  from typing import Any
19
19
 
@@ -1,8 +1,9 @@
1
1
  import asyncio
2
+ import textwrap
2
3
  import typing
3
- import urllib.parse
4
4
 
5
5
  from ._config import AppConfig
6
+ from ._connection_info import ConnectionInfo
6
7
  from ._process import kill_process_by_port
7
8
 
8
9
  if typing.TYPE_CHECKING:
@@ -17,8 +18,7 @@ async def run_function_app(
17
18
  app: 'FastAPI',
18
19
  log_level: str = 'error',
19
20
  kill_existing_app_server: bool = True,
20
- ) -> None:
21
-
21
+ ) -> ConnectionInfo:
22
22
  global _running_server
23
23
  from ._uvicorn_util import AwaitableUvicornServer
24
24
 
@@ -52,8 +52,7 @@ async def run_function_app(
52
52
  def ping() -> str:
53
53
  return 'Success!'
54
54
 
55
- base_path = urllib.parse.urlparse(app_config.url).path
56
- app.root_path = base_path
55
+ app.root_path = app_config.base_path
57
56
 
58
57
  config = uvicorn.Config(
59
58
  app,
@@ -66,5 +65,26 @@ async def run_function_app(
66
65
  asyncio.create_task(_running_server.serve())
67
66
  await _running_server.wait_for_startup()
68
67
 
68
+ connection_info = ConnectionInfo(app_config.base_url, app_config.token)
69
+
69
70
  if app_config.running_interactively:
70
- print(f'Cloud function available at {app_config.url}')
71
+ if app_config.is_gateway_enabled:
72
+ print(
73
+ 'Cloud function available at '
74
+ f'{app_config.base_url}docs?authToken={app_config.token}',
75
+ )
76
+ else:
77
+ curl_header = f'-H "Authorization: Bearer {app_config.token}"'
78
+ curl_example = f'curl "{app_config.base_url}" {curl_header}'
79
+ print(
80
+ textwrap.dedent(f"""
81
+ Cloud function available at {app_config.base_url}
82
+
83
+ Auth Token: {app_config.token}
84
+
85
+ Curl example: {curl_example}
86
+
87
+ """).strip(),
88
+ )
89
+
90
+ return connection_info
@@ -1,33 +1,66 @@
1
1
  import os
2
2
  from dataclasses import dataclass
3
+ from typing import Optional
3
4
 
4
5
 
5
6
  @dataclass
6
7
  class AppConfig:
7
8
  listen_port: int
8
- url: str
9
+ base_url: str
10
+ base_path: str
11
+ app_token: Optional[str]
12
+ user_token: Optional[str]
9
13
  running_interactively: bool
14
+ is_gateway_enabled: bool
10
15
 
11
- @classmethod
12
- def from_env(cls) -> 'AppConfig':
13
- port = os.environ.get('SINGLESTOREDB_APP_LISTEN_PORT')
14
- if port is None:
15
- raise RuntimeError(
16
- 'Missing SINGLESTOREDB_APP_LISTEN_PORT environment variable. '
17
- 'Is the code running outside SingleStoreDB notebook environment?',
18
- )
19
- url = os.environ.get('SINGLESTOREDB_APP_URL')
20
- if url is None:
16
+ @staticmethod
17
+ def _read_variable(name: str) -> str:
18
+ value = os.environ.get(name)
19
+ if value is None:
21
20
  raise RuntimeError(
22
- 'Missing SINGLESTOREDB_APP_URL environment variable. '
21
+ f'Missing {name} environment variable. '
23
22
  'Is the code running outside SingleStoreDB notebook environment?',
24
23
  )
24
+ return value
25
+
26
+ @classmethod
27
+ def from_env(cls) -> 'AppConfig':
28
+ port = cls._read_variable('SINGLESTOREDB_APP_LISTEN_PORT')
29
+ base_url = cls._read_variable('SINGLESTOREDB_APP_BASE_URL')
30
+ base_path = cls._read_variable('SINGLESTOREDB_APP_BASE_PATH')
25
31
 
26
32
  workload_type = os.environ.get('SINGLESTOREDB_WORKLOAD_TYPE')
27
33
  running_interactively = workload_type == 'InteractiveNotebook'
28
34
 
35
+ is_gateway_enabled = 'SINGLESTOREDB_NOVA_GATEWAY_ENDPOINT' in os.environ
36
+
37
+ app_token = os.environ.get('SINGLESTOREDB_APP_TOKEN')
38
+ user_token = os.environ.get('SINGLESTOREDB_USER_TOKEN')
39
+
40
+ # Make sure the required variables are present
41
+ # and present useful error message if not
42
+ if running_interactively:
43
+ if is_gateway_enabled:
44
+ app_token = cls._read_variable('SINGLESTOREDB_APP_TOKEN')
45
+ else:
46
+ user_token = cls._read_variable('SINGLESTOREDB_USER_TOKEN')
47
+
29
48
  return cls(
30
49
  listen_port=int(port),
31
- url=url,
50
+ base_url=base_url,
51
+ base_path=base_path,
52
+ app_token=app_token,
53
+ user_token=user_token,
32
54
  running_interactively=running_interactively,
55
+ is_gateway_enabled=is_gateway_enabled,
33
56
  )
57
+
58
+ @property
59
+ def token(self) -> Optional[str]:
60
+ """
61
+ Returns None if running non-interactively
62
+ """
63
+ if self.is_gateway_enabled:
64
+ return self.app_token
65
+ else:
66
+ return self.user_token
@@ -0,0 +1,10 @@
1
+ from dataclasses import dataclass
2
+ from typing import Optional
3
+
4
+
5
+ @dataclass
6
+ class ConnectionInfo:
7
+ url: str
8
+
9
+ # Only present in interactive mode
10
+ token: Optional[str]
@@ -1,51 +1,47 @@
1
1
  import typing
2
- import urllib.parse
3
2
 
4
3
  from ._config import AppConfig
5
4
  from ._process import kill_process_by_port
5
+ from ._stdout_supress import StdoutSuppressor
6
+ from singlestoredb.apps._connection_info import ConnectionInfo
6
7
 
7
8
  if typing.TYPE_CHECKING:
8
- from plotly.graph_objs import Figure
9
+ from dash import Dash
9
10
 
10
11
 
11
- def run_dashboard_app(
12
- figure: 'Figure',
12
+ async def run_dashboard_app(
13
+ app: 'Dash',
13
14
  debug: bool = False,
14
15
  kill_existing_app_server: bool = True,
15
- ) -> None:
16
+ ) -> ConnectionInfo:
16
17
  try:
17
- import dash
18
+ from dash import Dash
18
19
  except ImportError:
19
20
  raise ImportError('package dash is required to run dashboards')
20
21
 
21
- try:
22
- from plotly.graph_objs import Figure
23
- except ImportError:
24
- raise ImportError('package dash is required to run dashboards')
25
-
26
- if not isinstance(figure, Figure):
27
- raise TypeError('figure is not an instance of plotly Figure')
22
+ if not isinstance(app, Dash):
23
+ raise TypeError('app is not an instance of Dash App')
28
24
 
29
25
  app_config = AppConfig.from_env()
30
26
 
31
27
  if kill_existing_app_server:
32
28
  kill_process_by_port(app_config.listen_port)
33
29
 
34
- base_path = urllib.parse.urlparse(app_config.url).path
35
-
36
- app = dash.Dash(requests_pathname_prefix=base_path)
37
- app.layout = dash.html.Div(
38
- [
39
- dash.dcc.Graph(figure=figure),
40
- ],
41
- )
42
-
43
- app.run(
44
- host='0.0.0.0',
45
- debug=debug,
46
- port=str(app_config.listen_port),
47
- jupyter_mode='external',
48
- )
30
+ if app.config.requests_pathname_prefix is None or \
31
+ app.config.requests_pathname_prefix != app_config.base_path:
32
+ raise RuntimeError('''
33
+ requests_pathname_prefix of the Dash App is invalid. Please set
34
+ requests_pathname_prefix=os.environ['SINGLESTOREDB_APP_BASE_PATH']
35
+ while initializing the Dash App and retry''')
36
+
37
+ with StdoutSuppressor():
38
+ app.run(
39
+ host='0.0.0.0',
40
+ debug=debug,
41
+ port=str(app_config.listen_port),
42
+ jupyter_mode='external',
43
+ )
49
44
 
50
45
  if app_config.running_interactively:
51
- print(f'Dash app available at {app_config.url}')
46
+ print(f'Dash app available at {app_config.base_url}?authToken={app_config.token}')
47
+ return ConnectionInfo(app_config.base_url, app_config.token)
@@ -0,0 +1,30 @@
1
+ import io
2
+ import sys
3
+ from typing import Optional
4
+
5
+
6
+ class StdoutSuppressor:
7
+ """
8
+ Supresses the stdout for code executed within the context.
9
+ This should not be used for asynchronous or threaded executions.
10
+
11
+ ```py
12
+ with Supressor():
13
+ print("This won't be printed")
14
+ ```
15
+
16
+ """
17
+
18
+ def __enter__(self) -> None:
19
+ self.stdout = sys.stdout
20
+ self.buffer = io.StringIO()
21
+ sys.stdout = self.buffer
22
+
23
+ def __exit__(
24
+ self,
25
+ exc_type: Optional[object],
26
+ exc_value: Optional[Exception],
27
+ exc_traceback: Optional[str],
28
+ ) -> None:
29
+ del self.buffer
30
+ sys.stdout = self.stdout
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: singlestoredb
3
- Version: 1.7.0
3
+ Version: 1.7.2
4
4
  Summary: Interface to the SingleStoreDB database and workspace management APIs
5
5
  Home-page: https://github.com/singlestore-labs/singlestoredb-python
6
6
  Author: SingleStore
@@ -1,5 +1,5 @@
1
- _singlestoredb_accel.pyd,sha256=gJJyyabIixf5VSFu-TZUyDH7e81IWGWM2AM5_XWlvaY,59392
2
- singlestoredb/__init__.py,sha256=QfF5_hgd3Qij5ssWBZesWxdych7o-gKPfWx4G1uR-XM,1697
1
+ _singlestoredb_accel.pyd,sha256=74y_1TpqSVFQ-rTN7XE73b1dJ16kA-s1K57dV-NmkEY,59392
2
+ singlestoredb/__init__.py,sha256=jSf2uwMGpvrTEf60dTZMxvO63yzzmKGE12bZUuCMOQA,1697
3
3
  singlestoredb/auth.py,sha256=RmYiH0Wlc2RXc4pTlRMysxtBI445ggCIwojWKC_eDLE,7844
4
4
  singlestoredb/config.py,sha256=LlrwKor_23uA9u7jWBYb-IaOKs30CjWIM7o9xCXEPcc,12721
5
5
  singlestoredb/connection.py,sha256=QC5YQemwJOhdW_-ZBFpNLE15xFxwI1fB2LuvE1hNi9k,46812
@@ -11,10 +11,12 @@ singlestoredb/ai/__init__.py,sha256=nT048t90xqjaNhz7KJ10KfSVW4RcZRoujyC6po6Nmb8,
11
11
  singlestoredb/ai/embeddings.py,sha256=KVvQY3viyYWXDBobFpj0xqiGRijt36zcHHlPNAfFAxA,770
12
12
  singlestoredb/alchemy/__init__.py,sha256=bUmCl1xUn2v36RMbXLIrvgKzZSqx71mp1ReUw9JeVA8,2613
13
13
  singlestoredb/apps/__init__.py,sha256=IKQrPKb1d_LQvmr7jXQvgPRrB5Ja_1kGAXwYvdjp6ok,120
14
- singlestoredb/apps/_cloud_functions.py,sha256=v8PEBz8MXryarE0nfqjwwnZiAO1S659WeITXGjJRcC4,2106
15
- singlestoredb/apps/_config.py,sha256=DzWlFdW0_wANnE5XddLQeUv8y_zRUvw8KNz7B4l9KnU,1089
16
- singlestoredb/apps/_dashboards.py,sha256=FOEPjxpiQL9vBaMQBlTfpmA0b4a-cadSdTFrfjdIcY4,1323
14
+ singlestoredb/apps/_cloud_functions.py,sha256=DMRC-4z3Q52hsKb_WlolfNcYV-5XmQGiJWbbaUxFZ0s,2794
15
+ singlestoredb/apps/_config.py,sha256=kMNpkc-RtPrk_XW0kLAXeF444WIlBXzI8dLnFgIW5Jw,2184
16
+ singlestoredb/apps/_connection_info.py,sha256=t8hFOSRALXt5tqvDX0fholKoT148xktE5r__SYdH6Dk,185
17
+ singlestoredb/apps/_dashboards.py,sha256=qEdDivjwS68Uukay0Qw-3awHZFpkcqapzd3vLaVUzWo,1521
17
18
  singlestoredb/apps/_process.py,sha256=eMiBO4piaRX1S6zdnMx0X0E4J7E1XrXndnVW0GRYq1Y,976
19
+ singlestoredb/apps/_stdout_supress.py,sha256=QRV-IHQQMvWMeJfqORuVE2-Il6ohO2Ti4IokFoTCJWE,689
18
20
  singlestoredb/apps/_uvicorn_util.py,sha256=Petkmq5keBPfXZsHBrnZfY3O2rUHvb3Cw6o-BRz5MP0,994
19
21
  singlestoredb/functions/__init__.py,sha256=EVxqWOCcXiIX4Yj7rljAYBBoVbTvm2KSuKSkMBDnEeU,42
20
22
  singlestoredb/functions/decorator.py,sha256=M103c1JAZfyGFQAU4uJ_J8XGGH3InhcfrNUCoEORNFQ,5335
@@ -123,9 +125,9 @@ singlestoredb/utils/events.py,sha256=rC9cHAetua_E1f-EiFkFM-gJzQSQIH5Uk-4sspC3KjI
123
125
  singlestoredb/utils/mogrify.py,sha256=gCcn99-vgsGVjTUV7RHJ6hH4vCNrsGB_Xo4z8kiSPDQ,4201
124
126
  singlestoredb/utils/results.py,sha256=wR70LhCqlobniZf52r67zYLBOKjWHQm68NAskdRQND8,15862
125
127
  singlestoredb/utils/xdict.py,sha256=-wi1lSPTnY99fhVMBhPKJ8cCsQhNG4GMUfkEBDKYgCw,13321
126
- singlestoredb-1.7.0.dist-info/LICENSE,sha256=Bojenzui8aPNjlF3w4ojguDP7sTf8vFV_9Gc2UAG1sg,11542
127
- singlestoredb-1.7.0.dist-info/METADATA,sha256=dx6R3uQafE_V3NoNKsT5mJCqTo1jrF6NdTdBqZ0rgY4,5710
128
- singlestoredb-1.7.0.dist-info/WHEEL,sha256=UyMHzmWA0xVqVPKfTiLs2eN3OWWZUl-kQemNbpIqlKo,100
129
- singlestoredb-1.7.0.dist-info/entry_points.txt,sha256=bSLaTWB5zGjpVYPAaI46MkkDup0su-eb3uAhCNYuRV0,48
130
- singlestoredb-1.7.0.dist-info/top_level.txt,sha256=SDtemIXf-Kp-_F2f_S6x0db33cHGOILdAEsIQZe2LZc,35
131
- singlestoredb-1.7.0.dist-info/RECORD,,
128
+ singlestoredb-1.7.2.dist-info/LICENSE,sha256=Bojenzui8aPNjlF3w4ojguDP7sTf8vFV_9Gc2UAG1sg,11542
129
+ singlestoredb-1.7.2.dist-info/METADATA,sha256=EcxKSeGY473TFRuGP6W42122Mz_hry8hPLXAVseir0A,5710
130
+ singlestoredb-1.7.2.dist-info/WHEEL,sha256=UyMHzmWA0xVqVPKfTiLs2eN3OWWZUl-kQemNbpIqlKo,100
131
+ singlestoredb-1.7.2.dist-info/entry_points.txt,sha256=bSLaTWB5zGjpVYPAaI46MkkDup0su-eb3uAhCNYuRV0,48
132
+ singlestoredb-1.7.2.dist-info/top_level.txt,sha256=SDtemIXf-Kp-_F2f_S6x0db33cHGOILdAEsIQZe2LZc,35
133
+ singlestoredb-1.7.2.dist-info/RECORD,,