omniload 0.0.0.dev0__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.
Files changed (218) hide show
  1. omniload/conftest.py +72 -0
  2. omniload/main.py +810 -0
  3. omniload/src/.gitignore +10 -0
  4. omniload/src/adjust/__init__.py +108 -0
  5. omniload/src/adjust/adjust_helpers.py +122 -0
  6. omniload/src/airtable/__init__.py +84 -0
  7. omniload/src/allium/__init__.py +128 -0
  8. omniload/src/anthropic/__init__.py +277 -0
  9. omniload/src/anthropic/helpers.py +525 -0
  10. omniload/src/applovin/__init__.py +316 -0
  11. omniload/src/applovin_max/__init__.py +117 -0
  12. omniload/src/appsflyer/__init__.py +325 -0
  13. omniload/src/appsflyer/client.py +110 -0
  14. omniload/src/appstore/__init__.py +142 -0
  15. omniload/src/appstore/client.py +126 -0
  16. omniload/src/appstore/errors.py +15 -0
  17. omniload/src/appstore/models.py +117 -0
  18. omniload/src/appstore/resources.py +179 -0
  19. omniload/src/arrow/__init__.py +81 -0
  20. omniload/src/asana_source/__init__.py +281 -0
  21. omniload/src/asana_source/helpers.py +30 -0
  22. omniload/src/asana_source/settings.py +158 -0
  23. omniload/src/attio/__init__.py +102 -0
  24. omniload/src/attio/helpers.py +65 -0
  25. omniload/src/blob.py +95 -0
  26. omniload/src/bruin/__init__.py +76 -0
  27. omniload/src/chess/__init__.py +180 -0
  28. omniload/src/chess/helpers.py +35 -0
  29. omniload/src/chess/settings.py +18 -0
  30. omniload/src/clickup/__init__.py +85 -0
  31. omniload/src/clickup/helpers.py +47 -0
  32. omniload/src/collector/spinner.py +43 -0
  33. omniload/src/couchbase_source/__init__.py +118 -0
  34. omniload/src/couchbase_source/helpers.py +135 -0
  35. omniload/src/cursor/__init__.py +83 -0
  36. omniload/src/cursor/helpers.py +188 -0
  37. omniload/src/customer_io/__init__.py +486 -0
  38. omniload/src/customer_io/helpers.py +530 -0
  39. omniload/src/destinations.py +982 -0
  40. omniload/src/docebo/__init__.py +589 -0
  41. omniload/src/docebo/client.py +435 -0
  42. omniload/src/docebo/helpers.py +97 -0
  43. omniload/src/dune/__init__.py +104 -0
  44. omniload/src/dune/helpers.py +108 -0
  45. omniload/src/dynamodb/__init__.py +86 -0
  46. omniload/src/elasticsearch/__init__.py +80 -0
  47. omniload/src/elasticsearch/helpers.py +141 -0
  48. omniload/src/errors.py +26 -0
  49. omniload/src/facebook_ads/__init__.py +403 -0
  50. omniload/src/facebook_ads/exceptions.py +19 -0
  51. omniload/src/facebook_ads/helpers.py +296 -0
  52. omniload/src/facebook_ads/settings.py +224 -0
  53. omniload/src/facebook_ads/utils.py +53 -0
  54. omniload/src/factory.py +305 -0
  55. omniload/src/filesystem/__init__.py +133 -0
  56. omniload/src/filesystem/helpers.py +114 -0
  57. omniload/src/filesystem/readers.py +187 -0
  58. omniload/src/filters.py +62 -0
  59. omniload/src/fireflies/__init__.py +151 -0
  60. omniload/src/fireflies/helpers.py +753 -0
  61. omniload/src/fluxx/__init__.py +10013 -0
  62. omniload/src/fluxx/helpers.py +233 -0
  63. omniload/src/frankfurter/__init__.py +157 -0
  64. omniload/src/frankfurter/helpers.py +48 -0
  65. omniload/src/freshdesk/__init__.py +103 -0
  66. omniload/src/freshdesk/freshdesk_client.py +151 -0
  67. omniload/src/freshdesk/settings.py +23 -0
  68. omniload/src/fundraiseup/__init__.py +95 -0
  69. omniload/src/fundraiseup/client.py +81 -0
  70. omniload/src/github/__init__.py +202 -0
  71. omniload/src/github/helpers.py +207 -0
  72. omniload/src/github/queries.py +129 -0
  73. omniload/src/github/settings.py +24 -0
  74. omniload/src/google_ads/__init__.py +198 -0
  75. omniload/src/google_ads/field.py +17 -0
  76. omniload/src/google_ads/metrics.py +254 -0
  77. omniload/src/google_ads/predicates.py +37 -0
  78. omniload/src/google_ads/reports.py +411 -0
  79. omniload/src/google_ads/test_google_ads.py +184 -0
  80. omniload/src/google_analytics/__init__.py +144 -0
  81. omniload/src/google_analytics/helpers.py +312 -0
  82. omniload/src/google_sheets/README.md +95 -0
  83. omniload/src/google_sheets/__init__.py +166 -0
  84. omniload/src/google_sheets/helpers/__init__.py +15 -0
  85. omniload/src/google_sheets/helpers/api_calls.py +160 -0
  86. omniload/src/google_sheets/helpers/data_processing.py +316 -0
  87. omniload/src/gorgias/__init__.py +595 -0
  88. omniload/src/gorgias/helpers.py +166 -0
  89. omniload/src/hostaway/__init__.py +302 -0
  90. omniload/src/hostaway/client.py +288 -0
  91. omniload/src/http/__init__.py +38 -0
  92. omniload/src/http/readers.py +146 -0
  93. omniload/src/http_client.py +24 -0
  94. omniload/src/hubspot/__init__.py +800 -0
  95. omniload/src/hubspot/helpers.py +417 -0
  96. omniload/src/hubspot/settings.py +329 -0
  97. omniload/src/indeed/__init__.py +153 -0
  98. omniload/src/indeed/helpers.py +228 -0
  99. omniload/src/influxdb/__init__.py +46 -0
  100. omniload/src/influxdb/client.py +34 -0
  101. omniload/src/intercom/__init__.py +142 -0
  102. omniload/src/intercom/helpers.py +674 -0
  103. omniload/src/intercom/settings.py +279 -0
  104. omniload/src/isoc_pulse/__init__.py +159 -0
  105. omniload/src/jira_source/__init__.py +377 -0
  106. omniload/src/jira_source/helpers.py +510 -0
  107. omniload/src/jira_source/settings.py +184 -0
  108. omniload/src/kafka/__init__.py +120 -0
  109. omniload/src/kafka/helpers.py +241 -0
  110. omniload/src/kinesis/__init__.py +153 -0
  111. omniload/src/kinesis/helpers.py +96 -0
  112. omniload/src/klaviyo/__init__.py +237 -0
  113. omniload/src/klaviyo/client.py +212 -0
  114. omniload/src/klaviyo/helpers.py +19 -0
  115. omniload/src/linear/__init__.py +634 -0
  116. omniload/src/linear/helpers.py +111 -0
  117. omniload/src/linkedin_ads/__init__.py +266 -0
  118. omniload/src/linkedin_ads/dimension_time_enum.py +17 -0
  119. omniload/src/linkedin_ads/helpers.py +246 -0
  120. omniload/src/loader.py +69 -0
  121. omniload/src/mailchimp/__init__.py +126 -0
  122. omniload/src/mailchimp/helpers.py +226 -0
  123. omniload/src/mailchimp/settings.py +164 -0
  124. omniload/src/masking.py +344 -0
  125. omniload/src/mixpanel/__init__.py +62 -0
  126. omniload/src/mixpanel/client.py +104 -0
  127. omniload/src/monday/__init__.py +246 -0
  128. omniload/src/monday/helpers.py +392 -0
  129. omniload/src/monday/settings.py +325 -0
  130. omniload/src/mongodb/__init__.py +281 -0
  131. omniload/src/mongodb/helpers.py +975 -0
  132. omniload/src/notion/__init__.py +69 -0
  133. omniload/src/notion/helpers/__init__.py +14 -0
  134. omniload/src/notion/helpers/client.py +178 -0
  135. omniload/src/notion/helpers/database.py +92 -0
  136. omniload/src/notion/settings.py +17 -0
  137. omniload/src/partition.py +32 -0
  138. omniload/src/personio/__init__.py +345 -0
  139. omniload/src/personio/helpers.py +100 -0
  140. omniload/src/phantombuster/__init__.py +65 -0
  141. omniload/src/phantombuster/client.py +87 -0
  142. omniload/src/pinterest/__init__.py +82 -0
  143. omniload/src/pipedrive/__init__.py +212 -0
  144. omniload/src/pipedrive/helpers/__init__.py +37 -0
  145. omniload/src/pipedrive/helpers/custom_fields_munger.py +116 -0
  146. omniload/src/pipedrive/helpers/pages.py +129 -0
  147. omniload/src/pipedrive/settings.py +41 -0
  148. omniload/src/pipedrive/typing.py +17 -0
  149. omniload/src/plusvibeai/__init__.py +335 -0
  150. omniload/src/plusvibeai/helpers.py +544 -0
  151. omniload/src/plusvibeai/settings.py +252 -0
  152. omniload/src/primer/__init__.py +45 -0
  153. omniload/src/primer/helpers.py +79 -0
  154. omniload/src/quickbooks/__init__.py +117 -0
  155. omniload/src/reddit_ads/__init__.py +183 -0
  156. omniload/src/reddit_ads/helpers.py +232 -0
  157. omniload/src/resource.py +40 -0
  158. omniload/src/revenuecat/__init__.py +83 -0
  159. omniload/src/revenuecat/helpers.py +237 -0
  160. omniload/src/salesforce/__init__.py +170 -0
  161. omniload/src/salesforce/helpers.py +78 -0
  162. omniload/src/shopify/__init__.py +1953 -0
  163. omniload/src/shopify/exceptions.py +17 -0
  164. omniload/src/shopify/helpers.py +202 -0
  165. omniload/src/shopify/settings.py +19 -0
  166. omniload/src/slack/__init__.py +290 -0
  167. omniload/src/slack/helpers.py +218 -0
  168. omniload/src/slack/settings.py +36 -0
  169. omniload/src/smartsheets/__init__.py +82 -0
  170. omniload/src/snapchat_ads/__init__.py +455 -0
  171. omniload/src/snapchat_ads/client.py +72 -0
  172. omniload/src/snapchat_ads/helpers.py +630 -0
  173. omniload/src/snapchat_ads/settings.py +130 -0
  174. omniload/src/socrata_source/__init__.py +83 -0
  175. omniload/src/socrata_source/helpers.py +85 -0
  176. omniload/src/socrata_source/settings.py +8 -0
  177. omniload/src/solidgate/__init__.py +219 -0
  178. omniload/src/solidgate/helpers.py +154 -0
  179. omniload/src/sources.py +5408 -0
  180. omniload/src/sql_database/__init__.py +0 -0
  181. omniload/src/sql_database/callbacks.py +66 -0
  182. omniload/src/stripe_analytics/__init__.py +183 -0
  183. omniload/src/stripe_analytics/helpers.py +386 -0
  184. omniload/src/stripe_analytics/settings.py +80 -0
  185. omniload/src/table_definition.py +15 -0
  186. omniload/src/testdata/fakebqcredentials.json +14 -0
  187. omniload/src/tiktok_ads/__init__.py +150 -0
  188. omniload/src/tiktok_ads/tiktok_helpers.py +130 -0
  189. omniload/src/time.py +11 -0
  190. omniload/src/trustpilot/__init__.py +48 -0
  191. omniload/src/trustpilot/client.py +48 -0
  192. omniload/src/version.py +6 -0
  193. omniload/src/wise/__init__.py +68 -0
  194. omniload/src/wise/client.py +63 -0
  195. omniload/src/zendesk/__init__.py +480 -0
  196. omniload/src/zendesk/helpers/__init__.py +39 -0
  197. omniload/src/zendesk/helpers/api_helpers.py +119 -0
  198. omniload/src/zendesk/helpers/credentials.py +68 -0
  199. omniload/src/zendesk/helpers/talk_api.py +132 -0
  200. omniload/src/zendesk/settings.py +71 -0
  201. omniload/src/zoom/__init__.py +99 -0
  202. omniload/src/zoom/helpers.py +102 -0
  203. omniload/testdata/.gitignore +2 -0
  204. omniload/testdata/create_replace.csv +21 -0
  205. omniload/testdata/delete_insert_expected.csv +6 -0
  206. omniload/testdata/delete_insert_part1.csv +5 -0
  207. omniload/testdata/delete_insert_part2.csv +6 -0
  208. omniload/testdata/merge_expected.csv +5 -0
  209. omniload/testdata/merge_part1.csv +4 -0
  210. omniload/testdata/merge_part2.csv +5 -0
  211. omniload/tests/unit/test_smartsheets.py +133 -0
  212. omniload-0.0.0.dev0.dist-info/METADATA +439 -0
  213. omniload-0.0.0.dev0.dist-info/RECORD +218 -0
  214. omniload-0.0.0.dev0.dist-info/WHEEL +4 -0
  215. omniload-0.0.0.dev0.dist-info/entry_points.txt +2 -0
  216. omniload-0.0.0.dev0.dist-info/licenses/LICENSE.Apache-2.0 +201 -0
  217. omniload-0.0.0.dev0.dist-info/licenses/LICENSE.md +21 -0
  218. omniload-0.0.0.dev0.dist-info/licenses/NOTICE +35 -0
@@ -0,0 +1,480 @@
1
+ # Copyright 2022-2025 ScaleVector
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """
16
+ Defines all the sources and resources needed for ZendeskSupport, ZendeskChat and ZendeskTalk
17
+ """
18
+
19
+ from itertools import chain
20
+ from typing import Iterable, Iterator, Optional
21
+
22
+ import dlt
23
+ from dlt.common import pendulum
24
+ from dlt.common.time import ensure_pendulum_datetime
25
+ from dlt.common.typing import TAnyDateTime, TDataItem, TDataItems
26
+ from dlt.sources import DltResource
27
+
28
+ from .helpers.api_helpers import process_ticket, process_ticket_field
29
+ from .helpers.credentials import TZendeskCredentials, ZendeskCredentialsOAuth
30
+ from .helpers.talk_api import PaginationType, ZendeskAPIClient
31
+ from .settings import (
32
+ CUSTOM_FIELDS_STATE_KEY,
33
+ DEFAULT_START_DATE,
34
+ INCREMENTAL_TALK_ENDPOINTS,
35
+ SUPPORT_ENDPOINTS,
36
+ SUPPORT_EXTRA_ENDPOINTS,
37
+ TALK_ENDPOINTS,
38
+ )
39
+
40
+
41
+ @dlt.source(max_table_nesting=0)
42
+ def zendesk_talk(
43
+ credentials: TZendeskCredentials = dlt.secrets.value,
44
+ start_date: Optional[TAnyDateTime] = DEFAULT_START_DATE,
45
+ end_date: Optional[TAnyDateTime] = None,
46
+ ) -> Iterable[DltResource]:
47
+ """
48
+ Retrieves data from Zendesk Talk for phone calls and voicemails.
49
+
50
+ `start_date` argument can be used on its own or together with `end_date`. When both are provided
51
+ data is limited to items updated in that time range.
52
+ The range is "half-open", meaning elements equal and higher than `start_date` and elements lower than `end_date` are included.
53
+ All resources opt-in to use Airflow scheduler if run as Airflow task
54
+
55
+ Args:
56
+ credentials: The credentials for authentication. Defaults to the value in the `dlt.secrets` object.
57
+ start_date: The start time of the range for which to load. Defaults to January 1st 2000.
58
+ end_date: The end time of the range for which to load data.
59
+ If end time is not provided, the incremental loading will be enabled and after initial run, only new data will be retrieved
60
+ Yields:
61
+ DltResource: Data resources from Zendesk Talk.
62
+ """
63
+
64
+ # use the credentials to authenticate with the ZendeskClient
65
+ zendesk_client = ZendeskAPIClient(credentials)
66
+ start_date_obj = ensure_pendulum_datetime(start_date)
67
+ end_date_obj = ensure_pendulum_datetime(end_date) if end_date else None
68
+
69
+ # regular endpoints
70
+ for key, talk_endpoint, item_name, cursor_paginated in TALK_ENDPOINTS:
71
+ yield dlt.resource(
72
+ talk_resource(
73
+ zendesk_client,
74
+ key,
75
+ item_name or talk_endpoint,
76
+ PaginationType.CURSOR if cursor_paginated else PaginationType.OFFSET,
77
+ ),
78
+ name=key,
79
+ write_disposition="replace",
80
+ )
81
+
82
+ # adding incremental endpoints
83
+ for key, talk_incremental_endpoint in INCREMENTAL_TALK_ENDPOINTS.items():
84
+ yield dlt.resource(
85
+ talk_incremental_resource,
86
+ name=f"{key}_incremental",
87
+ primary_key="id",
88
+ write_disposition="merge",
89
+ )(
90
+ zendesk_client=zendesk_client,
91
+ talk_endpoint_name=key,
92
+ talk_endpoint=talk_incremental_endpoint,
93
+ updated_at=dlt.sources.incremental[str](
94
+ "updated_at",
95
+ initial_value=start_date_obj.isoformat(),
96
+ end_value=end_date_obj.isoformat() if end_date_obj else None,
97
+ allow_external_schedulers=True,
98
+ ),
99
+ )
100
+
101
+
102
+ def talk_resource(
103
+ zendesk_client: ZendeskAPIClient,
104
+ talk_endpoint_name: str,
105
+ talk_endpoint: str,
106
+ pagination_type: PaginationType,
107
+ ) -> Iterator[TDataItem]:
108
+ """
109
+ Loads data from a Zendesk Talk endpoint.
110
+
111
+ Args:
112
+ zendesk_client: An instance of ZendeskAPIClient for making API calls to Zendesk Talk.
113
+ talk_endpoint_name: The name of the talk_endpoint.
114
+ talk_endpoint: The actual URL ending of the endpoint.
115
+ pagination: Type of pagination type used by endpoint
116
+
117
+ Yields:
118
+ TDataItem: Dictionary containing the data from the endpoint.
119
+ """
120
+ # send query and process it
121
+ yield from zendesk_client.get_pages(
122
+ talk_endpoint, talk_endpoint_name, pagination_type
123
+ )
124
+
125
+
126
+ def talk_incremental_resource(
127
+ zendesk_client: ZendeskAPIClient,
128
+ talk_endpoint_name: str,
129
+ talk_endpoint: str,
130
+ updated_at: dlt.sources.incremental[str],
131
+ ) -> Iterator[TDataItem]:
132
+ """
133
+ Loads data from a Zendesk Talk endpoint with incremental loading.
134
+
135
+ Args:
136
+ zendesk_client: An instance of ZendeskAPIClient for making API calls to Zendesk Talk.
137
+ talk_endpoint_name: The name of the talk_endpoint.
138
+ talk_endpoint: The actual URL ending of the endpoint.
139
+ updated_at: Source for the last updated timestamp.
140
+
141
+ Yields:
142
+ TDataItem: Dictionary containing the data from the endpoint.
143
+ """
144
+ # send the request and process it
145
+ for page in zendesk_client.get_pages(
146
+ talk_endpoint,
147
+ talk_endpoint_name,
148
+ PaginationType.START_TIME,
149
+ params={
150
+ "start_time": ensure_pendulum_datetime(updated_at.last_value).int_timestamp
151
+ },
152
+ ):
153
+ yield page
154
+ if updated_at.end_out_of_range:
155
+ return
156
+
157
+
158
+ @dlt.source(max_table_nesting=0)
159
+ def zendesk_chat(
160
+ credentials: ZendeskCredentialsOAuth,
161
+ start_date: Optional[TAnyDateTime] = DEFAULT_START_DATE,
162
+ end_date: Optional[TAnyDateTime] = None,
163
+ ) -> Iterable[DltResource]:
164
+ """
165
+ Retrieves data from Zendesk Chat for chat interactions.
166
+
167
+ `start_date` argument can be used on its own or together with `end_date`. When both are provided
168
+ data is limited to items updated in that time range.
169
+ The range is "half-open", meaning elements equal and higher than `start_date` and elements lower than `end_date` are included.
170
+ All resources opt-in to use Airflow scheduler if run as Airflow task
171
+
172
+ Args:
173
+ credentials: The credentials for authentication. Defaults to the value in the `dlt.secrets` object.
174
+ start_date: The start time of the range for which to load. Defaults to January 1st 2000.
175
+ end_date: The end time of the range for which to load data.
176
+ If end time is not provided, the incremental loading will be enabled and after initial run, only new data will be retrieved
177
+
178
+ Yields:
179
+ DltResource: Data resources from Zendesk Chat.
180
+ """
181
+
182
+ # Authenticate
183
+ zendesk_client = ZendeskAPIClient(credentials, url_prefix="https://www.zopim.com")
184
+ start_date_obj = ensure_pendulum_datetime(start_date)
185
+ end_date_obj = ensure_pendulum_datetime(end_date) if end_date else None
186
+
187
+ yield dlt.resource(chats_table_resource, name="chats", write_disposition="merge")(
188
+ zendesk_client,
189
+ dlt.sources.incremental[str](
190
+ "update_timestamp|updated_timestamp",
191
+ initial_value=start_date_obj.isoformat(),
192
+ end_value=end_date_obj.isoformat() if end_date_obj else None,
193
+ allow_external_schedulers=True,
194
+ ),
195
+ )
196
+
197
+
198
+ def chats_table_resource(
199
+ zendesk_client: ZendeskAPIClient,
200
+ update_timestamp: dlt.sources.incremental[str],
201
+ ) -> Iterator[TDataItems]:
202
+ """
203
+ Resource for Chats
204
+
205
+ Args:
206
+ zendesk_client: The Zendesk API client instance, used to make calls to Zendesk API.
207
+ update_timestamp: Incremental source specifying the timestamp for incremental loading.
208
+
209
+ Yields:
210
+ dict: A dictionary representing each row of data.
211
+ """
212
+ chat_pages = zendesk_client.get_pages(
213
+ "/api/v2/incremental/chats",
214
+ "chats",
215
+ PaginationType.START_TIME,
216
+ params={
217
+ "start_time": ensure_pendulum_datetime(
218
+ update_timestamp.last_value
219
+ ).int_timestamp,
220
+ "fields": "chats(*)",
221
+ },
222
+ )
223
+ for page in chat_pages:
224
+ yield page
225
+
226
+ if update_timestamp.end_out_of_range:
227
+ return
228
+
229
+
230
+ @dlt.source(max_table_nesting=0)
231
+ def zendesk_support(
232
+ credentials: TZendeskCredentials,
233
+ load_all: bool = True,
234
+ pivot_ticket_fields: bool = True,
235
+ start_date: Optional[TAnyDateTime] = DEFAULT_START_DATE,
236
+ end_date: Optional[TAnyDateTime] = None,
237
+ ) -> Iterable[DltResource]:
238
+ """
239
+ Retrieves data from Zendesk Support for tickets, users, brands, organizations, and groups.
240
+
241
+ `start_date` argument can be used on its own or together with `end_date`. When both are provided
242
+ data is limited to items updated in that time range.
243
+ The range is "half-open", meaning elements equal and higher than `start_date` and elements lower than `end_date` are included.
244
+ All resources opt-in to use Airflow scheduler if run as Airflow task
245
+
246
+ Args:
247
+ credentials: The credentials for authentication. Defaults to the value in the `dlt.secrets` object.
248
+ load_all: Whether to load extra resources for the API. Defaults to True.
249
+ pivot_ticket_fields: Whether to pivot the custom fields in tickets. Defaults to True.
250
+ start_date: The start time of the range for which to load. Defaults to January 1st 2000.
251
+ end_date: The end time of the range for which to load data.
252
+ If end time is not provided, the incremental loading will be enabled and after initial run, only new data will be retrieved
253
+
254
+ Returns:
255
+ Sequence[DltResource]: Multiple dlt resources.
256
+ """
257
+
258
+ start_date_obj = ensure_pendulum_datetime(start_date)
259
+ end_date_obj = ensure_pendulum_datetime(end_date) if end_date else None
260
+
261
+ start_date_ts = start_date_obj.int_timestamp
262
+ start_date_iso_str = start_date_obj.isoformat()
263
+ end_date_ts: Optional[int] = None
264
+ end_date_iso_str: Optional[str] = None
265
+ if end_date_obj:
266
+ end_date_ts = end_date_obj.int_timestamp
267
+ end_date_iso_str = end_date_obj.isoformat()
268
+
269
+ @dlt.resource(primary_key="id", write_disposition="append")
270
+ def ticket_events(
271
+ zendesk_client: ZendeskAPIClient,
272
+ timestamp: dlt.sources.incremental[int] = dlt.sources.incremental(
273
+ "timestamp",
274
+ initial_value=start_date_ts,
275
+ end_value=end_date_ts,
276
+ allow_external_schedulers=True,
277
+ range_end="closed",
278
+ range_start="closed",
279
+ ),
280
+ ) -> Iterator[TDataItem]:
281
+ # URL For ticket events
282
+ # 'https://d3v-dlthub.zendesk.com/api/v2/incremental/ticket_events.json?start_time=946684800'
283
+ event_pages = zendesk_client.get_pages(
284
+ "/api/v2/incremental/ticket_events.json",
285
+ "ticket_events",
286
+ PaginationType.STREAM,
287
+ params={"start_time": timestamp.last_value},
288
+ )
289
+ for page in event_pages:
290
+ yield page
291
+ if timestamp.end_out_of_range:
292
+ return
293
+
294
+ @dlt.resource(
295
+ name="tickets",
296
+ primary_key="id",
297
+ write_disposition="merge",
298
+ columns={
299
+ "tags": {"data_type": "json"},
300
+ "custom_fields": {"data_type": "json"},
301
+ },
302
+ )
303
+ def ticket_table(
304
+ zendesk_client: ZendeskAPIClient,
305
+ pivot_fields: bool = True,
306
+ updated_at: dlt.sources.incremental[
307
+ pendulum.DateTime
308
+ ] = dlt.sources.incremental(
309
+ "updated_at",
310
+ initial_value=start_date_obj,
311
+ end_value=end_date_obj,
312
+ allow_external_schedulers=True,
313
+ range_end="closed",
314
+ range_start="closed",
315
+ ),
316
+ ) -> Iterator[TDataItem]:
317
+ """
318
+ Resource for tickets table. Uses DLT state to handle column renaming of custom fields to prevent changing the names of said columns.
319
+ This resource uses pagination, loading and side loading to make API calls more efficient.
320
+
321
+ Args:
322
+ zendesk_client: The Zendesk API client instance, used to make calls to Zendesk API.
323
+ pivot_fields: Indicates whether to pivot the custom fields in tickets. Defaults to True.
324
+ per_page: The number of Ticket objects to load per page. Defaults to 1000.
325
+ updated_at: Incremental source for the 'updated_at' column.
326
+ Defaults to dlt.sources.incremental("updated_at", initial_value=start_date).
327
+
328
+ Yields:
329
+ TDataItem: Dictionary containing the ticket data.
330
+ """
331
+ # grab the custom fields from dlt state if any
332
+ if pivot_fields:
333
+ load_ticket_fields_state(zendesk_client)
334
+ fields_dict = dlt.current.source_state().setdefault(CUSTOM_FIELDS_STATE_KEY, {})
335
+ # include_objects = ["users", "groups", "organisation", "brands"]
336
+ ticket_pages = zendesk_client.get_pages(
337
+ "/api/v2/incremental/tickets",
338
+ "tickets",
339
+ PaginationType.STREAM,
340
+ params={"start_time": updated_at.last_value.int_timestamp},
341
+ )
342
+ for page in ticket_pages:
343
+ yield [
344
+ process_ticket(ticket, fields_dict, pivot_custom_fields=pivot_fields)
345
+ for ticket in page
346
+ ]
347
+ # stop loading when using end_value and end is reached
348
+ if updated_at.end_out_of_range:
349
+ return
350
+
351
+ @dlt.resource(
352
+ name="ticket_metric_events", primary_key="id", write_disposition="append"
353
+ )
354
+ def ticket_metric_table(
355
+ zendesk_client: ZendeskAPIClient,
356
+ time: dlt.sources.incremental[str] = dlt.sources.incremental(
357
+ "time",
358
+ initial_value=start_date_iso_str,
359
+ end_value=end_date_iso_str,
360
+ allow_external_schedulers=True,
361
+ range_end="closed",
362
+ range_start="closed",
363
+ ),
364
+ ) -> Iterator[TDataItem]:
365
+ """
366
+ Resource for ticket metric events table. Returns all the ticket metric events from the starting date,
367
+ with the default starting date being January 1st of the current year.
368
+
369
+ Args:
370
+ zendesk_client: The Zendesk API client instance, used to make calls to Zendesk API.
371
+ time: Incremental source for the 'time' column,
372
+ indicating the starting date for retrieving ticket metric events.
373
+ Defaults to dlt.sources.incremental("time", initial_value=start_date_iso_str).
374
+
375
+ Yields:
376
+ TDataItem: Dictionary containing the ticket metric event data.
377
+ """
378
+ # "https://example.zendesk.com/api/v2/incremental/ticket_metric_events?start_time=1332034771"
379
+ metric_event_pages = zendesk_client.get_pages(
380
+ "/api/v2/incremental/ticket_metric_events",
381
+ "ticket_metric_events",
382
+ PaginationType.CURSOR,
383
+ params={
384
+ "start_time": ensure_pendulum_datetime(time.last_value).int_timestamp,
385
+ },
386
+ )
387
+ for page in metric_event_pages:
388
+ yield page
389
+
390
+ if time.end_out_of_range:
391
+ return
392
+
393
+ def ticket_fields_table(zendesk_client: ZendeskAPIClient) -> Iterator[TDataItem]:
394
+ """
395
+ Loads ticket fields data from Zendesk API.
396
+
397
+ Args:
398
+ zendesk_client: The Zendesk API client instance, used to make calls to Zendesk API.
399
+
400
+ Yields:
401
+ TDataItem: Dictionary containing the ticket fields data.
402
+ """
403
+ # get dlt state
404
+ ticket_custom_fields = dlt.current.source_state().setdefault(
405
+ CUSTOM_FIELDS_STATE_KEY, {}
406
+ )
407
+ # get all custom fields and update state if needed, otherwise just load dicts into tables
408
+ all_fields = list(
409
+ chain.from_iterable(
410
+ zendesk_client.get_pages(
411
+ "/api/v2/ticket_fields.json", "ticket_fields", PaginationType.OFFSET
412
+ )
413
+ )
414
+ )
415
+ # all_fields = zendesk_client.ticket_fields()
416
+ for field in all_fields:
417
+ yield process_ticket_field(field, ticket_custom_fields)
418
+
419
+ def load_ticket_fields_state(
420
+ zendesk_client: ZendeskAPIClient,
421
+ ) -> None:
422
+ for _ in ticket_fields_table(zendesk_client):
423
+ pass
424
+
425
+ ticket_fields_resource = dlt.resource(
426
+ name="ticket_fields", write_disposition="replace"
427
+ )(ticket_fields_table)
428
+
429
+ # Authenticate
430
+ zendesk_client = ZendeskAPIClient(credentials)
431
+
432
+ # loading base tables
433
+ resource_list = [
434
+ ticket_fields_resource(zendesk_client=zendesk_client),
435
+ ticket_events(zendesk_client=zendesk_client),
436
+ ticket_table(zendesk_client=zendesk_client, pivot_fields=pivot_ticket_fields),
437
+ ticket_metric_table(zendesk_client=zendesk_client),
438
+ ]
439
+
440
+ # other tables to be loaded
441
+ resources_to_be_loaded = list(SUPPORT_ENDPOINTS) # make a copy
442
+ if load_all:
443
+ resources_to_be_loaded.extend(SUPPORT_EXTRA_ENDPOINTS)
444
+ for resource, endpoint_url, data_key, cursor_paginated in resources_to_be_loaded:
445
+ resource_list.append(
446
+ dlt.resource(
447
+ basic_resource(
448
+ zendesk_client, endpoint_url, data_key or resource, cursor_paginated
449
+ ),
450
+ name=resource,
451
+ write_disposition="replace",
452
+ )
453
+ )
454
+ return resource_list
455
+
456
+
457
+ def basic_resource(
458
+ zendesk_client: ZendeskAPIClient,
459
+ endpoint_url: str,
460
+ data_key: str,
461
+ cursor_paginated: bool,
462
+ ) -> Iterator[TDataItem]:
463
+ """
464
+ Basic loader for most endpoints offered by Zenpy. Supports pagination. Expects to be called as a DLT Resource.
465
+
466
+ Args:
467
+ zendesk_client: The Zendesk API client instance, used to make calls to Zendesk API.
468
+ resource: The Zenpy endpoint to retrieve data from, usually directly linked to a Zendesk API endpoint.
469
+ cursor_paginated: Tells to use CURSOR pagination or OFFSET/no pagination
470
+
471
+ Yields:
472
+ TDataItem: Dictionary containing the resource data.
473
+ """
474
+
475
+ pages = zendesk_client.get_pages(
476
+ endpoint_url,
477
+ data_key,
478
+ PaginationType.CURSOR if cursor_paginated else PaginationType.OFFSET,
479
+ )
480
+ yield from pages
@@ -0,0 +1,39 @@
1
+ # Copyright 2022-2025 ScaleVector
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Zendesk source helpers"""
16
+
17
+ from typing import List, Tuple
18
+
19
+ from dlt.common import pendulum
20
+ from dlt.common.time import timedelta
21
+
22
+
23
+ def make_date_ranges(
24
+ start: pendulum.DateTime, end: pendulum.DateTime, step: timedelta
25
+ ) -> List[Tuple[pendulum.DateTime, pendulum.DateTime]]:
26
+ """Make tuples of (start, end) date ranges between the given `start` and `end` dates.
27
+ The last range in the resulting list will be capped to the value of `end` argument so it may be smaller than `step`
28
+
29
+ Example usage, create 1 week ranges between January 1st 2023 and today:
30
+ >>> make_date_ranges(pendulum.DateTime(2023, 1, 1).as_tz('UTC'), pendulum.today(), timedelta(weeks=1))
31
+ """
32
+ ranges = []
33
+ while True:
34
+ end_time = min(start + step, end)
35
+ ranges.append((start, end_time))
36
+ if end_time == end:
37
+ break
38
+ start = end_time
39
+ return ranges
@@ -0,0 +1,119 @@
1
+ # Copyright 2022-2025 ScaleVector
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from typing import Dict, Optional, TypedDict
16
+
17
+ from dlt.common import logger, pendulum
18
+ from dlt.common.time import ensure_pendulum_datetime
19
+ from dlt.common.typing import DictStrAny, DictStrStr, TDataItem
20
+
21
+
22
+ class TCustomFieldInfo(TypedDict):
23
+ title: str
24
+ options: DictStrStr
25
+
26
+
27
+ def _parse_date_or_none(value: Optional[str]) -> Optional[pendulum.DateTime]:
28
+ if not value:
29
+ return None
30
+ return ensure_pendulum_datetime(value)
31
+
32
+
33
+ def process_ticket(
34
+ ticket: DictStrAny,
35
+ custom_fields: Dict[str, TCustomFieldInfo],
36
+ pivot_custom_fields: bool = True,
37
+ ) -> DictStrAny:
38
+ """
39
+ Helper function that processes a ticket object and returns a dictionary of ticket data.
40
+
41
+ Args:
42
+ ticket: The ticket dict object returned by a Zendesk API call.
43
+ custom_fields: A dictionary containing all the custom fields available for tickets.
44
+ pivot_custom_fields: A boolean indicating whether to pivot all custom fields or not.
45
+ Defaults to True.
46
+
47
+ Returns:
48
+ DictStrAny: A dictionary containing cleaned data about a ticket.
49
+ """
50
+ # pivot custom field if indicated as such
51
+ # get custom fields
52
+ pivoted_fields = set()
53
+ for custom_field in ticket["custom_fields"]:
54
+ if pivot_custom_fields:
55
+ cus_field_id = str(custom_field["id"])
56
+ field = custom_fields.get(cus_field_id, None)
57
+ if field is None:
58
+ logger.warning(
59
+ "Custom field with ID %s does not exist in fields state. It may have been created after the pipeline run started.",
60
+ cus_field_id,
61
+ )
62
+ custom_field["ticket_id"] = ticket["id"]
63
+ continue
64
+
65
+ pivoted_fields.add(cus_field_id)
66
+ field_name = field["title"]
67
+ current_value = custom_field["value"]
68
+ options = field["options"]
69
+ # Map dropdown values to labels
70
+ if not current_value or not options:
71
+ ticket[field_name] = current_value
72
+ elif isinstance(
73
+ current_value, list
74
+ ): # Multiple choice field has a list of values
75
+ ticket[field_name] = [options.get(key, key) for key in current_value]
76
+ else:
77
+ ticket[field_name] = options.get(current_value)
78
+ else:
79
+ custom_field["ticket_id"] = ticket["id"]
80
+ # delete fields that are not needed for pivoting
81
+ if pivot_custom_fields:
82
+ ticket["custom_fields"] = [
83
+ f for f in ticket["custom_fields"] if str(f["id"]) not in pivoted_fields
84
+ ]
85
+ if not ticket["custom_fields"]:
86
+ del ticket["custom_fields"]
87
+ del ticket["fields"]
88
+ # modify dates to return datetime objects instead
89
+ ticket["updated_at"] = _parse_date_or_none(ticket["updated_at"])
90
+ ticket["created_at"] = _parse_date_or_none(ticket["created_at"])
91
+ ticket["due_at"] = _parse_date_or_none(ticket["due_at"])
92
+ return ticket
93
+
94
+
95
+ def process_ticket_field(
96
+ field: DictStrAny, custom_fields_state: Dict[str, TCustomFieldInfo]
97
+ ) -> TDataItem:
98
+ """Update custom field mapping in dlt state for the given field."""
99
+ # grab id and update state dict
100
+ # if the id is new, add a new key to indicate that this is the initial value for title
101
+ # New dropdown options are added to existing field but existing options are not changed
102
+ return_dict = field.copy()
103
+ field_id = str(field["id"])
104
+
105
+ options = field.get("custom_field_options", [])
106
+ new_options = {o["value"]: o["name"] for o in options}
107
+ existing_field = custom_fields_state.get(field_id)
108
+ if existing_field:
109
+ existing_options = existing_field["options"]
110
+ if return_options := return_dict.get("custom_field_options"):
111
+ for item in return_options:
112
+ item["name"] = existing_options.get(item["value"], item["name"])
113
+ for key, value in new_options.items():
114
+ if key not in existing_options:
115
+ existing_options[key] = value
116
+ else:
117
+ custom_fields_state[field_id] = dict(title=field["title"], options=new_options)
118
+ return_dict["initial_title"] = field["title"]
119
+ return return_dict