airbyte-agent-klaviyo 0.1.0__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 (57) hide show
  1. airbyte_agent_klaviyo/__init__.py +225 -0
  2. airbyte_agent_klaviyo/_vendored/__init__.py +1 -0
  3. airbyte_agent_klaviyo/_vendored/connector_sdk/__init__.py +82 -0
  4. airbyte_agent_klaviyo/_vendored/connector_sdk/auth_strategies.py +1171 -0
  5. airbyte_agent_klaviyo/_vendored/connector_sdk/auth_template.py +135 -0
  6. airbyte_agent_klaviyo/_vendored/connector_sdk/cloud_utils/__init__.py +5 -0
  7. airbyte_agent_klaviyo/_vendored/connector_sdk/cloud_utils/client.py +213 -0
  8. airbyte_agent_klaviyo/_vendored/connector_sdk/connector_model_loader.py +1120 -0
  9. airbyte_agent_klaviyo/_vendored/connector_sdk/constants.py +78 -0
  10. airbyte_agent_klaviyo/_vendored/connector_sdk/exceptions.py +23 -0
  11. airbyte_agent_klaviyo/_vendored/connector_sdk/executor/__init__.py +31 -0
  12. airbyte_agent_klaviyo/_vendored/connector_sdk/executor/hosted_executor.py +201 -0
  13. airbyte_agent_klaviyo/_vendored/connector_sdk/executor/local_executor.py +1854 -0
  14. airbyte_agent_klaviyo/_vendored/connector_sdk/executor/models.py +202 -0
  15. airbyte_agent_klaviyo/_vendored/connector_sdk/extensions.py +693 -0
  16. airbyte_agent_klaviyo/_vendored/connector_sdk/http/__init__.py +37 -0
  17. airbyte_agent_klaviyo/_vendored/connector_sdk/http/adapters/__init__.py +9 -0
  18. airbyte_agent_klaviyo/_vendored/connector_sdk/http/adapters/httpx_adapter.py +251 -0
  19. airbyte_agent_klaviyo/_vendored/connector_sdk/http/config.py +98 -0
  20. airbyte_agent_klaviyo/_vendored/connector_sdk/http/exceptions.py +119 -0
  21. airbyte_agent_klaviyo/_vendored/connector_sdk/http/protocols.py +114 -0
  22. airbyte_agent_klaviyo/_vendored/connector_sdk/http/response.py +104 -0
  23. airbyte_agent_klaviyo/_vendored/connector_sdk/http_client.py +693 -0
  24. airbyte_agent_klaviyo/_vendored/connector_sdk/introspection.py +481 -0
  25. airbyte_agent_klaviyo/_vendored/connector_sdk/logging/__init__.py +11 -0
  26. airbyte_agent_klaviyo/_vendored/connector_sdk/logging/logger.py +273 -0
  27. airbyte_agent_klaviyo/_vendored/connector_sdk/logging/types.py +93 -0
  28. airbyte_agent_klaviyo/_vendored/connector_sdk/observability/__init__.py +11 -0
  29. airbyte_agent_klaviyo/_vendored/connector_sdk/observability/config.py +179 -0
  30. airbyte_agent_klaviyo/_vendored/connector_sdk/observability/models.py +19 -0
  31. airbyte_agent_klaviyo/_vendored/connector_sdk/observability/redactor.py +81 -0
  32. airbyte_agent_klaviyo/_vendored/connector_sdk/observability/session.py +103 -0
  33. airbyte_agent_klaviyo/_vendored/connector_sdk/performance/__init__.py +6 -0
  34. airbyte_agent_klaviyo/_vendored/connector_sdk/performance/instrumentation.py +57 -0
  35. airbyte_agent_klaviyo/_vendored/connector_sdk/performance/metrics.py +93 -0
  36. airbyte_agent_klaviyo/_vendored/connector_sdk/schema/__init__.py +75 -0
  37. airbyte_agent_klaviyo/_vendored/connector_sdk/schema/base.py +201 -0
  38. airbyte_agent_klaviyo/_vendored/connector_sdk/schema/components.py +244 -0
  39. airbyte_agent_klaviyo/_vendored/connector_sdk/schema/connector.py +120 -0
  40. airbyte_agent_klaviyo/_vendored/connector_sdk/schema/extensions.py +301 -0
  41. airbyte_agent_klaviyo/_vendored/connector_sdk/schema/operations.py +156 -0
  42. airbyte_agent_klaviyo/_vendored/connector_sdk/schema/security.py +236 -0
  43. airbyte_agent_klaviyo/_vendored/connector_sdk/secrets.py +182 -0
  44. airbyte_agent_klaviyo/_vendored/connector_sdk/telemetry/__init__.py +10 -0
  45. airbyte_agent_klaviyo/_vendored/connector_sdk/telemetry/config.py +32 -0
  46. airbyte_agent_klaviyo/_vendored/connector_sdk/telemetry/events.py +59 -0
  47. airbyte_agent_klaviyo/_vendored/connector_sdk/telemetry/tracker.py +155 -0
  48. airbyte_agent_klaviyo/_vendored/connector_sdk/types.py +270 -0
  49. airbyte_agent_klaviyo/_vendored/connector_sdk/utils.py +60 -0
  50. airbyte_agent_klaviyo/_vendored/connector_sdk/validation.py +848 -0
  51. airbyte_agent_klaviyo/connector.py +1431 -0
  52. airbyte_agent_klaviyo/connector_model.py +2230 -0
  53. airbyte_agent_klaviyo/models.py +676 -0
  54. airbyte_agent_klaviyo/types.py +1319 -0
  55. airbyte_agent_klaviyo-0.1.0.dist-info/METADATA +151 -0
  56. airbyte_agent_klaviyo-0.1.0.dist-info/RECORD +57 -0
  57. airbyte_agent_klaviyo-0.1.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,155 @@
1
+ """Anonymous telemetry tracker using Segment."""
2
+
3
+ import logging
4
+ import platform
5
+ import sys
6
+ from datetime import UTC, datetime
7
+
8
+ from ..observability import ObservabilitySession
9
+
10
+ from .config import SEGMENT_WRITE_KEY, TelemetryConfig, TelemetryMode
11
+ from .events import ConnectorInitEvent, OperationEvent, SessionEndEvent
12
+
13
+ logger = logging.getLogger(__name__)
14
+
15
+
16
+ class SegmentTracker:
17
+ """Anonymous telemetry tracker using Segment."""
18
+
19
+ def __init__(
20
+ self,
21
+ session: ObservabilitySession,
22
+ mode: TelemetryMode | None = None,
23
+ ):
24
+ self.session = session
25
+ self.mode = mode or TelemetryConfig.get_mode()
26
+ self.success_count = 0
27
+ self.failure_count = 0
28
+ self.enabled = TelemetryConfig.is_enabled()
29
+ self._analytics = None
30
+
31
+ if self.enabled:
32
+ try:
33
+ # NOTE: Import here intentionally - segment is an optional dependency.
34
+ # This allows the SDK to work without telemetry if segment is not installed.
35
+ import segment.analytics as analytics
36
+
37
+ analytics.write_key = SEGMENT_WRITE_KEY
38
+ self._analytics = analytics
39
+ self._log_startup_message()
40
+ except ImportError:
41
+ logger.warning("Telemetry disabled: segment-analytics-python not installed")
42
+ self.enabled = False
43
+
44
+ def _log_startup_message(self):
45
+ """Log message when telemetry is enabled."""
46
+ logger.info(f"Anonymous telemetry enabled (mode: {self.mode.value})")
47
+ logger.info("To opt-out: export AIRBYTE_TELEMETRY_MODE=disabled")
48
+
49
+ def track_connector_init(
50
+ self,
51
+ connector_version: str | None = None,
52
+ ) -> None:
53
+ """Track connector initialization."""
54
+ if not self.enabled or not self._analytics:
55
+ return
56
+
57
+ try:
58
+ event = ConnectorInitEvent(
59
+ timestamp=datetime.now(UTC),
60
+ session_id=self.session.session_id,
61
+ user_id=self.session.user_id,
62
+ execution_context=self.session.execution_context,
63
+ is_internal_user=self.session.is_internal_user,
64
+ public_ip=self.session.public_ip,
65
+ connector_name=self.session.connector_name,
66
+ connector_version=connector_version,
67
+ python_version=f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}",
68
+ os_name=platform.system(),
69
+ os_version=platform.release(),
70
+ )
71
+
72
+ self._analytics.track(
73
+ user_id=self.session.user_id,
74
+ anonymous_id=event.session_id,
75
+ event="Connector Initialized",
76
+ properties=event.to_dict(),
77
+ )
78
+ except Exception as e:
79
+ # Never fail on tracking errors
80
+ logger.error(f"Telemetry error: {e}")
81
+
82
+ def track_operation(
83
+ self,
84
+ entity: str,
85
+ action: str,
86
+ status_code: int | None,
87
+ timing_ms: float,
88
+ error_type: str | None = None,
89
+ ) -> None:
90
+ """Track API operation."""
91
+ # Always track success/failure counts (useful even when tracking is disabled)
92
+ if status_code and 200 <= status_code < 300:
93
+ self.success_count += 1
94
+ else:
95
+ self.failure_count += 1
96
+
97
+ if not self.enabled or not self._analytics:
98
+ return
99
+
100
+ try:
101
+ event = OperationEvent(
102
+ timestamp=datetime.now(UTC),
103
+ session_id=self.session.session_id,
104
+ user_id=self.session.user_id,
105
+ execution_context=self.session.execution_context,
106
+ is_internal_user=self.session.is_internal_user,
107
+ public_ip=self.session.public_ip,
108
+ connector_name=self.session.connector_name,
109
+ entity=entity,
110
+ action=action,
111
+ status_code=status_code,
112
+ timing_ms=timing_ms,
113
+ error_type=error_type,
114
+ )
115
+
116
+ self._analytics.track(
117
+ user_id=self.session.user_id,
118
+ anonymous_id=event.session_id,
119
+ event="Operation Executed",
120
+ properties=event.to_dict(),
121
+ )
122
+ except Exception as e:
123
+ logger.error(f"Telemetry error: {e}")
124
+
125
+ def track_session_end(self) -> None:
126
+ """Track session end."""
127
+ if not self.enabled or not self._analytics:
128
+ return
129
+
130
+ try:
131
+ event = SessionEndEvent(
132
+ timestamp=datetime.now(UTC),
133
+ session_id=self.session.session_id,
134
+ user_id=self.session.user_id,
135
+ execution_context=self.session.execution_context,
136
+ is_internal_user=self.session.is_internal_user,
137
+ public_ip=self.session.public_ip,
138
+ connector_name=self.session.connector_name,
139
+ duration_seconds=self.session.duration_seconds(),
140
+ operation_count=self.session.operation_count,
141
+ success_count=self.success_count,
142
+ failure_count=self.failure_count,
143
+ )
144
+
145
+ self._analytics.track(
146
+ user_id=self.session.user_id,
147
+ anonymous_id=event.session_id,
148
+ event="Session Ended",
149
+ properties=event.to_dict(),
150
+ )
151
+
152
+ # Ensure events are sent before shutdown
153
+ self._analytics.flush()
154
+ except Exception as e:
155
+ logger.error(f"Telemetry error: {e}")
@@ -0,0 +1,270 @@
1
+ """Type definitions for Airbyte SDK."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from enum import Enum
6
+ from typing import Any
7
+ from uuid import UUID
8
+
9
+ from pydantic import BaseModel, ConfigDict, Field
10
+
11
+ from .constants import OPENAPI_DEFAULT_VERSION
12
+ from .schema.components import PathOverrideConfig
13
+ from .schema.extensions import RetryConfig
14
+ from .schema.security import AirbyteAuthConfig
15
+
16
+
17
+ class Action(str, Enum):
18
+ """Supported actions for Entity operations.
19
+
20
+ Standard CRUD actions:
21
+ GET, CREATE, UPDATE, DELETE, LIST
22
+
23
+ Special actions:
24
+ API_SEARCH - Search via API endpoint
25
+ DOWNLOAD - Download file content
26
+ AUTHORIZE - OAuth authorization flow
27
+ """
28
+
29
+ GET = "get"
30
+ CREATE = "create"
31
+ UPDATE = "update"
32
+ DELETE = "delete"
33
+ LIST = "list"
34
+ API_SEARCH = "api_search"
35
+ DOWNLOAD = "download"
36
+ AUTHORIZE = "authorize"
37
+
38
+
39
+ class AuthType(str, Enum):
40
+ """Supported authentication types."""
41
+
42
+ API_KEY = "api_key"
43
+ BEARER = "bearer"
44
+ HTTP = "http"
45
+ BASIC = "basic"
46
+ OAUTH2 = "oauth2"
47
+
48
+
49
+ class ContentType(str, Enum):
50
+ """Supported content types for request bodies."""
51
+
52
+ JSON = "application/json"
53
+ FORM_URLENCODED = "application/x-www-form-urlencoded"
54
+ FORM_DATA = "multipart/form-data"
55
+
56
+
57
+ class ParameterLocation(str, Enum):
58
+ """Location of operation parameters."""
59
+
60
+ PATH = "path"
61
+ QUERY = "query"
62
+ HEADER = "header"
63
+ COOKIE = "cookie"
64
+
65
+
66
+ # All comprehensive OpenAPI 3.0 models are now in connector_sdk.schema package
67
+ # Import from connector_sdk.schema for: OpenAPIConnector, Components, Schema, Operation, etc.
68
+
69
+
70
+ class AuthOption(BaseModel):
71
+ """A single authentication option in a multi-auth connector.
72
+
73
+ Represents one security scheme from OpenAPI components.securitySchemes.
74
+ Each option defines a complete authentication method with its own type,
75
+ configuration, and user-facing credential specification.
76
+
77
+ Example:
78
+ For a connector supporting both OAuth2 and API Key auth:
79
+ - AuthOption(scheme_name="oauth", type=OAUTH2, ...)
80
+ - AuthOption(scheme_name="apikey", type=BEARER, ...)
81
+ """
82
+
83
+ scheme_name: str = Field(description="Security scheme name from OpenAPI spec (e.g., 'githubOAuth', 'githubPAT')")
84
+ type: AuthType = Field(description="Authentication type for this option")
85
+ config: dict[str, Any] = Field(
86
+ default_factory=dict,
87
+ description="Auth-specific configuration (e.g., OAuth2 refresh settings)",
88
+ )
89
+ user_config_spec: AirbyteAuthConfig | None = Field(
90
+ None,
91
+ description="User-facing credential specification from x-airbyte-auth-config",
92
+ )
93
+
94
+
95
+ class AuthConfig(BaseModel):
96
+ """Authentication configuration supporting single or multiple auth methods.
97
+
98
+ Connectors can define either:
99
+ - Single auth: One authentication method (backwards compatible)
100
+ - Multi-auth: Multiple authentication methods (user/agent selects one)
101
+
102
+ For single-auth connectors (most common):
103
+ AuthConfig(type=OAUTH2, config={...}, user_config_spec={...})
104
+
105
+ For multi-auth connectors:
106
+ AuthConfig(options=[
107
+ AuthOption(scheme_name="oauth", type=OAUTH2, ...),
108
+ AuthOption(scheme_name="apikey", type=BEARER, ...)
109
+ ])
110
+ """
111
+
112
+ # Single-auth mode (backwards compatible)
113
+ type: AuthType | None = Field(
114
+ None,
115
+ description="Authentication type (single-auth mode only)",
116
+ )
117
+ config: dict[str, Any] = Field(
118
+ default_factory=dict,
119
+ description="Auth configuration (single-auth mode only)",
120
+ )
121
+ user_config_spec: AirbyteAuthConfig | None = Field(
122
+ None,
123
+ description="User-facing config spec from x-airbyte-auth-config (single-auth mode)",
124
+ )
125
+
126
+ # Multi-auth mode
127
+ options: list[AuthOption] | None = Field(
128
+ None,
129
+ description="Multiple authentication options (multi-auth mode only)",
130
+ )
131
+
132
+ def is_multi_auth(self) -> bool:
133
+ """Check if this configuration supports multiple authentication methods.
134
+
135
+ Returns:
136
+ True if multiple auth options are available, False for single-auth
137
+ """
138
+ return self.options is not None and len(self.options) > 0
139
+
140
+ def get_single_option(self) -> AuthOption:
141
+ """Get single auth option (for backwards compatibility).
142
+
143
+ Converts single-auth config to AuthOption format for uniform handling.
144
+
145
+ Returns:
146
+ AuthOption containing the single auth configuration
147
+
148
+ Raises:
149
+ ValueError: If this is a multi-auth config or invalid
150
+ """
151
+ if self.is_multi_auth():
152
+ raise ValueError("Cannot call get_single_option() on multi-auth config. Use options list instead.")
153
+
154
+ if self.type is None:
155
+ raise ValueError("Invalid AuthConfig: neither single-auth nor multi-auth")
156
+
157
+ return AuthOption(
158
+ scheme_name="default",
159
+ type=self.type,
160
+ config=self.config,
161
+ user_config_spec=self.user_config_spec,
162
+ )
163
+
164
+
165
+ # Executor types (used by executor.py)
166
+ class EndpointDefinition(BaseModel):
167
+ """Definition of an API endpoint."""
168
+
169
+ method: str # GET, POST, PUT, DELETE, etc.
170
+ path: str # e.g., /v1/customers/{id} (OpenAPI path)
171
+ path_override: PathOverrideConfig | None = Field(
172
+ None,
173
+ description=("Path override config from x-airbyte-path-override. When set, overrides the path for actual HTTP requests."),
174
+ )
175
+ action: Action | None = None # Semantic action (get, list, create, update, delete)
176
+ description: str | None = None
177
+ body_fields: list[str] = Field(default_factory=list) # For POST/PUT
178
+ query_params: list[str] = Field(default_factory=list) # For GET
179
+ query_params_schema: dict[str, dict[str, Any]] = Field(
180
+ default_factory=dict,
181
+ description="Schema for query params including defaults: {name: {type, default, required}}",
182
+ )
183
+ deep_object_params: list[str] = Field(
184
+ default_factory=list,
185
+ description="Query parameters using deepObject style (e.g., filter[key]=value)",
186
+ ) # For GET with deepObject query params
187
+ path_params: list[str] = Field(default_factory=list) # Extracted from path
188
+ path_params_schema: dict[str, dict[str, Any]] = Field(
189
+ default_factory=dict,
190
+ description="Schema for path params including defaults: {name: {type, default, required}}",
191
+ )
192
+ header_params: list[str] = Field(default_factory=list) # Header parameters from OpenAPI
193
+ header_params_schema: dict[str, dict[str, Any]] = Field(
194
+ default_factory=dict,
195
+ description="Schema for header params including defaults: {name: {type, default, required}}",
196
+ )
197
+ request_body_defaults: dict[str, Any] = Field(
198
+ default_factory=dict,
199
+ description="Default values for request body fields from OpenAPI schema",
200
+ )
201
+ content_type: ContentType = ContentType.JSON
202
+ request_schema: dict[str, Any] | None = None
203
+ response_schema: dict[str, Any] | None = None
204
+
205
+ # GraphQL support (Airbyte extension)
206
+ graphql_body: dict[str, Any] | None = Field(
207
+ None,
208
+ description="GraphQL body configuration from x-airbyte-body-type extension",
209
+ )
210
+
211
+ # Record extractor support (Airbyte extension)
212
+ record_extractor: str | None = Field(
213
+ None,
214
+ description="JSONPath expression to extract records from response envelopes",
215
+ )
216
+
217
+ # Metadata extractor support (Airbyte extension)
218
+ meta_extractor: dict[str, str] | None = Field(
219
+ None,
220
+ description="Dictionary mapping field names to JSONPath expressions for extracting metadata from response envelopes",
221
+ )
222
+
223
+ # Download support (Airbyte extension)
224
+ file_field: str | None = Field(
225
+ None,
226
+ description="Field in metadata response containing download URL (from x-airbyte-file-url extension)",
227
+ )
228
+
229
+ # Test validation support (Airbyte extension)
230
+ untested: bool = Field(
231
+ False,
232
+ description="Mark operation as untested to skip cassette validation (from x-airbyte-untested extension)",
233
+ )
234
+
235
+ # Health check support (Airbyte extension)
236
+ preferred_for_check: bool = Field(
237
+ False,
238
+ description="Mark this list operation as preferred for health checks (from x-airbyte-preferred-for-check extension)",
239
+ )
240
+
241
+
242
+ class EntityDefinition(BaseModel):
243
+ """Definition of an API entity."""
244
+
245
+ model_config = {"populate_by_name": True}
246
+
247
+ name: str
248
+ stream_name: str | None = Field(
249
+ default=None,
250
+ description="Airbyte stream name for cache lookup (from x-airbyte-stream-name schema extension)",
251
+ )
252
+ actions: list[Action]
253
+ endpoints: dict[Action, EndpointDefinition]
254
+ entity_schema: dict[str, Any] | None = Field(default=None, alias="schema")
255
+
256
+
257
+ class ConnectorModel(BaseModel):
258
+ """Complete connector model loaded from YAML definition."""
259
+
260
+ model_config = ConfigDict(use_enum_values=True)
261
+
262
+ id: UUID
263
+ name: str
264
+ version: str = OPENAPI_DEFAULT_VERSION
265
+ base_url: str
266
+ auth: AuthConfig
267
+ entities: list[EntityDefinition]
268
+ openapi_spec: Any | None = None # Optional reference to OpenAPIConnector
269
+ retry_config: RetryConfig | None = None # Optional retry configuration
270
+ search_field_paths: dict[str, list[str]] | None = None
@@ -0,0 +1,60 @@
1
+ """Utility functions for working with connectors."""
2
+
3
+ from collections.abc import AsyncIterator
4
+ from pathlib import Path
5
+
6
+
7
+ async def save_download(
8
+ download_iterator: AsyncIterator[bytes],
9
+ path: str | Path,
10
+ *,
11
+ overwrite: bool = False,
12
+ ) -> Path:
13
+ """Save a download iterator to a file.
14
+
15
+ Args:
16
+ download_iterator: AsyncIterator[bytes] from a download operation
17
+ path: File path where content should be saved
18
+ overwrite: Whether to overwrite existing file (default: False)
19
+
20
+ Returns:
21
+ Absolute Path to the saved file
22
+
23
+ Raises:
24
+ FileExistsError: If file exists and overwrite=False
25
+ OSError: If file cannot be written
26
+
27
+ Example:
28
+ >>> from .utils import save_download
29
+ >>>
30
+ >>> # Download and save a file
31
+ >>> result = await connector.download_article_attachment(id="123")
32
+ >>> file_path = await save_download(result, "./downloads/attachment.pdf")
33
+ >>> print(f"Downloaded to {file_path}")
34
+ Downloaded to /absolute/path/to/downloads/attachment.pdf
35
+ >>>
36
+ >>> # Overwrite existing file
37
+ >>> file_path = await save_download(result, "./downloads/attachment.pdf", overwrite=True)
38
+ """
39
+ # Convert to Path object
40
+ file_path = Path(path).expanduser().resolve()
41
+
42
+ # Check if file exists
43
+ if file_path.exists() and not overwrite:
44
+ raise FileExistsError(f"File already exists: {file_path}. Use overwrite=True to replace it.")
45
+
46
+ # Create parent directories if needed
47
+ file_path.parent.mkdir(parents=True, exist_ok=True)
48
+
49
+ # Stream content to file
50
+ try:
51
+ with open(file_path, "wb") as f:
52
+ async for chunk in download_iterator:
53
+ f.write(chunk)
54
+ except Exception as e:
55
+ # Clean up partial file on error
56
+ if file_path.exists():
57
+ file_path.unlink()
58
+ raise OSError(f"Failed to write file {file_path}: {e}") from e
59
+
60
+ return file_path