definite-sdk 0.1.8__py3-none-any.whl → 0.1.9__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/__init__.py CHANGED
@@ -6,14 +6,16 @@ A Python library for interacting with the Definite API and tools.
6
6
 
7
7
  from definite_sdk.client import DefiniteClient
8
8
  from definite_sdk.integration import DefiniteIntegrationStore
9
+ from definite_sdk.message import DefiniteMessageClient
9
10
  from definite_sdk.secret import DefiniteSecretStore
10
11
  from definite_sdk.sql import DefiniteSqlClient
11
12
  from definite_sdk.store import DefiniteKVStore
12
13
 
13
- __version__ = "0.1.8"
14
+ __version__ = "0.1.9"
14
15
  __all__ = [
15
16
  "DefiniteClient",
16
17
  "DefiniteIntegrationStore",
18
+ "DefiniteMessageClient",
17
19
  "DefiniteSecretStore",
18
20
  "DefiniteSqlClient",
19
21
  "DefiniteKVStore",
definite_sdk/client.py CHANGED
@@ -2,6 +2,7 @@ import os
2
2
  from typing import Optional
3
3
 
4
4
  from definite_sdk.integration import DefiniteIntegrationStore
5
+ from definite_sdk.message import DefiniteMessageClient
5
6
  from definite_sdk.secret import DefiniteSecretStore
6
7
  from definite_sdk.sql import DefiniteSqlClient
7
8
  from definite_sdk.store import DefiniteKVStore
@@ -77,3 +78,15 @@ class DefiniteClient:
77
78
  def integration_store(self) -> DefiniteIntegrationStore:
78
79
  """Alias for get_integration_store."""
79
80
  return self.get_integration_store()
81
+
82
+ def get_message_client(self) -> DefiniteMessageClient:
83
+ """Initializes the message client for sending messages via various channels.
84
+
85
+ See DefiniteMessageClient for more how to send messages.
86
+ """
87
+
88
+ return DefiniteMessageClient(self.api_key, self.api_url)
89
+
90
+ def message_client(self) -> DefiniteMessageClient:
91
+ """Alias for get_message_client."""
92
+ return self.get_message_client()
@@ -0,0 +1,199 @@
1
+ from typing import Any, Dict, List, Optional
2
+
3
+ import requests
4
+
5
+ MESSAGE_ENDPOINT = "/v3"
6
+
7
+
8
+ class DefiniteMessageClient:
9
+ """
10
+ A message client for sending messages via various channels through the Definite API.
11
+
12
+ Initialization:
13
+ >>> client = DefiniteClient("MY_API_KEY")
14
+ >>> message_client = client.get_message_client()
15
+
16
+ Sending messages:
17
+ >>> # Send a Slack message
18
+ >>> result = message_client.send_message(
19
+ ... channel="slack",
20
+ ... integration_id="slack_integration_id",
21
+ ... to="C0920MVPWFN", # channel_id
22
+ ... content="Hello from Definite SDK!"
23
+ ... )
24
+
25
+ >>> # Send a Slack message with blocks and thread
26
+ >>> result = message_client.send_message(
27
+ ... channel="slack",
28
+ ... integration_id="slack_integration_id",
29
+ ... to="C0920MVPWFN",
30
+ ... content="Hello!",
31
+ ... blocks=[{"type": "section", "text": {"type": "mrkdwn", "text": "Hello!"}}],
32
+ ... thread_ts="1234567890.123456"
33
+ ... )
34
+ """
35
+
36
+ def __init__(self, api_key: str, api_url: str):
37
+ """
38
+ Initializes the DefiniteMessageClient.
39
+
40
+ Args:
41
+ api_key (str): The API key for authorization.
42
+ api_url (str): The base URL for the Definite API.
43
+ """
44
+ self._api_key = api_key
45
+ self._message_url = api_url + MESSAGE_ENDPOINT
46
+
47
+ def send_message(
48
+ self,
49
+ channel: str,
50
+ integration_id: str,
51
+ to: str,
52
+ content: str,
53
+ subject: Optional[str] = None,
54
+ blocks: Optional[List[Dict[str, Any]]] = None,
55
+ thread_ts: Optional[str] = None,
56
+ **kwargs: Any
57
+ ) -> Dict[str, Any]:
58
+ """
59
+ Sends a message through the specified channel.
60
+
61
+ Args:
62
+ channel (str): The messaging channel to use (e.g., "slack", "email").
63
+ integration_id (str): The ID of the integration to use.
64
+ to (str): The recipient identifier (channel_id for Slack, email address for email).
65
+ content (str): The message content (text for Slack, body for email).
66
+ subject (Optional[str]): Subject line (used for email).
67
+ blocks (Optional[List[Dict[str, Any]]]): Slack Block Kit blocks for formatting.
68
+ thread_ts (Optional[str]): Slack thread timestamp to reply to.
69
+ **kwargs: Additional channel-specific parameters.
70
+
71
+ Returns:
72
+ Dict[str, Any]: The response from the API.
73
+
74
+ Raises:
75
+ requests.HTTPError: If the API request fails.
76
+ ValueError: If the channel is not supported.
77
+
78
+ Example:
79
+ >>> # Slack message
80
+ >>> result = message_client.send_message(
81
+ ... channel="slack",
82
+ ... integration_id="slack_123",
83
+ ... to="C0920MVPWFN",
84
+ ... content="Hello team!"
85
+ ... )
86
+
87
+ >>> # Slack message with blocks
88
+ >>> result = message_client.send_message(
89
+ ... channel="slack",
90
+ ... integration_id="slack_123",
91
+ ... to="C0920MVPWFN",
92
+ ... content="Fallback text",
93
+ ... blocks=[{
94
+ ... "type": "section",
95
+ ... "text": {"type": "mrkdwn", "text": "*Important Update*"}
96
+ ... }]
97
+ ... )
98
+ """
99
+ channel_lower = channel.lower()
100
+
101
+ if channel_lower == "slack":
102
+ return self._send_slack_message(
103
+ integration_id=integration_id,
104
+ channel_id=to,
105
+ text=content,
106
+ blocks=blocks,
107
+ thread_ts=thread_ts,
108
+ **kwargs
109
+ )
110
+ else:
111
+ raise ValueError(f"Unsupported channel: {channel}")
112
+
113
+ def _send_slack_message(
114
+ self,
115
+ integration_id: str,
116
+ channel_id: str,
117
+ text: str,
118
+ blocks: Optional[List[Dict[str, Any]]] = None,
119
+ thread_ts: Optional[str] = None,
120
+ **kwargs: Any
121
+ ) -> Dict[str, Any]:
122
+ """
123
+ Internal method to send a Slack message.
124
+
125
+ Args:
126
+ integration_id (str): The Slack integration ID.
127
+ channel_id (str): The Slack channel ID.
128
+ text (str): The message text.
129
+ blocks (Optional[List[Dict[str, Any]]]): Slack blocks for formatting.
130
+ thread_ts (Optional[str]): Thread timestamp for replies.
131
+ **kwargs: Additional Slack-specific parameters.
132
+
133
+ Returns:
134
+ Dict[str, Any]: The API response.
135
+ """
136
+ url = f"{self._message_url}/slack/message"
137
+
138
+ payload = {
139
+ "integration_id": integration_id,
140
+ "channel_id": channel_id,
141
+ "text": text
142
+ }
143
+
144
+ if blocks:
145
+ payload["blocks"] = blocks
146
+ if thread_ts:
147
+ payload["thread_ts"] = thread_ts
148
+
149
+ # Add any additional kwargs to the payload
150
+ payload.update(kwargs)
151
+
152
+ response = requests.post(
153
+ url,
154
+ json=payload,
155
+ headers={"Authorization": "Bearer " + self._api_key},
156
+ )
157
+ response.raise_for_status()
158
+ return response.json()
159
+
160
+ def send_slack_message(
161
+ self,
162
+ integration_id: str,
163
+ channel_id: str,
164
+ text: str,
165
+ blocks: Optional[List[Dict[str, Any]]] = None,
166
+ thread_ts: Optional[str] = None,
167
+ **kwargs: Any
168
+ ) -> Dict[str, Any]:
169
+ """
170
+ Convenience method to send a Slack message directly.
171
+
172
+ Args:
173
+ integration_id (str): The Slack integration ID.
174
+ channel_id (str): The Slack channel ID.
175
+ text (str): The message text.
176
+ blocks (Optional[List[Dict[str, Any]]]): Slack blocks for formatting.
177
+ thread_ts (Optional[str]): Thread timestamp for replies.
178
+ **kwargs: Additional Slack-specific parameters.
179
+
180
+ Returns:
181
+ Dict[str, Any]: The API response.
182
+
183
+ Example:
184
+ >>> result = message_client.send_slack_message(
185
+ ... integration_id="slack_123",
186
+ ... channel_id="C0920MVPWFN",
187
+ ... text="Hello from Definite SDK! 👋"
188
+ ... )
189
+ >>> print(f"Message sent! Timestamp: {result['ts']}")
190
+ """
191
+ return self.send_message(
192
+ channel="slack",
193
+ integration_id=integration_id,
194
+ to=channel_id,
195
+ content=text,
196
+ blocks=blocks,
197
+ thread_ts=thread_ts,
198
+ **kwargs
199
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: definite-sdk
3
- Version: 0.1.8
3
+ Version: 0.1.9
4
4
  Summary: Definite SDK for Python
5
5
  License: MIT
6
6
  Author: Definite
@@ -21,7 +21,7 @@ Description-Content-Type: text/markdown
21
21
 
22
22
  # Definite SDK
23
23
 
24
- A Python client for interacting with the Definite API, providing a convenient interface for key-value store operations, SQL query execution, secrets management, and DLT (Data Load Tool) integration with state persistence.
24
+ A Python client for interacting with the Definite API, providing a convenient interface for key-value store operations, SQL query execution, secrets management, messaging capabilities, and DLT (Data Load Tool) integration with state persistence.
25
25
 
26
26
  ## Installation
27
27
 
@@ -57,6 +57,7 @@ client = DefiniteClient("YOUR_API_KEY")
57
57
  - **Cube Query Execution**: Execute Cube queries for advanced analytics and data modeling
58
58
  - **Secret Management**: Secure storage and retrieval of application secrets
59
59
  - **Integration Store**: Read-only access to integration configurations
60
+ - **Messaging**: Send messages through various channels (Slack, and more coming soon)
60
61
  - **dlt Integration**: Run dlt pipelines with automatic state persistence to Definite
61
62
  - **DuckDB Support**: Automatic discovery and connection to team's DuckDB integrations
62
63
 
@@ -167,6 +168,49 @@ integrations = list(integration_store.list_integrations())
167
168
  integration = integration_store.get_integration("my_integration")
168
169
  ```
169
170
 
171
+ ### 💬 Messaging
172
+
173
+ Send messages through various channels using the messaging client.
174
+
175
+ ```python
176
+ # Initialize the message client
177
+ message_client = client.get_message_client()
178
+ # Or use the alias method
179
+ message_client = client.message_client()
180
+
181
+ # Send a Slack message using the unified interface
182
+ result = message_client.send_message(
183
+ channel="slack",
184
+ integration_id="your_slack_integration_id",
185
+ to="C0920MVPWFN", # Slack channel ID
186
+ content="Hello from Definite SDK! 👋"
187
+ )
188
+
189
+ # Send a Slack message with blocks and threading
190
+ result = message_client.send_message(
191
+ channel="slack",
192
+ integration_id="your_slack_integration_id",
193
+ to="C0920MVPWFN",
194
+ content="Fallback text",
195
+ blocks=[{
196
+ "type": "section",
197
+ "text": {"type": "mrkdwn", "text": "*Important Update*"}
198
+ }],
199
+ thread_ts="1234567890.123456" # Reply in thread
200
+ )
201
+
202
+ # Or use the convenience method for Slack
203
+ result = message_client.send_slack_message(
204
+ integration_id="your_slack_integration_id",
205
+ channel_id="C0920MVPWFN",
206
+ text="Quick message using the convenience method!",
207
+ blocks=[{
208
+ "type": "section",
209
+ "text": {"type": "mrkdwn", "text": "Message with *rich* _formatting_"}
210
+ }]
211
+ )
212
+ ```
213
+
170
214
  ### dlt Integration
171
215
 
172
216
  ```python
@@ -1,12 +1,13 @@
1
- definite_sdk/__init__.py,sha256=0XR4YMDG50jLcGpaZvU834L4wg9swm9hxAzV858ccDE,520
2
- definite_sdk/client.py,sha256=Uc3hYMeS8icHBW7m6BQrWXUiW4PbOOu_bJXXca6y3l0,2714
1
+ definite_sdk/__init__.py,sha256=Y3GwfDOkpWt6EILoZ7PRT7nXuoVnk0zHrNOPHlkEHS4,604
2
+ definite_sdk/client.py,sha256=2wRrFFwMMeGfP5riaEGhCLk1OiyBsJj_uMqFb3hIooY,3199
3
3
  definite_sdk/dlt.py,sha256=JC-S1jd6zqnpGSnvk9kYb8GQ1IPZRd1zVKTVYAbeA4w,7188
4
4
  definite_sdk/integration.py,sha256=v15QIpWm3eAZr-cmavfA39LXTjpskEEQ2SM_TBV4E1U,3395
5
+ definite_sdk/message.py,sha256=I3qx2v9gIcC9NZyr5zEp_Seft8clRoER4WeUbAaDiFc,6549
5
6
  definite_sdk/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
7
  definite_sdk/secret.py,sha256=3wvEnTZ946hOxJBdB29dxvppwJ0x-TJV_LxRcXGqtis,2503
7
8
  definite_sdk/sql.py,sha256=K5cPXM7B60Fzd8CyI-B4rXwK7hLpLT1Z8XZSZJjSogQ,3878
8
9
  definite_sdk/store.py,sha256=7VYvROIrlWyM_ZX3LpqWWAfVLNDm0XMccMLv6qi9id8,5575
9
- definite_sdk-0.1.8.dist-info/LICENSE,sha256=jMd7PtwNWiMoGIDgFutC1v4taO69W9SRZLKe9o470Vk,1064
10
- definite_sdk-0.1.8.dist-info/METADATA,sha256=P1BJsi8QwDzRWjXQGT-esrwWyzmunbQLoFNIip5aw4Y,6865
11
- definite_sdk-0.1.8.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
12
- definite_sdk-0.1.8.dist-info/RECORD,,
10
+ definite_sdk-0.1.9.dist-info/LICENSE,sha256=jMd7PtwNWiMoGIDgFutC1v4taO69W9SRZLKe9o470Vk,1064
11
+ definite_sdk-0.1.9.dist-info/METADATA,sha256=jZfdfG0EFt7kfN6HpbSCnAzhZHBrEy7SV7WKH-K0LVU,8196
12
+ definite_sdk-0.1.9.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
13
+ definite_sdk-0.1.9.dist-info/RECORD,,