ingestr 0.14.1__py3-none-any.whl → 0.14.3__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.

Potentially problematic release.


This version of ingestr might be problematic. Click here for more details.

ingestr/src/buildinfo.py CHANGED
@@ -1 +1 @@
1
- version = "v0.14.1"
1
+ version = "v0.14.3"
@@ -813,30 +813,7 @@ class ElasticsearchDestination:
813
813
 
814
814
  class MongoDBDestination:
815
815
  def dlt_dest(self, uri: str, **kwargs):
816
- from urllib.parse import urlparse
817
-
818
- parsed_uri = urlparse(uri)
819
-
820
- # Extract connection details from URI
821
- host = parsed_uri.hostname or "localhost"
822
- port = parsed_uri.port or 27017
823
- username = parsed_uri.username
824
- password = parsed_uri.password
825
- database = (
826
- parsed_uri.path.lstrip("/") if parsed_uri.path.lstrip("/") else "ingestr_db"
827
- )
828
-
829
- # Build connection string
830
- if username and password:
831
- connection_string = f"mongodb://{username}:{password}@{host}:{port}"
832
- else:
833
- connection_string = f"mongodb://{host}:{port}"
834
-
835
- # Add query parameters if any
836
- if parsed_uri.query:
837
- connection_string += f"?{parsed_uri.query}"
838
-
839
- return mongodb_insert(connection_string, database)
816
+ return mongodb_insert(uri)
840
817
 
841
818
  def dlt_run_params(self, uri: str, table: str, **kwargs) -> dict:
842
819
  return {
@@ -1,6 +1,7 @@
1
1
  """Elasticsearch destination helpers"""
2
2
 
3
3
  import json
4
+ import logging
4
5
  from typing import Any, Dict, Iterator
5
6
  from urllib.parse import urlparse
6
7
 
@@ -9,6 +10,10 @@ import dlt
9
10
  from elasticsearch import Elasticsearch
10
11
  from elasticsearch.helpers import bulk
11
12
 
13
+ # Suppress Elasticsearch transport logging
14
+ logging.getLogger("elasticsearch.transport").setLevel(logging.WARNING)
15
+ logging.getLogger("elastic_transport.transport").setLevel(logging.WARNING)
16
+
12
17
 
13
18
  def process_file_items(file_path: str) -> Iterator[Dict[str, Any]]:
14
19
  """Process items from a file path (JSONL format)."""
@@ -52,15 +57,36 @@ def elasticsearch_insert(
52
57
  parsed = urlparse(connection_string)
53
58
 
54
59
  # Build Elasticsearch client configuration
55
- hosts = [
56
- {
57
- "host": parsed.hostname or "localhost",
58
- "port": parsed.port or 9200,
59
- "scheme": parsed.scheme or "http",
60
- }
61
- ]
62
-
63
- es_config: Dict[str, Any] = {"hosts": hosts}
60
+ actual_url = connection_string
61
+ secure = True # Default to HTTPS (secure by default)
62
+
63
+ if connection_string.startswith("elasticsearch://"):
64
+ actual_url = connection_string.replace("elasticsearch://", "")
65
+
66
+ # Parse to check for query parameters
67
+ temp_parsed = urlparse("http://" + actual_url)
68
+ from urllib.parse import parse_qs
69
+
70
+ query_params = parse_qs(temp_parsed.query)
71
+
72
+ # Check ?secure parameter (defaults to true)
73
+ if "secure" in query_params:
74
+ secure = query_params["secure"][0].lower() in ["true", "1", "yes"]
75
+
76
+ # Remove query params from URL for ES client
77
+ actual_url = actual_url.split("?")[0]
78
+
79
+ # Add scheme
80
+ scheme = "https" if secure else "http"
81
+ actual_url = f"{scheme}://{actual_url}"
82
+
83
+ parsed = urlparse(actual_url)
84
+
85
+ es_config: Dict[str, Any] = {
86
+ "hosts": [actual_url],
87
+ "verify_certs": secure,
88
+ "ssl_show_warn": False,
89
+ }
64
90
 
65
91
  # Add authentication if present
66
92
  if parsed.username and parsed.password:
ingestr/src/factory.py CHANGED
@@ -54,7 +54,9 @@ from ingestr.src.sources import (
54
54
  GorgiasSource,
55
55
  HubspotSource,
56
56
  InfluxDBSource,
57
+ IntercomSource,
57
58
  IsocPulseSource,
59
+ JiraSource,
58
60
  KafkaSource,
59
61
  KinesisSource,
60
62
  KlaviyoSource,
@@ -166,6 +168,8 @@ class SourceDestinationFactory:
166
168
  "fluxx": FluxxSource,
167
169
  "slack": SlackSource,
168
170
  "hubspot": HubspotSource,
171
+ "intercom": IntercomSource,
172
+ "jira": JiraSource,
169
173
  "airtable": AirtableSource,
170
174
  "klaviyo": KlaviyoSource,
171
175
  "mixpanel": MixpanelSource,
@@ -96,6 +96,15 @@ FLUXX_RESOURCES = {
96
96
  "workflow_events": {"data_type": "json", "field_type": "relation"},
97
97
  },
98
98
  },
99
+ "alert_email": {
100
+ "endpoint": "alert_email",
101
+ "fields": {
102
+ "alert_id": {"data_type": "bigint", "field_type": "column"},
103
+ "created_at": {"data_type": "timestamp", "field_type": "column"},
104
+ "id": {"data_type": "bigint", "field_type": "column"},
105
+ "updated_at": {"data_type": "timestamp", "field_type": "column"},
106
+ },
107
+ },
99
108
  "affiliate": {
100
109
  "endpoint": "affiliate",
101
110
  "fields": {
@@ -93,7 +93,6 @@ def hubspot(
93
93
  def companies(
94
94
  api_key: str = api_key,
95
95
  include_history: bool = include_history,
96
- props: Sequence[str] = DEFAULT_COMPANY_PROPS,
97
96
  include_custom_props: bool = include_custom_props,
98
97
  ) -> Iterator[TDataItems]:
99
98
  """Hubspot companies resource"""
@@ -101,7 +100,7 @@ def hubspot(
101
100
  "company",
102
101
  api_key,
103
102
  include_history=include_history,
104
- props=props,
103
+ props=DEFAULT_COMPANY_PROPS,
105
104
  include_custom_props=include_custom_props,
106
105
  )
107
106
 
@@ -109,7 +108,6 @@ def hubspot(
109
108
  def contacts(
110
109
  api_key: str = api_key,
111
110
  include_history: bool = include_history,
112
- props: Sequence[str] = DEFAULT_CONTACT_PROPS,
113
111
  include_custom_props: bool = include_custom_props,
114
112
  ) -> Iterator[TDataItems]:
115
113
  """Hubspot contacts resource"""
@@ -117,7 +115,7 @@ def hubspot(
117
115
  "contact",
118
116
  api_key,
119
117
  include_history,
120
- props,
118
+ DEFAULT_CONTACT_PROPS,
121
119
  include_custom_props,
122
120
  )
123
121
 
@@ -125,7 +123,6 @@ def hubspot(
125
123
  def deals(
126
124
  api_key: str = api_key,
127
125
  include_history: bool = include_history,
128
- props: Sequence[str] = DEFAULT_DEAL_PROPS,
129
126
  include_custom_props: bool = include_custom_props,
130
127
  ) -> Iterator[TDataItems]:
131
128
  """Hubspot deals resource"""
@@ -133,7 +130,7 @@ def hubspot(
133
130
  "deal",
134
131
  api_key,
135
132
  include_history,
136
- props,
133
+ DEFAULT_DEAL_PROPS,
137
134
  include_custom_props,
138
135
  )
139
136
 
@@ -141,7 +138,6 @@ def hubspot(
141
138
  def tickets(
142
139
  api_key: str = api_key,
143
140
  include_history: bool = include_history,
144
- props: Sequence[str] = DEFAULT_TICKET_PROPS,
145
141
  include_custom_props: bool = include_custom_props,
146
142
  ) -> Iterator[TDataItems]:
147
143
  """Hubspot tickets resource"""
@@ -149,7 +145,7 @@ def hubspot(
149
145
  "ticket",
150
146
  api_key,
151
147
  include_history,
152
- props,
148
+ DEFAULT_TICKET_PROPS,
153
149
  include_custom_props,
154
150
  )
155
151
 
@@ -157,7 +153,6 @@ def hubspot(
157
153
  def products(
158
154
  api_key: str = api_key,
159
155
  include_history: bool = include_history,
160
- props: Sequence[str] = DEFAULT_PRODUCT_PROPS,
161
156
  include_custom_props: bool = include_custom_props,
162
157
  ) -> Iterator[TDataItems]:
163
158
  """Hubspot products resource"""
@@ -165,7 +160,7 @@ def hubspot(
165
160
  "product",
166
161
  api_key,
167
162
  include_history,
168
- props,
163
+ DEFAULT_PRODUCT_PROPS,
169
164
  include_custom_props,
170
165
  )
171
166
 
@@ -180,7 +175,6 @@ def hubspot(
180
175
  def quotes(
181
176
  api_key: str = api_key,
182
177
  include_history: bool = include_history,
183
- props: Sequence[str] = DEFAULT_QUOTE_PROPS,
184
178
  include_custom_props: bool = include_custom_props,
185
179
  ) -> Iterator[TDataItems]:
186
180
  """Hubspot quotes resource"""
@@ -188,7 +182,7 @@ def hubspot(
188
182
  "quote",
189
183
  api_key,
190
184
  include_history,
191
- props,
185
+ DEFAULT_QUOTE_PROPS,
192
186
  include_custom_props,
193
187
  )
194
188
 
@@ -0,0 +1,142 @@
1
+ """
2
+ Intercom source implementation for data ingestion.
3
+
4
+ This module provides DLT sources for retrieving data from Intercom API endpoints
5
+ including contacts, companies, conversations, tickets, and more.
6
+ """
7
+
8
+ from typing import Optional, Sequence
9
+
10
+ import dlt
11
+ from dlt.common.time import ensure_pendulum_datetime
12
+ from dlt.common.typing import TAnyDateTime
13
+ from dlt.sources import DltResource, DltSource
14
+
15
+ from .helpers import (
16
+ IntercomAPIClient,
17
+ IntercomCredentialsAccessToken,
18
+ TIntercomCredentials,
19
+ convert_datetime_to_timestamp,
20
+ create_resource_from_config,
21
+ transform_company,
22
+ transform_contact,
23
+ transform_conversation,
24
+ )
25
+ from .helpers import (
26
+ IntercomCredentialsOAuth as IntercomCredentialsOAuth,
27
+ )
28
+ from .settings import (
29
+ DEFAULT_START_DATE,
30
+ RESOURCE_CONFIGS,
31
+ )
32
+
33
+
34
+ @dlt.source(name="intercom", max_table_nesting=0)
35
+ def intercom_source(
36
+ credentials: TIntercomCredentials = dlt.secrets.value,
37
+ start_date: Optional[TAnyDateTime] = DEFAULT_START_DATE,
38
+ end_date: Optional[TAnyDateTime] = None,
39
+ ) -> Sequence[DltResource]:
40
+ """
41
+ A DLT source that retrieves data from Intercom API.
42
+
43
+ This source provides access to various Intercom resources including contacts,
44
+ companies, conversations, tickets, and more. It supports incremental loading
45
+ for resources that track updated timestamps.
46
+
47
+ Args:
48
+ credentials: Intercom API credentials (AccessToken or OAuth).
49
+ Defaults to dlt.secrets.value.
50
+ start_date: The start date for incremental loading.
51
+ Defaults to January 1, 2020.
52
+ end_date: Optional end date for incremental loading.
53
+ If not provided, loads all data from start_date to present.
54
+
55
+ Returns:
56
+ Sequence of DLT resources for different Intercom endpoints.
57
+
58
+ Example:
59
+ >>> source = intercom_source(
60
+ ... credentials=IntercomCredentialsAccessToken(
61
+ ... access_token="your_token",
62
+ ... region="us"
63
+ ... ),
64
+ ... start_date=datetime(2024, 1, 1)
65
+ ... )
66
+ """
67
+ # Initialize API client
68
+ api_client = IntercomAPIClient(credentials)
69
+
70
+ # Convert dates to pendulum and then to unix timestamps for Intercom API
71
+ start_date_obj = ensure_pendulum_datetime(start_date) if start_date else None
72
+ end_date_obj = ensure_pendulum_datetime(end_date) if end_date else None
73
+
74
+ # Convert to unix timestamps for API compatibility
75
+ # Use default start date if none provided
76
+ if not start_date_obj:
77
+ from .settings import DEFAULT_START_DATE
78
+
79
+ start_date_obj = ensure_pendulum_datetime(DEFAULT_START_DATE)
80
+
81
+ start_timestamp = convert_datetime_to_timestamp(start_date_obj)
82
+ end_timestamp = (
83
+ convert_datetime_to_timestamp(end_date_obj) if end_date_obj else None
84
+ )
85
+
86
+ # Transform function mapping
87
+ transform_functions = {
88
+ "transform_contact": transform_contact,
89
+ "transform_company": transform_company,
90
+ "transform_conversation": transform_conversation,
91
+ }
92
+
93
+ # Generate all resources from configuration
94
+ resources = []
95
+ for resource_name, config in RESOURCE_CONFIGS.items():
96
+ resource_func = create_resource_from_config(
97
+ resource_name,
98
+ config,
99
+ api_client,
100
+ start_timestamp,
101
+ end_timestamp,
102
+ transform_functions,
103
+ )
104
+
105
+ # Call the resource function to get the actual resource
106
+ resources.append(resource_func())
107
+
108
+ return resources
109
+
110
+
111
+ def intercom(
112
+ api_key: str,
113
+ region: str = "us",
114
+ start_date: Optional[TAnyDateTime] = DEFAULT_START_DATE,
115
+ end_date: Optional[TAnyDateTime] = None,
116
+ ) -> DltSource:
117
+ """
118
+ Convenience function to create Intercom source with access token.
119
+
120
+ Args:
121
+ api_key: Intercom API access token.
122
+ region: Data region (us, eu, or au). Defaults to "us".
123
+ start_date: Start date for incremental loading.
124
+ end_date: Optional end date for incremental loading.
125
+
126
+ Returns:
127
+ Sequence of DLT resources.
128
+
129
+ Example:
130
+ >>> source = intercom(
131
+ ... api_key="your_access_token",
132
+ ... region="us",
133
+ ... start_date=datetime(2024, 1, 1)
134
+ ... )
135
+ """
136
+ credentials = IntercomCredentialsAccessToken(access_token=api_key, region=region)
137
+
138
+ return intercom_source(
139
+ credentials=credentials,
140
+ start_date=start_date,
141
+ end_date=end_date,
142
+ )