ttd-data 0.0.1__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 (53) hide show
  1. ttd_data/__init__.py +17 -0
  2. ttd_data/_hooks/__init__.py +5 -0
  3. ttd_data/_hooks/registration.py +13 -0
  4. ttd_data/_hooks/sdkhooks.py +76 -0
  5. ttd_data/_hooks/types.py +112 -0
  6. ttd_data/_version.py +15 -0
  7. ttd_data/advertiser.py +244 -0
  8. ttd_data/basesdk.py +380 -0
  9. ttd_data/errors/__init__.py +42 -0
  10. ttd_data/errors/advertiserdataserverresponse_error.py +43 -0
  11. ttd_data/errors/apierror.py +40 -0
  12. ttd_data/errors/dataerror.py +30 -0
  13. ttd_data/errors/no_response_error.py +17 -0
  14. ttd_data/errors/responsevalidationerror.py +27 -0
  15. ttd_data/errors/ttddataerror.py +30 -0
  16. ttd_data/httpclient.py +125 -0
  17. ttd_data/models/__init__.py +79 -0
  18. ttd_data/models/advertiserdata.py +88 -0
  19. ttd_data/models/advertiserdataitem.py +134 -0
  20. ttd_data/models/advertiserdatarequest.py +56 -0
  21. ttd_data/models/advertiserdataresponseerrorcode.py +18 -0
  22. ttd_data/models/advertiserdataserverresponse.py +54 -0
  23. ttd_data/models/advertiserdataserverresponseline.py +61 -0
  24. ttd_data/models/httpmetadata.py +23 -0
  25. ttd_data/models/ingestadvertiserdataop.py +89 -0
  26. ttd_data/py.typed +1 -0
  27. ttd_data/sdk.py +164 -0
  28. ttd_data/sdkconfiguration.py +47 -0
  29. ttd_data/types/__init__.py +21 -0
  30. ttd_data/types/basemodel.py +77 -0
  31. ttd_data/utils/__init__.py +175 -0
  32. ttd_data/utils/annotations.py +79 -0
  33. ttd_data/utils/datetimes.py +23 -0
  34. ttd_data/utils/dynamic_imports.py +54 -0
  35. ttd_data/utils/enums.py +134 -0
  36. ttd_data/utils/eventstreaming.py +280 -0
  37. ttd_data/utils/forms.py +234 -0
  38. ttd_data/utils/headers.py +136 -0
  39. ttd_data/utils/logger.py +27 -0
  40. ttd_data/utils/metadata.py +118 -0
  41. ttd_data/utils/queryparams.py +217 -0
  42. ttd_data/utils/requestbodies.py +66 -0
  43. ttd_data/utils/retries.py +271 -0
  44. ttd_data/utils/security.py +176 -0
  45. ttd_data/utils/serializers.py +229 -0
  46. ttd_data/utils/unmarshal_json_response.py +38 -0
  47. ttd_data/utils/url.py +155 -0
  48. ttd_data/utils/values.py +137 -0
  49. ttd_data-0.0.1.dist-info/METADATA +454 -0
  50. ttd_data-0.0.1.dist-info/RECORD +53 -0
  51. ttd_data-0.0.1.dist-info/WHEEL +5 -0
  52. ttd_data-0.0.1.dist-info/top_level.txt +2 -0
  53. ttd_data_python/_hooks/registration.py +13 -0
ttd_data/__init__.py ADDED
@@ -0,0 +1,17 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from ._version import (
4
+ __title__,
5
+ __version__,
6
+ __openapi_doc_version__,
7
+ __gen_version__,
8
+ __user_agent__,
9
+ )
10
+ from .sdk import *
11
+ from .sdkconfiguration import *
12
+
13
+
14
+ VERSION: str = __version__
15
+ OPENAPI_DOC_VERSION = __openapi_doc_version__
16
+ SPEAKEASY_GENERATOR_VERSION = __gen_version__
17
+ USER_AGENT = __user_agent__
@@ -0,0 +1,5 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from .sdkhooks import *
4
+ from .types import *
5
+ from .registration import *
@@ -0,0 +1,13 @@
1
+ from .types import Hooks
2
+
3
+
4
+ # This file is only ever generated once on the first generation and then is free to be modified.
5
+ # Any hooks you wish to add should be registered in the init_hooks function. Feel free to define them
6
+ # in this file or in separate files in the hooks folder.
7
+
8
+
9
+ def init_hooks(hooks: Hooks):
10
+ # pylint: disable=unused-argument
11
+ """Add hooks by calling hooks.register{sdk_init/before_request/after_success/after_error}Hook
12
+ with an instance of a hook that implements that specific Hook interface
13
+ Hooks are registered per SDK instance, and are valid for the lifetime of the SDK instance"""
@@ -0,0 +1,76 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ import httpx
4
+ from .types import (
5
+ SDKInitHook,
6
+ BeforeRequestContext,
7
+ BeforeRequestHook,
8
+ AfterSuccessContext,
9
+ AfterSuccessHook,
10
+ AfterErrorContext,
11
+ AfterErrorHook,
12
+ Hooks,
13
+ )
14
+ from .registration import init_hooks
15
+ from typing import List, Optional, Tuple
16
+ from ttd_data.sdkconfiguration import SDKConfiguration
17
+
18
+
19
+ class SDKHooks(Hooks):
20
+ def __init__(self) -> None:
21
+ self.sdk_init_hooks: List[SDKInitHook] = []
22
+ self.before_request_hooks: List[BeforeRequestHook] = []
23
+ self.after_success_hooks: List[AfterSuccessHook] = []
24
+ self.after_error_hooks: List[AfterErrorHook] = []
25
+ init_hooks(self)
26
+
27
+ def register_sdk_init_hook(self, hook: SDKInitHook) -> None:
28
+ self.sdk_init_hooks.append(hook)
29
+
30
+ def register_before_request_hook(self, hook: BeforeRequestHook) -> None:
31
+ self.before_request_hooks.append(hook)
32
+
33
+ def register_after_success_hook(self, hook: AfterSuccessHook) -> None:
34
+ self.after_success_hooks.append(hook)
35
+
36
+ def register_after_error_hook(self, hook: AfterErrorHook) -> None:
37
+ self.after_error_hooks.append(hook)
38
+
39
+ def sdk_init(self, config: SDKConfiguration) -> SDKConfiguration:
40
+ for hook in self.sdk_init_hooks:
41
+ config = hook.sdk_init(config)
42
+ return config
43
+
44
+ def before_request(
45
+ self, hook_ctx: BeforeRequestContext, request: httpx.Request
46
+ ) -> httpx.Request:
47
+ for hook in self.before_request_hooks:
48
+ out = hook.before_request(hook_ctx, request)
49
+ if isinstance(out, Exception):
50
+ raise out
51
+ request = out
52
+
53
+ return request
54
+
55
+ def after_success(
56
+ self, hook_ctx: AfterSuccessContext, response: httpx.Response
57
+ ) -> httpx.Response:
58
+ for hook in self.after_success_hooks:
59
+ out = hook.after_success(hook_ctx, response)
60
+ if isinstance(out, Exception):
61
+ raise out
62
+ response = out
63
+ return response
64
+
65
+ def after_error(
66
+ self,
67
+ hook_ctx: AfterErrorContext,
68
+ response: Optional[httpx.Response],
69
+ error: Optional[Exception],
70
+ ) -> Tuple[Optional[httpx.Response], Optional[Exception]]:
71
+ for hook in self.after_error_hooks:
72
+ result = hook.after_error(hook_ctx, response, error)
73
+ if isinstance(result, Exception):
74
+ raise result
75
+ response, error = result
76
+ return response, error
@@ -0,0 +1,112 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from abc import ABC, abstractmethod
4
+ import httpx
5
+ from ttd_data.sdkconfiguration import SDKConfiguration
6
+ from typing import Any, Callable, List, Optional, Tuple, Union
7
+
8
+
9
+ class HookContext:
10
+ config: SDKConfiguration
11
+ base_url: str
12
+ operation_id: str
13
+ oauth2_scopes: Optional[List[str]] = None
14
+ security_source: Optional[Union[Any, Callable[[], Any]]] = None
15
+
16
+ def __init__(
17
+ self,
18
+ config: SDKConfiguration,
19
+ base_url: str,
20
+ operation_id: str,
21
+ oauth2_scopes: Optional[List[str]],
22
+ security_source: Optional[Union[Any, Callable[[], Any]]],
23
+ ):
24
+ self.config = config
25
+ self.base_url = base_url
26
+ self.operation_id = operation_id
27
+ self.oauth2_scopes = oauth2_scopes
28
+ self.security_source = security_source
29
+
30
+
31
+ class BeforeRequestContext(HookContext):
32
+ def __init__(self, hook_ctx: HookContext):
33
+ super().__init__(
34
+ hook_ctx.config,
35
+ hook_ctx.base_url,
36
+ hook_ctx.operation_id,
37
+ hook_ctx.oauth2_scopes,
38
+ hook_ctx.security_source,
39
+ )
40
+
41
+
42
+ class AfterSuccessContext(HookContext):
43
+ def __init__(self, hook_ctx: HookContext):
44
+ super().__init__(
45
+ hook_ctx.config,
46
+ hook_ctx.base_url,
47
+ hook_ctx.operation_id,
48
+ hook_ctx.oauth2_scopes,
49
+ hook_ctx.security_source,
50
+ )
51
+
52
+
53
+ class AfterErrorContext(HookContext):
54
+ def __init__(self, hook_ctx: HookContext):
55
+ super().__init__(
56
+ hook_ctx.config,
57
+ hook_ctx.base_url,
58
+ hook_ctx.operation_id,
59
+ hook_ctx.oauth2_scopes,
60
+ hook_ctx.security_source,
61
+ )
62
+
63
+
64
+ class SDKInitHook(ABC):
65
+ @abstractmethod
66
+ def sdk_init(self, config: SDKConfiguration) -> SDKConfiguration:
67
+ pass
68
+
69
+
70
+ class BeforeRequestHook(ABC):
71
+ @abstractmethod
72
+ def before_request(
73
+ self, hook_ctx: BeforeRequestContext, request: httpx.Request
74
+ ) -> Union[httpx.Request, Exception]:
75
+ pass
76
+
77
+
78
+ class AfterSuccessHook(ABC):
79
+ @abstractmethod
80
+ def after_success(
81
+ self, hook_ctx: AfterSuccessContext, response: httpx.Response
82
+ ) -> Union[httpx.Response, Exception]:
83
+ pass
84
+
85
+
86
+ class AfterErrorHook(ABC):
87
+ @abstractmethod
88
+ def after_error(
89
+ self,
90
+ hook_ctx: AfterErrorContext,
91
+ response: Optional[httpx.Response],
92
+ error: Optional[Exception],
93
+ ) -> Union[Tuple[Optional[httpx.Response], Optional[Exception]], Exception]:
94
+ pass
95
+
96
+
97
+ class Hooks(ABC):
98
+ @abstractmethod
99
+ def register_sdk_init_hook(self, hook: SDKInitHook):
100
+ pass
101
+
102
+ @abstractmethod
103
+ def register_before_request_hook(self, hook: BeforeRequestHook):
104
+ pass
105
+
106
+ @abstractmethod
107
+ def register_after_success_hook(self, hook: AfterSuccessHook):
108
+ pass
109
+
110
+ @abstractmethod
111
+ def register_after_error_hook(self, hook: AfterErrorHook):
112
+ pass
ttd_data/_version.py ADDED
@@ -0,0 +1,15 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ import importlib.metadata
4
+
5
+ __title__: str = "ttd-data"
6
+ __version__: str = "0.0.1"
7
+ __openapi_doc_version__: str = "v1"
8
+ __gen_version__: str = "2.829.1"
9
+ __user_agent__: str = "speakeasy-sdk/python 0.0.1 2.829.1 v1 ttd-data"
10
+
11
+ try:
12
+ if __package__ is not None:
13
+ __version__ = importlib.metadata.version(__package__)
14
+ except importlib.metadata.PackageNotFoundError:
15
+ pass
ttd_data/advertiser.py ADDED
@@ -0,0 +1,244 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from .basesdk import BaseSDK
4
+ from ttd_data import errors, models, utils
5
+ from ttd_data._hooks import HookContext
6
+ from ttd_data.types import OptionalNullable, UNSET
7
+ from ttd_data.utils.unmarshal_json_response import unmarshal_json_response
8
+ from typing import Any, List, Mapping, Optional, Union
9
+
10
+
11
+ class Advertiser(BaseSDK):
12
+ def ingest_advertiser_data(
13
+ self,
14
+ *,
15
+ advertiser_id: str,
16
+ ttd_auth: Optional[str] = None,
17
+ ttd_signature: Optional[str] = None,
18
+ data_provider_id: OptionalNullable[str] = UNSET,
19
+ items: OptionalNullable[
20
+ Union[
21
+ List[models.AdvertiserDataItem],
22
+ List[models.AdvertiserDataItemTypedDict],
23
+ ]
24
+ ] = UNSET,
25
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
26
+ server_url: Optional[str] = None,
27
+ timeout_ms: Optional[int] = None,
28
+ http_headers: Optional[Mapping[str, str]] = None,
29
+ ) -> models.IngestAdvertiserDataResponse:
30
+ r"""Upload first-party data for the specified ID for use in audience targeting.
31
+
32
+ :param advertiser_id:
33
+ :param ttd_auth: Data API token for authentication. If not provided, TtdSignature is required.
34
+ :param ttd_signature: Legacy signature-based authentication. Required if TTD-Auth is not provided.
35
+ :param data_provider_id:
36
+ :param items:
37
+ :param retries: Override the default retry configuration for this method
38
+ :param server_url: Override the default server URL for this method
39
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
40
+ :param http_headers: Additional headers to set or replace on requests.
41
+ """
42
+ base_url = None
43
+ url_variables = None
44
+ if timeout_ms is None:
45
+ timeout_ms = self.sdk_configuration.timeout_ms
46
+
47
+ if server_url is not None:
48
+ base_url = server_url
49
+ else:
50
+ base_url = self._get_url(base_url, url_variables)
51
+
52
+ request = models.IngestAdvertiserDataRequest(
53
+ ttd_auth=ttd_auth,
54
+ ttd_signature=ttd_signature,
55
+ body=models.AdvertiserDataRequest(
56
+ data_provider_id=data_provider_id,
57
+ advertiser_id=advertiser_id,
58
+ items=utils.get_pydantic_model(
59
+ items, OptionalNullable[List[models.AdvertiserDataItem]]
60
+ ),
61
+ ),
62
+ )
63
+
64
+ req = self._build_request(
65
+ method="POST",
66
+ path="/data/advertiser",
67
+ base_url=base_url,
68
+ url_variables=url_variables,
69
+ request=request,
70
+ request_body_required=True,
71
+ request_has_path_params=False,
72
+ request_has_query_params=False,
73
+ user_agent_header="user-agent",
74
+ accept_header_value="application/json",
75
+ http_headers=http_headers,
76
+ get_serialized_body=lambda: utils.serialize_request_body(
77
+ request.body, False, False, "json", models.AdvertiserDataRequest
78
+ ),
79
+ allow_empty_value=None,
80
+ timeout_ms=timeout_ms,
81
+ )
82
+
83
+ if retries == UNSET:
84
+ if self.sdk_configuration.retry_config is not UNSET:
85
+ retries = self.sdk_configuration.retry_config
86
+
87
+ retry_config = None
88
+ if isinstance(retries, utils.RetryConfig):
89
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
90
+
91
+ http_res = self.do_request(
92
+ hook_ctx=HookContext(
93
+ config=self.sdk_configuration,
94
+ base_url=base_url or "",
95
+ operation_id="IngestAdvertiserData",
96
+ oauth2_scopes=None,
97
+ security_source=None,
98
+ ),
99
+ request=req,
100
+ error_status_codes=["400", "403", "413", "429", "4XX", "500", "503", "5XX"],
101
+ retry_config=retry_config,
102
+ )
103
+
104
+ response_data: Any = None
105
+ if utils.match_response(http_res, "200", "application/json"):
106
+ return models.IngestAdvertiserDataResponse(
107
+ advertiser_data_server_response=unmarshal_json_response(
108
+ Optional[models.AdvertiserDataServerResponse], http_res
109
+ ),
110
+ http_meta=models.HTTPMetadata(request=req, response=http_res),
111
+ )
112
+ if utils.match_response(http_res, ["400", "429"], "application/json"):
113
+ response_data = unmarshal_json_response(
114
+ errors.AdvertiserDataServerResponseErrorData, http_res
115
+ )
116
+ response_data.http_meta = models.HTTPMetadata(
117
+ request=req, response=http_res
118
+ )
119
+ raise errors.AdvertiserDataServerResponseError(response_data, http_res)
120
+ if utils.match_response(http_res, ["403", "413", "4XX"], "*"):
121
+ http_res_text = utils.stream_to_text(http_res)
122
+ raise errors.APIError("API error occurred", http_res, http_res_text)
123
+ if utils.match_response(http_res, ["500", "503", "5XX"], "*"):
124
+ http_res_text = utils.stream_to_text(http_res)
125
+ raise errors.APIError("API error occurred", http_res, http_res_text)
126
+
127
+ raise errors.APIError("Unexpected response received", http_res)
128
+
129
+ async def ingest_advertiser_data_async(
130
+ self,
131
+ *,
132
+ advertiser_id: str,
133
+ ttd_auth: Optional[str] = None,
134
+ ttd_signature: Optional[str] = None,
135
+ data_provider_id: OptionalNullable[str] = UNSET,
136
+ items: OptionalNullable[
137
+ Union[
138
+ List[models.AdvertiserDataItem],
139
+ List[models.AdvertiserDataItemTypedDict],
140
+ ]
141
+ ] = UNSET,
142
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
143
+ server_url: Optional[str] = None,
144
+ timeout_ms: Optional[int] = None,
145
+ http_headers: Optional[Mapping[str, str]] = None,
146
+ ) -> models.IngestAdvertiserDataResponse:
147
+ r"""Upload first-party data for the specified ID for use in audience targeting.
148
+
149
+ :param advertiser_id:
150
+ :param ttd_auth: Data API token for authentication. If not provided, TtdSignature is required.
151
+ :param ttd_signature: Legacy signature-based authentication. Required if TTD-Auth is not provided.
152
+ :param data_provider_id:
153
+ :param items:
154
+ :param retries: Override the default retry configuration for this method
155
+ :param server_url: Override the default server URL for this method
156
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
157
+ :param http_headers: Additional headers to set or replace on requests.
158
+ """
159
+ base_url = None
160
+ url_variables = None
161
+ if timeout_ms is None:
162
+ timeout_ms = self.sdk_configuration.timeout_ms
163
+
164
+ if server_url is not None:
165
+ base_url = server_url
166
+ else:
167
+ base_url = self._get_url(base_url, url_variables)
168
+
169
+ request = models.IngestAdvertiserDataRequest(
170
+ ttd_auth=ttd_auth,
171
+ ttd_signature=ttd_signature,
172
+ body=models.AdvertiserDataRequest(
173
+ data_provider_id=data_provider_id,
174
+ advertiser_id=advertiser_id,
175
+ items=utils.get_pydantic_model(
176
+ items, OptionalNullable[List[models.AdvertiserDataItem]]
177
+ ),
178
+ ),
179
+ )
180
+
181
+ req = self._build_request_async(
182
+ method="POST",
183
+ path="/data/advertiser",
184
+ base_url=base_url,
185
+ url_variables=url_variables,
186
+ request=request,
187
+ request_body_required=True,
188
+ request_has_path_params=False,
189
+ request_has_query_params=False,
190
+ user_agent_header="user-agent",
191
+ accept_header_value="application/json",
192
+ http_headers=http_headers,
193
+ get_serialized_body=lambda: utils.serialize_request_body(
194
+ request.body, False, False, "json", models.AdvertiserDataRequest
195
+ ),
196
+ allow_empty_value=None,
197
+ timeout_ms=timeout_ms,
198
+ )
199
+
200
+ if retries == UNSET:
201
+ if self.sdk_configuration.retry_config is not UNSET:
202
+ retries = self.sdk_configuration.retry_config
203
+
204
+ retry_config = None
205
+ if isinstance(retries, utils.RetryConfig):
206
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
207
+
208
+ http_res = await self.do_request_async(
209
+ hook_ctx=HookContext(
210
+ config=self.sdk_configuration,
211
+ base_url=base_url or "",
212
+ operation_id="IngestAdvertiserData",
213
+ oauth2_scopes=None,
214
+ security_source=None,
215
+ ),
216
+ request=req,
217
+ error_status_codes=["400", "403", "413", "429", "4XX", "500", "503", "5XX"],
218
+ retry_config=retry_config,
219
+ )
220
+
221
+ response_data: Any = None
222
+ if utils.match_response(http_res, "200", "application/json"):
223
+ return models.IngestAdvertiserDataResponse(
224
+ advertiser_data_server_response=unmarshal_json_response(
225
+ Optional[models.AdvertiserDataServerResponse], http_res
226
+ ),
227
+ http_meta=models.HTTPMetadata(request=req, response=http_res),
228
+ )
229
+ if utils.match_response(http_res, ["400", "429"], "application/json"):
230
+ response_data = unmarshal_json_response(
231
+ errors.AdvertiserDataServerResponseErrorData, http_res
232
+ )
233
+ response_data.http_meta = models.HTTPMetadata(
234
+ request=req, response=http_res
235
+ )
236
+ raise errors.AdvertiserDataServerResponseError(response_data, http_res)
237
+ if utils.match_response(http_res, ["403", "413", "4XX"], "*"):
238
+ http_res_text = await utils.stream_to_text_async(http_res)
239
+ raise errors.APIError("API error occurred", http_res, http_res_text)
240
+ if utils.match_response(http_res, ["500", "503", "5XX"], "*"):
241
+ http_res_text = await utils.stream_to_text_async(http_res)
242
+ raise errors.APIError("API error occurred", http_res, http_res_text)
243
+
244
+ raise errors.APIError("Unexpected response received", http_res)