definite-sdk 0.1.9__py3-none-any.whl → 0.1.11__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/client.py +50 -0
- definite_sdk/sql.py +9 -2
- {definite_sdk-0.1.9.dist-info → definite_sdk-0.1.11.dist-info}/METADATA +35 -1
- {definite_sdk-0.1.9.dist-info → definite_sdk-0.1.11.dist-info}/RECORD +6 -6
- {definite_sdk-0.1.9.dist-info → definite_sdk-0.1.11.dist-info}/LICENSE +0 -0
- {definite_sdk-0.1.9.dist-info → definite_sdk-0.1.11.dist-info}/WHEEL +0 -0
definite_sdk/client.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import os
|
|
2
2
|
from typing import Optional
|
|
3
3
|
|
|
4
|
+
import requests
|
|
4
5
|
from definite_sdk.integration import DefiniteIntegrationStore
|
|
5
6
|
from definite_sdk.message import DefiniteMessageClient
|
|
6
7
|
from definite_sdk.secret import DefiniteSecretStore
|
|
@@ -66,6 +67,55 @@ class DefiniteClient:
|
|
|
66
67
|
|
|
67
68
|
return DefiniteSqlClient(self.api_key, self.api_url)
|
|
68
69
|
|
|
70
|
+
def attach_ducklake(self, alias: str = "lake") -> str:
|
|
71
|
+
"""Generates SQL statements to attach DuckLake to a DuckDB connection.
|
|
72
|
+
|
|
73
|
+
This method fetches the team's DuckLake integration credentials and generates
|
|
74
|
+
the necessary SQL statements to create a GCS secret and attach DuckLake.
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
alias: The alias name for the attached DuckLake database (default: "lake")
|
|
78
|
+
|
|
79
|
+
Returns:
|
|
80
|
+
str: SQL statements to execute for attaching DuckLake
|
|
81
|
+
|
|
82
|
+
Example:
|
|
83
|
+
>>> client = DefiniteClient(os.environ["DEFINITE_API_KEY"])
|
|
84
|
+
>>> sql = client.attach_ducklake()
|
|
85
|
+
>>> conn.execute(sql)
|
|
86
|
+
"""
|
|
87
|
+
# Fetch DuckLake integration details
|
|
88
|
+
response = requests.get(
|
|
89
|
+
f"{self.api_url}/v1/api/integration/DuckLake",
|
|
90
|
+
headers={"Authorization": f"Bearer {self.api_key}"},
|
|
91
|
+
)
|
|
92
|
+
response.raise_for_status()
|
|
93
|
+
dl_integration = response.json()
|
|
94
|
+
|
|
95
|
+
# Generate SQL statements
|
|
96
|
+
create_secret_sql = f"""CREATE SECRET (
|
|
97
|
+
TYPE gcs,
|
|
98
|
+
KEY_ID '{dl_integration['gcs_access_key_id']}',
|
|
99
|
+
SECRET '{dl_integration['gcs_secret_access_key']}'
|
|
100
|
+
);"""
|
|
101
|
+
|
|
102
|
+
# Build PostgreSQL connection string
|
|
103
|
+
pg_conn_str = (
|
|
104
|
+
f"postgresql://{dl_integration['pg_user']}:"
|
|
105
|
+
f"{dl_integration['pg_password']}@"
|
|
106
|
+
f"{dl_integration['pg_host']}:"
|
|
107
|
+
f"{dl_integration['pg_port']}/"
|
|
108
|
+
f"{dl_integration['pg_database']}"
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
attach_sql = (
|
|
112
|
+
f"ATTACH 'ducklake:postgres:{pg_conn_str}' AS {alias} "
|
|
113
|
+
f"(DATA_PATH 'gs://{dl_integration['gcs_bucket_path']}', "
|
|
114
|
+
f"METADATA_SCHEMA '{dl_integration['pg_schema']}');"
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
return f"{create_secret_sql}\n\n{attach_sql}"
|
|
118
|
+
|
|
69
119
|
# Alias methods for consistency
|
|
70
120
|
def kv_store(self, name: str) -> DefiniteKVStore:
|
|
71
121
|
"""Alias for get_kv_store."""
|
definite_sdk/sql.py
CHANGED
|
@@ -84,7 +84,9 @@ class DefiniteSqlClient:
|
|
|
84
84
|
def execute_cube_query(
|
|
85
85
|
self,
|
|
86
86
|
cube_query: Dict[str, Any],
|
|
87
|
-
integration_id: Optional[str] = None
|
|
87
|
+
integration_id: Optional[str] = None,
|
|
88
|
+
persist: bool = True,
|
|
89
|
+
invalidate: bool = False,
|
|
88
90
|
) -> Dict[str, Any]:
|
|
89
91
|
"""
|
|
90
92
|
Executes a Cube query against a Cube integration.
|
|
@@ -93,6 +95,8 @@ class DefiniteSqlClient:
|
|
|
93
95
|
cube_query (Dict[str, Any]): The Cube query in JSON format.
|
|
94
96
|
integration_id (Optional[str]): The Cube integration ID to query against.
|
|
95
97
|
If not provided, the default integration will be used.
|
|
98
|
+
persist (bool): Whether to persist the query result to the cache.
|
|
99
|
+
invalidate (bool): Whether to invalidate the cached result.
|
|
96
100
|
|
|
97
101
|
Returns:
|
|
98
102
|
Dict[str, Any]: The query result as returned by the API.
|
|
@@ -116,7 +120,10 @@ class DefiniteSqlClient:
|
|
|
116
120
|
payload = {"cube_query": cube_query}
|
|
117
121
|
if integration_id:
|
|
118
122
|
payload["integration_id"] = integration_id
|
|
119
|
-
|
|
123
|
+
if persist:
|
|
124
|
+
payload["persist"] = persist
|
|
125
|
+
if invalidate:
|
|
126
|
+
payload["invalidate"] = invalidate
|
|
120
127
|
response = requests.post(
|
|
121
128
|
self._sql_url,
|
|
122
129
|
json=payload,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: definite-sdk
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.11
|
|
4
4
|
Summary: Definite SDK for Python
|
|
5
5
|
License: MIT
|
|
6
6
|
Author: Definite
|
|
@@ -59,6 +59,7 @@ client = DefiniteClient("YOUR_API_KEY")
|
|
|
59
59
|
- **Integration Store**: Read-only access to integration configurations
|
|
60
60
|
- **Messaging**: Send messages through various channels (Slack, and more coming soon)
|
|
61
61
|
- **dlt Integration**: Run dlt pipelines with automatic state persistence to Definite
|
|
62
|
+
- **DuckLake Integration**: Easy attachment of your team's DuckLake to DuckDB connections
|
|
62
63
|
- **DuckDB Support**: Automatic discovery and connection to team's DuckDB integrations
|
|
63
64
|
|
|
64
65
|
## Basic Usage
|
|
@@ -231,6 +232,39 @@ pipeline.run(orders())
|
|
|
231
232
|
last_cursor = pipeline.get_state("orders")
|
|
232
233
|
```
|
|
233
234
|
|
|
235
|
+
### DuckLake Integration
|
|
236
|
+
|
|
237
|
+
Attach your team's DuckLake to a DuckDB connection for seamless data access:
|
|
238
|
+
|
|
239
|
+
```python
|
|
240
|
+
import duckdb
|
|
241
|
+
from definite_sdk import DefiniteClient
|
|
242
|
+
|
|
243
|
+
# Initialize the client
|
|
244
|
+
client = DefiniteClient("YOUR_API_KEY")
|
|
245
|
+
|
|
246
|
+
# Connect to DuckDB and attach DuckLake
|
|
247
|
+
conn = duckdb.connect()
|
|
248
|
+
conn.execute(client.attach_ducklake())
|
|
249
|
+
|
|
250
|
+
# Now you can use DuckLake tables
|
|
251
|
+
conn.execute("CREATE SCHEMA IF NOT EXISTS lake.my_schema;")
|
|
252
|
+
conn.execute("CREATE OR REPLACE TABLE lake.my_schema.users AS SELECT * FROM df")
|
|
253
|
+
|
|
254
|
+
# Query your DuckLake data
|
|
255
|
+
result = conn.sql("SELECT * FROM lake.my_schema.users").df()
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
You can also specify a custom alias for the attached DuckLake:
|
|
259
|
+
|
|
260
|
+
```python
|
|
261
|
+
# Attach with custom alias
|
|
262
|
+
conn.execute(client.attach_ducklake(alias="warehouse"))
|
|
263
|
+
|
|
264
|
+
# Use the custom alias
|
|
265
|
+
conn.execute("SELECT * FROM warehouse.my_schema.users")
|
|
266
|
+
```
|
|
267
|
+
|
|
234
268
|
### DuckDB Integration Discovery
|
|
235
269
|
|
|
236
270
|
```python
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
definite_sdk/__init__.py,sha256=Y3GwfDOkpWt6EILoZ7PRT7nXuoVnk0zHrNOPHlkEHS4,604
|
|
2
|
-
definite_sdk/client.py,sha256=
|
|
2
|
+
definite_sdk/client.py,sha256=mpXFpJVmK3JVYsNrn7f4bzqlxMbIsS3meRu3XMiXWZ4,5075
|
|
3
3
|
definite_sdk/dlt.py,sha256=JC-S1jd6zqnpGSnvk9kYb8GQ1IPZRd1zVKTVYAbeA4w,7188
|
|
4
4
|
definite_sdk/integration.py,sha256=v15QIpWm3eAZr-cmavfA39LXTjpskEEQ2SM_TBV4E1U,3395
|
|
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=
|
|
8
|
+
definite_sdk/sql.py,sha256=nVPUuQy4zLMoeUe9bRgU1eMmIJBwlNCNXZm2tO0M8sw,4223
|
|
9
9
|
definite_sdk/store.py,sha256=7VYvROIrlWyM_ZX3LpqWWAfVLNDm0XMccMLv6qi9id8,5575
|
|
10
|
-
definite_sdk-0.1.
|
|
11
|
-
definite_sdk-0.1.
|
|
12
|
-
definite_sdk-0.1.
|
|
13
|
-
definite_sdk-0.1.
|
|
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,,
|
|
File without changes
|
|
File without changes
|