definite-sdk 0.1.9__tar.gz → 0.1.11__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.3
2
2
  Name: definite-sdk
3
- Version: 0.1.9
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
@@ -38,6 +38,7 @@ client = DefiniteClient("YOUR_API_KEY")
38
38
  - **Integration Store**: Read-only access to integration configurations
39
39
  - **Messaging**: Send messages through various channels (Slack, and more coming soon)
40
40
  - **dlt Integration**: Run dlt pipelines with automatic state persistence to Definite
41
+ - **DuckLake Integration**: Easy attachment of your team's DuckLake to DuckDB connections
41
42
  - **DuckDB Support**: Automatic discovery and connection to team's DuckDB integrations
42
43
 
43
44
  ## Basic Usage
@@ -210,6 +211,39 @@ pipeline.run(orders())
210
211
  last_cursor = pipeline.get_state("orders")
211
212
  ```
212
213
 
214
+ ### DuckLake Integration
215
+
216
+ Attach your team's DuckLake to a DuckDB connection for seamless data access:
217
+
218
+ ```python
219
+ import duckdb
220
+ from definite_sdk import DefiniteClient
221
+
222
+ # Initialize the client
223
+ client = DefiniteClient("YOUR_API_KEY")
224
+
225
+ # Connect to DuckDB and attach DuckLake
226
+ conn = duckdb.connect()
227
+ conn.execute(client.attach_ducklake())
228
+
229
+ # Now you can use DuckLake tables
230
+ conn.execute("CREATE SCHEMA IF NOT EXISTS lake.my_schema;")
231
+ conn.execute("CREATE OR REPLACE TABLE lake.my_schema.users AS SELECT * FROM df")
232
+
233
+ # Query your DuckLake data
234
+ result = conn.sql("SELECT * FROM lake.my_schema.users").df()
235
+ ```
236
+
237
+ You can also specify a custom alias for the attached DuckLake:
238
+
239
+ ```python
240
+ # Attach with custom alias
241
+ conn.execute(client.attach_ducklake(alias="warehouse"))
242
+
243
+ # Use the custom alias
244
+ conn.execute("SELECT * FROM warehouse.my_schema.users")
245
+ ```
246
+
213
247
  ### DuckDB Integration Discovery
214
248
 
215
249
  ```python
@@ -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."""
@@ -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
  [tool.poetry]
2
2
  name = "definite-sdk"
3
- version = "0.1.9"
3
+ version = "0.1.11"
4
4
  description = "Definite SDK for Python"
5
5
  authors = ["Definite <hello@definite.app>"]
6
6
  license = "MIT"
File without changes