definite-sdk 0.1.11__py3-none-any.whl → 0.1.12__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.
definite_sdk/sql.py CHANGED
@@ -1,4 +1,4 @@
1
- from typing import Any, Dict, List, Optional, Union
1
+ from typing import Any, Dict, Optional
2
2
 
3
3
  import requests
4
4
 
@@ -31,7 +31,9 @@ class DefiniteSqlClient:
31
31
  ... "timeDimensions": [{"dimension": "sales.date", "granularity": "month"}],
32
32
  ... "limit": 1000
33
33
  ... }
34
- >>> result = sql_client.execute_cube_query(cube_query, integration_id="my_cube_integration")
34
+ >>> result = sql_client.execute_cube_query(
35
+ ... cube_query, integration_id="my_cube_integration"
36
+ ... )
35
37
  >>> print(result)
36
38
  """
37
39
 
@@ -46,11 +48,7 @@ class DefiniteSqlClient:
46
48
  self._api_key = api_key
47
49
  self._sql_url = api_url + SQL_ENDPOINT
48
50
 
49
- def execute(
50
- self,
51
- sql: str,
52
- integration_id: Optional[str] = None
53
- ) -> Dict[str, Any]:
51
+ def execute(self, sql: str, integration_id: Optional[str] = None) -> Dict[str, Any]:
54
52
  """
55
53
  Executes a SQL query against a database integration.
56
54
 
@@ -69,7 +67,7 @@ class DefiniteSqlClient:
69
67
  >>> result = sql_client.execute("SELECT COUNT(*) FROM users")
70
68
  >>> print(result)
71
69
  """
72
- payload = {"sql": sql}
70
+ payload: Dict[str, Any] = {"sql": sql}
73
71
  if integration_id:
74
72
  payload["integration_id"] = integration_id
75
73
 
@@ -82,11 +80,12 @@ class DefiniteSqlClient:
82
80
  return response.json()
83
81
 
84
82
  def execute_cube_query(
85
- self,
86
- cube_query: Dict[str, Any],
83
+ self,
84
+ cube_query: Dict[str, Any],
87
85
  integration_id: Optional[str] = None,
88
86
  persist: bool = True,
89
87
  invalidate: bool = False,
88
+ raw: bool = False,
90
89
  ) -> Dict[str, Any]:
91
90
  """
92
91
  Executes a Cube query against a Cube integration.
@@ -97,6 +96,7 @@ class DefiniteSqlClient:
97
96
  If not provided, the default integration will be used.
98
97
  persist (bool): Whether to persist the query result to the cache.
99
98
  invalidate (bool): Whether to invalidate the cached result.
99
+ raw (bool): Whether to return raw/unformatted cube results.
100
100
 
101
101
  Returns:
102
102
  Dict[str, Any]: The query result as returned by the API.
@@ -110,24 +110,38 @@ class DefiniteSqlClient:
110
110
  ... "measures": ["sales.total_amount"],
111
111
  ... "timeDimensions": [{
112
112
  ... "dimension": "sales.date",
113
- ... "granularity": "month"
113
+ ... "granularity": "month",
114
114
  ... }],
115
115
  ... "limit": 1000
116
116
  ... }
117
- >>> result = sql_client.execute_cube_query(cube_query, "my_cube_integration")
117
+ >>> result = sql_client.execute_cube_query(
118
+ ... cube_query, "my_cube_integration"
119
+ ... )
118
120
  >>> print(result)
121
+
122
+ >>> # To get raw/unformatted results:
123
+ >>> raw_result = sql_client.execute_cube_query(
124
+ ... cube_query, "my_cube_integration", raw=True
125
+ ... )
126
+ >>> print(raw_result)
119
127
  """
120
- payload = {"cube_query": cube_query}
128
+ payload: Dict[str, Any] = {"cube_query": cube_query}
121
129
  if integration_id:
122
130
  payload["integration_id"] = integration_id
123
131
  if persist:
124
132
  payload["persist"] = persist
125
133
  if invalidate:
126
134
  payload["invalidate"] = invalidate
135
+
136
+ # Build URL with query parameters
137
+ url = self._sql_url
138
+ if raw:
139
+ url += "?raw=true"
140
+
127
141
  response = requests.post(
128
- self._sql_url,
142
+ url,
129
143
  json=payload,
130
144
  headers={"Authorization": "Bearer " + self._api_key},
131
145
  )
132
146
  response.raise_for_status()
133
- return response.json()
147
+ return response.json()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: definite-sdk
3
- Version: 0.1.11
3
+ Version: 0.1.12
4
4
  Summary: Definite SDK for Python
5
5
  License: MIT
6
6
  Author: Definite
@@ -5,9 +5,9 @@ definite_sdk/integration.py,sha256=v15QIpWm3eAZr-cmavfA39LXTjpskEEQ2SM_TBV4E1U,3
5
5
  definite_sdk/message.py,sha256=I3qx2v9gIcC9NZyr5zEp_Seft8clRoER4WeUbAaDiFc,6549
6
6
  definite_sdk/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  definite_sdk/secret.py,sha256=3wvEnTZ946hOxJBdB29dxvppwJ0x-TJV_LxRcXGqtis,2503
8
- definite_sdk/sql.py,sha256=nVPUuQy4zLMoeUe9bRgU1eMmIJBwlNCNXZm2tO0M8sw,4223
8
+ definite_sdk/sql.py,sha256=o2ume-S7__wp8hMBy2aC6dmGYV4s-IXMlMAyEuyAP84,4705
9
9
  definite_sdk/store.py,sha256=7VYvROIrlWyM_ZX3LpqWWAfVLNDm0XMccMLv6qi9id8,5575
10
- definite_sdk-0.1.11.dist-info/LICENSE,sha256=jMd7PtwNWiMoGIDgFutC1v4taO69W9SRZLKe9o470Vk,1064
11
- definite_sdk-0.1.11.dist-info/METADATA,sha256=Xvh6IRpK-0vcD1mY814f_otQpY-300jXxRHR-cXtWro,9136
12
- definite_sdk-0.1.11.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
13
- definite_sdk-0.1.11.dist-info/RECORD,,
10
+ definite_sdk-0.1.12.dist-info/LICENSE,sha256=jMd7PtwNWiMoGIDgFutC1v4taO69W9SRZLKe9o470Vk,1064
11
+ definite_sdk-0.1.12.dist-info/METADATA,sha256=mR32ZrkWtX_q7BBMF6dtE2f2lHicy2SBo1lkMxOTFto,9136
12
+ definite_sdk-0.1.12.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
13
+ definite_sdk-0.1.12.dist-info/RECORD,,