newscatcher-catchall-sdk 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 (74) hide show
  1. newscatcher_catchall/__init__.py +149 -0
  2. newscatcher_catchall/client.py +211 -0
  3. newscatcher_catchall/core/__init__.py +105 -0
  4. newscatcher_catchall/core/api_error.py +23 -0
  5. newscatcher_catchall/core/client_wrapper.py +79 -0
  6. newscatcher_catchall/core/datetime_utils.py +28 -0
  7. newscatcher_catchall/core/file.py +67 -0
  8. newscatcher_catchall/core/force_multipart.py +18 -0
  9. newscatcher_catchall/core/http_client.py +543 -0
  10. newscatcher_catchall/core/http_response.py +55 -0
  11. newscatcher_catchall/core/http_sse/__init__.py +42 -0
  12. newscatcher_catchall/core/http_sse/_api.py +112 -0
  13. newscatcher_catchall/core/http_sse/_decoders.py +61 -0
  14. newscatcher_catchall/core/http_sse/_exceptions.py +7 -0
  15. newscatcher_catchall/core/http_sse/_models.py +17 -0
  16. newscatcher_catchall/core/jsonable_encoder.py +100 -0
  17. newscatcher_catchall/core/pydantic_utilities.py +260 -0
  18. newscatcher_catchall/core/query_encoder.py +58 -0
  19. newscatcher_catchall/core/remove_none_from_dict.py +11 -0
  20. newscatcher_catchall/core/request_options.py +35 -0
  21. newscatcher_catchall/core/serialization.py +276 -0
  22. newscatcher_catchall/environment.py +7 -0
  23. newscatcher_catchall/errors/__init__.py +40 -0
  24. newscatcher_catchall/errors/forbidden_error.py +11 -0
  25. newscatcher_catchall/errors/not_found_error.py +11 -0
  26. newscatcher_catchall/errors/unprocessable_entity_error.py +11 -0
  27. newscatcher_catchall/jobs/__init__.py +4 -0
  28. newscatcher_catchall/jobs/client.py +389 -0
  29. newscatcher_catchall/jobs/raw_client.py +538 -0
  30. newscatcher_catchall/meta/__init__.py +34 -0
  31. newscatcher_catchall/meta/client.py +161 -0
  32. newscatcher_catchall/meta/raw_client.py +166 -0
  33. newscatcher_catchall/meta/types/__init__.py +38 -0
  34. newscatcher_catchall/meta/types/get_version_response.py +19 -0
  35. newscatcher_catchall/meta/types/health_check_response.py +19 -0
  36. newscatcher_catchall/monitors/__init__.py +38 -0
  37. newscatcher_catchall/monitors/client.py +550 -0
  38. newscatcher_catchall/monitors/raw_client.py +874 -0
  39. newscatcher_catchall/monitors/types/__init__.py +40 -0
  40. newscatcher_catchall/monitors/types/disable_monitor_response.py +19 -0
  41. newscatcher_catchall/monitors/types/enable_monitor_response.py +19 -0
  42. newscatcher_catchall/monitors/types/list_monitor_jobs_request_sort.py +5 -0
  43. newscatcher_catchall/py.typed +0 -0
  44. newscatcher_catchall/types/__init__.py +110 -0
  45. newscatcher_catchall/types/citation.py +33 -0
  46. newscatcher_catchall/types/context.py +3 -0
  47. newscatcher_catchall/types/create_monitor_response_dto.py +27 -0
  48. newscatcher_catchall/types/error.py +22 -0
  49. newscatcher_catchall/types/job_status.py +21 -0
  50. newscatcher_catchall/types/list_monitors_response_dto.py +28 -0
  51. newscatcher_catchall/types/list_user_jobs_response_dto.py +27 -0
  52. newscatcher_catchall/types/monitor_job_item.py +42 -0
  53. newscatcher_catchall/types/monitor_list_item.py +53 -0
  54. newscatcher_catchall/types/pull_job_response_dto.py +80 -0
  55. newscatcher_catchall/types/pull_job_response_dto_date_range.py +21 -0
  56. newscatcher_catchall/types/pull_monitor_response_dto.py +69 -0
  57. newscatcher_catchall/types/pull_monitor_response_dto_date_range.py +32 -0
  58. newscatcher_catchall/types/pull_monitor_response_dto_reference_job.py +31 -0
  59. newscatcher_catchall/types/query.py +3 -0
  60. newscatcher_catchall/types/record.py +40 -0
  61. newscatcher_catchall/types/schema.py +3 -0
  62. newscatcher_catchall/types/status_response_dto.py +25 -0
  63. newscatcher_catchall/types/submit_response_body.py +22 -0
  64. newscatcher_catchall/types/validation_error_detail.py +33 -0
  65. newscatcher_catchall/types/validation_error_detail_loc_item.py +5 -0
  66. newscatcher_catchall/types/validation_error_response.py +20 -0
  67. newscatcher_catchall/types/webhook_dto.py +43 -0
  68. newscatcher_catchall/types/webhook_dto_method.py +5 -0
  69. newscatcher_catchall/types/webhook_payload.py +44 -0
  70. newscatcher_catchall/version.py +3 -0
  71. newscatcher_catchall_sdk-0.1.0.dist-info/LICENSE +21 -0
  72. newscatcher_catchall_sdk-0.1.0.dist-info/METADATA +224 -0
  73. newscatcher_catchall_sdk-0.1.0.dist-info/RECORD +74 -0
  74. newscatcher_catchall_sdk-0.1.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,149 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ # isort: skip_file
4
+
5
+ import typing
6
+ from importlib import import_module
7
+
8
+ if typing.TYPE_CHECKING:
9
+ from .types import (
10
+ Citation,
11
+ Context,
12
+ CreateMonitorResponseDto,
13
+ Error,
14
+ JobStatus,
15
+ ListMonitorsResponseDto,
16
+ ListUserJobsResponseDto,
17
+ MonitorJobItem,
18
+ MonitorListItem,
19
+ PullJobResponseDto,
20
+ PullJobResponseDtoDateRange,
21
+ PullMonitorResponseDto,
22
+ PullMonitorResponseDtoDateRange,
23
+ PullMonitorResponseDtoReferenceJob,
24
+ Query,
25
+ Record,
26
+ Schema,
27
+ StatusResponseDto,
28
+ SubmitResponseBody,
29
+ ValidationErrorDetail,
30
+ ValidationErrorDetailLocItem,
31
+ ValidationErrorResponse,
32
+ WebhookDto,
33
+ WebhookDtoMethod,
34
+ WebhookPayload,
35
+ )
36
+ from .errors import ForbiddenError, NotFoundError, UnprocessableEntityError
37
+ from . import jobs, meta, monitors
38
+ from .client import AsyncCatchAllApi, CatchAllApi
39
+ from .environment import CatchAllApiEnvironment
40
+ from .meta import GetVersionResponse, HealthCheckResponse
41
+ from .monitors import DisableMonitorResponse, EnableMonitorResponse, ListMonitorJobsRequestSort
42
+ from .version import __version__
43
+ _dynamic_imports: typing.Dict[str, str] = {
44
+ "AsyncCatchAllApi": ".client",
45
+ "CatchAllApi": ".client",
46
+ "CatchAllApiEnvironment": ".environment",
47
+ "Citation": ".types",
48
+ "Context": ".types",
49
+ "CreateMonitorResponseDto": ".types",
50
+ "DisableMonitorResponse": ".monitors",
51
+ "EnableMonitorResponse": ".monitors",
52
+ "Error": ".types",
53
+ "ForbiddenError": ".errors",
54
+ "GetVersionResponse": ".meta",
55
+ "HealthCheckResponse": ".meta",
56
+ "JobStatus": ".types",
57
+ "ListMonitorJobsRequestSort": ".monitors",
58
+ "ListMonitorsResponseDto": ".types",
59
+ "ListUserJobsResponseDto": ".types",
60
+ "MonitorJobItem": ".types",
61
+ "MonitorListItem": ".types",
62
+ "NotFoundError": ".errors",
63
+ "PullJobResponseDto": ".types",
64
+ "PullJobResponseDtoDateRange": ".types",
65
+ "PullMonitorResponseDto": ".types",
66
+ "PullMonitorResponseDtoDateRange": ".types",
67
+ "PullMonitorResponseDtoReferenceJob": ".types",
68
+ "Query": ".types",
69
+ "Record": ".types",
70
+ "Schema": ".types",
71
+ "StatusResponseDto": ".types",
72
+ "SubmitResponseBody": ".types",
73
+ "UnprocessableEntityError": ".errors",
74
+ "ValidationErrorDetail": ".types",
75
+ "ValidationErrorDetailLocItem": ".types",
76
+ "ValidationErrorResponse": ".types",
77
+ "WebhookDto": ".types",
78
+ "WebhookDtoMethod": ".types",
79
+ "WebhookPayload": ".types",
80
+ "__version__": ".version",
81
+ "jobs": ".jobs",
82
+ "meta": ".meta",
83
+ "monitors": ".monitors",
84
+ }
85
+
86
+
87
+ def __getattr__(attr_name: str) -> typing.Any:
88
+ module_name = _dynamic_imports.get(attr_name)
89
+ if module_name is None:
90
+ raise AttributeError(f"No {attr_name} found in _dynamic_imports for module name -> {__name__}")
91
+ try:
92
+ module = import_module(module_name, __package__)
93
+ if module_name == f".{attr_name}":
94
+ return module
95
+ else:
96
+ return getattr(module, attr_name)
97
+ except ImportError as e:
98
+ raise ImportError(f"Failed to import {attr_name} from {module_name}: {e}") from e
99
+ except AttributeError as e:
100
+ raise AttributeError(f"Failed to get {attr_name} from {module_name}: {e}") from e
101
+
102
+
103
+ def __dir__():
104
+ lazy_attrs = list(_dynamic_imports.keys())
105
+ return sorted(lazy_attrs)
106
+
107
+
108
+ __all__ = [
109
+ "AsyncCatchAllApi",
110
+ "CatchAllApi",
111
+ "CatchAllApiEnvironment",
112
+ "Citation",
113
+ "Context",
114
+ "CreateMonitorResponseDto",
115
+ "DisableMonitorResponse",
116
+ "EnableMonitorResponse",
117
+ "Error",
118
+ "ForbiddenError",
119
+ "GetVersionResponse",
120
+ "HealthCheckResponse",
121
+ "JobStatus",
122
+ "ListMonitorJobsRequestSort",
123
+ "ListMonitorsResponseDto",
124
+ "ListUserJobsResponseDto",
125
+ "MonitorJobItem",
126
+ "MonitorListItem",
127
+ "NotFoundError",
128
+ "PullJobResponseDto",
129
+ "PullJobResponseDtoDateRange",
130
+ "PullMonitorResponseDto",
131
+ "PullMonitorResponseDtoDateRange",
132
+ "PullMonitorResponseDtoReferenceJob",
133
+ "Query",
134
+ "Record",
135
+ "Schema",
136
+ "StatusResponseDto",
137
+ "SubmitResponseBody",
138
+ "UnprocessableEntityError",
139
+ "ValidationErrorDetail",
140
+ "ValidationErrorDetailLocItem",
141
+ "ValidationErrorResponse",
142
+ "WebhookDto",
143
+ "WebhookDtoMethod",
144
+ "WebhookPayload",
145
+ "__version__",
146
+ "jobs",
147
+ "meta",
148
+ "monitors",
149
+ ]
@@ -0,0 +1,211 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ from __future__ import annotations
4
+
5
+ import typing
6
+
7
+ import httpx
8
+ from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
9
+ from .environment import CatchAllApiEnvironment
10
+
11
+ if typing.TYPE_CHECKING:
12
+ from .jobs.client import AsyncJobsClient, JobsClient
13
+ from .meta.client import AsyncMetaClient, MetaClient
14
+ from .monitors.client import AsyncMonitorsClient, MonitorsClient
15
+
16
+
17
+ class CatchAllApi:
18
+ """
19
+ Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.
20
+
21
+ Parameters
22
+ ----------
23
+ base_url : typing.Optional[str]
24
+ The base url to use for requests from the client.
25
+
26
+ environment : CatchAllApiEnvironment
27
+ The environment to use for requests from the client. from .environment import CatchAllApiEnvironment
28
+
29
+
30
+
31
+ Defaults to CatchAllApiEnvironment.DEFAULT
32
+
33
+
34
+
35
+ api_key : str
36
+ headers : typing.Optional[typing.Dict[str, str]]
37
+ Additional headers to send with every request.
38
+
39
+ timeout : typing.Optional[float]
40
+ The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.
41
+
42
+ follow_redirects : typing.Optional[bool]
43
+ Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.
44
+
45
+ httpx_client : typing.Optional[httpx.Client]
46
+ The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.
47
+
48
+ Examples
49
+ --------
50
+ from newscatcher_catchall import CatchAllApi
51
+
52
+ client = CatchAllApi(
53
+ api_key="YOUR_API_KEY",
54
+ )
55
+ """
56
+
57
+ def __init__(
58
+ self,
59
+ *,
60
+ base_url: typing.Optional[str] = None,
61
+ environment: CatchAllApiEnvironment = CatchAllApiEnvironment.DEFAULT,
62
+ api_key: str,
63
+ headers: typing.Optional[typing.Dict[str, str]] = None,
64
+ timeout: typing.Optional[float] = None,
65
+ follow_redirects: typing.Optional[bool] = True,
66
+ httpx_client: typing.Optional[httpx.Client] = None,
67
+ ):
68
+ _defaulted_timeout = (
69
+ timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
70
+ )
71
+ self._client_wrapper = SyncClientWrapper(
72
+ base_url=_get_base_url(base_url=base_url, environment=environment),
73
+ api_key=api_key,
74
+ headers=headers,
75
+ httpx_client=httpx_client
76
+ if httpx_client is not None
77
+ else httpx.Client(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
78
+ if follow_redirects is not None
79
+ else httpx.Client(timeout=_defaulted_timeout),
80
+ timeout=_defaulted_timeout,
81
+ )
82
+ self._jobs: typing.Optional[JobsClient] = None
83
+ self._monitors: typing.Optional[MonitorsClient] = None
84
+ self._meta: typing.Optional[MetaClient] = None
85
+
86
+ @property
87
+ def jobs(self):
88
+ if self._jobs is None:
89
+ from .jobs.client import JobsClient # noqa: E402
90
+
91
+ self._jobs = JobsClient(client_wrapper=self._client_wrapper)
92
+ return self._jobs
93
+
94
+ @property
95
+ def monitors(self):
96
+ if self._monitors is None:
97
+ from .monitors.client import MonitorsClient # noqa: E402
98
+
99
+ self._monitors = MonitorsClient(client_wrapper=self._client_wrapper)
100
+ return self._monitors
101
+
102
+ @property
103
+ def meta(self):
104
+ if self._meta is None:
105
+ from .meta.client import MetaClient # noqa: E402
106
+
107
+ self._meta = MetaClient(client_wrapper=self._client_wrapper)
108
+ return self._meta
109
+
110
+
111
+ class AsyncCatchAllApi:
112
+ """
113
+ Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.
114
+
115
+ Parameters
116
+ ----------
117
+ base_url : typing.Optional[str]
118
+ The base url to use for requests from the client.
119
+
120
+ environment : CatchAllApiEnvironment
121
+ The environment to use for requests from the client. from .environment import CatchAllApiEnvironment
122
+
123
+
124
+
125
+ Defaults to CatchAllApiEnvironment.DEFAULT
126
+
127
+
128
+
129
+ api_key : str
130
+ headers : typing.Optional[typing.Dict[str, str]]
131
+ Additional headers to send with every request.
132
+
133
+ timeout : typing.Optional[float]
134
+ The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.
135
+
136
+ follow_redirects : typing.Optional[bool]
137
+ Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.
138
+
139
+ httpx_client : typing.Optional[httpx.AsyncClient]
140
+ The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.
141
+
142
+ Examples
143
+ --------
144
+ from newscatcher_catchall import AsyncCatchAllApi
145
+
146
+ client = AsyncCatchAllApi(
147
+ api_key="YOUR_API_KEY",
148
+ )
149
+ """
150
+
151
+ def __init__(
152
+ self,
153
+ *,
154
+ base_url: typing.Optional[str] = None,
155
+ environment: CatchAllApiEnvironment = CatchAllApiEnvironment.DEFAULT,
156
+ api_key: str,
157
+ headers: typing.Optional[typing.Dict[str, str]] = None,
158
+ timeout: typing.Optional[float] = None,
159
+ follow_redirects: typing.Optional[bool] = True,
160
+ httpx_client: typing.Optional[httpx.AsyncClient] = None,
161
+ ):
162
+ _defaulted_timeout = (
163
+ timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
164
+ )
165
+ self._client_wrapper = AsyncClientWrapper(
166
+ base_url=_get_base_url(base_url=base_url, environment=environment),
167
+ api_key=api_key,
168
+ headers=headers,
169
+ httpx_client=httpx_client
170
+ if httpx_client is not None
171
+ else httpx.AsyncClient(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
172
+ if follow_redirects is not None
173
+ else httpx.AsyncClient(timeout=_defaulted_timeout),
174
+ timeout=_defaulted_timeout,
175
+ )
176
+ self._jobs: typing.Optional[AsyncJobsClient] = None
177
+ self._monitors: typing.Optional[AsyncMonitorsClient] = None
178
+ self._meta: typing.Optional[AsyncMetaClient] = None
179
+
180
+ @property
181
+ def jobs(self):
182
+ if self._jobs is None:
183
+ from .jobs.client import AsyncJobsClient # noqa: E402
184
+
185
+ self._jobs = AsyncJobsClient(client_wrapper=self._client_wrapper)
186
+ return self._jobs
187
+
188
+ @property
189
+ def monitors(self):
190
+ if self._monitors is None:
191
+ from .monitors.client import AsyncMonitorsClient # noqa: E402
192
+
193
+ self._monitors = AsyncMonitorsClient(client_wrapper=self._client_wrapper)
194
+ return self._monitors
195
+
196
+ @property
197
+ def meta(self):
198
+ if self._meta is None:
199
+ from .meta.client import AsyncMetaClient # noqa: E402
200
+
201
+ self._meta = AsyncMetaClient(client_wrapper=self._client_wrapper)
202
+ return self._meta
203
+
204
+
205
+ def _get_base_url(*, base_url: typing.Optional[str] = None, environment: CatchAllApiEnvironment) -> str:
206
+ if base_url is not None:
207
+ return base_url
208
+ elif environment is not None:
209
+ return environment.value
210
+ else:
211
+ raise Exception("Please pass in either base_url or environment to construct the client")
@@ -0,0 +1,105 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ # isort: skip_file
4
+
5
+ import typing
6
+ from importlib import import_module
7
+
8
+ if typing.TYPE_CHECKING:
9
+ from .api_error import ApiError
10
+ from .client_wrapper import AsyncClientWrapper, BaseClientWrapper, SyncClientWrapper
11
+ from .datetime_utils import serialize_datetime
12
+ from .file import File, convert_file_dict_to_httpx_tuples, with_content_type
13
+ from .http_client import AsyncHttpClient, HttpClient
14
+ from .http_response import AsyncHttpResponse, HttpResponse
15
+ from .jsonable_encoder import jsonable_encoder
16
+ from .pydantic_utilities import (
17
+ IS_PYDANTIC_V2,
18
+ UniversalBaseModel,
19
+ UniversalRootModel,
20
+ parse_obj_as,
21
+ universal_field_validator,
22
+ universal_root_validator,
23
+ update_forward_refs,
24
+ )
25
+ from .query_encoder import encode_query
26
+ from .remove_none_from_dict import remove_none_from_dict
27
+ from .request_options import RequestOptions
28
+ from .serialization import FieldMetadata, convert_and_respect_annotation_metadata
29
+ _dynamic_imports: typing.Dict[str, str] = {
30
+ "ApiError": ".api_error",
31
+ "AsyncClientWrapper": ".client_wrapper",
32
+ "AsyncHttpClient": ".http_client",
33
+ "AsyncHttpResponse": ".http_response",
34
+ "BaseClientWrapper": ".client_wrapper",
35
+ "FieldMetadata": ".serialization",
36
+ "File": ".file",
37
+ "HttpClient": ".http_client",
38
+ "HttpResponse": ".http_response",
39
+ "IS_PYDANTIC_V2": ".pydantic_utilities",
40
+ "RequestOptions": ".request_options",
41
+ "SyncClientWrapper": ".client_wrapper",
42
+ "UniversalBaseModel": ".pydantic_utilities",
43
+ "UniversalRootModel": ".pydantic_utilities",
44
+ "convert_and_respect_annotation_metadata": ".serialization",
45
+ "convert_file_dict_to_httpx_tuples": ".file",
46
+ "encode_query": ".query_encoder",
47
+ "jsonable_encoder": ".jsonable_encoder",
48
+ "parse_obj_as": ".pydantic_utilities",
49
+ "remove_none_from_dict": ".remove_none_from_dict",
50
+ "serialize_datetime": ".datetime_utils",
51
+ "universal_field_validator": ".pydantic_utilities",
52
+ "universal_root_validator": ".pydantic_utilities",
53
+ "update_forward_refs": ".pydantic_utilities",
54
+ "with_content_type": ".file",
55
+ }
56
+
57
+
58
+ def __getattr__(attr_name: str) -> typing.Any:
59
+ module_name = _dynamic_imports.get(attr_name)
60
+ if module_name is None:
61
+ raise AttributeError(f"No {attr_name} found in _dynamic_imports for module name -> {__name__}")
62
+ try:
63
+ module = import_module(module_name, __package__)
64
+ if module_name == f".{attr_name}":
65
+ return module
66
+ else:
67
+ return getattr(module, attr_name)
68
+ except ImportError as e:
69
+ raise ImportError(f"Failed to import {attr_name} from {module_name}: {e}") from e
70
+ except AttributeError as e:
71
+ raise AttributeError(f"Failed to get {attr_name} from {module_name}: {e}") from e
72
+
73
+
74
+ def __dir__():
75
+ lazy_attrs = list(_dynamic_imports.keys())
76
+ return sorted(lazy_attrs)
77
+
78
+
79
+ __all__ = [
80
+ "ApiError",
81
+ "AsyncClientWrapper",
82
+ "AsyncHttpClient",
83
+ "AsyncHttpResponse",
84
+ "BaseClientWrapper",
85
+ "FieldMetadata",
86
+ "File",
87
+ "HttpClient",
88
+ "HttpResponse",
89
+ "IS_PYDANTIC_V2",
90
+ "RequestOptions",
91
+ "SyncClientWrapper",
92
+ "UniversalBaseModel",
93
+ "UniversalRootModel",
94
+ "convert_and_respect_annotation_metadata",
95
+ "convert_file_dict_to_httpx_tuples",
96
+ "encode_query",
97
+ "jsonable_encoder",
98
+ "parse_obj_as",
99
+ "remove_none_from_dict",
100
+ "serialize_datetime",
101
+ "universal_field_validator",
102
+ "universal_root_validator",
103
+ "update_forward_refs",
104
+ "with_content_type",
105
+ ]
@@ -0,0 +1,23 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ from typing import Any, Dict, Optional
4
+
5
+
6
+ class ApiError(Exception):
7
+ headers: Optional[Dict[str, str]]
8
+ status_code: Optional[int]
9
+ body: Any
10
+
11
+ def __init__(
12
+ self,
13
+ *,
14
+ headers: Optional[Dict[str, str]] = None,
15
+ status_code: Optional[int] = None,
16
+ body: Any = None,
17
+ ) -> None:
18
+ self.headers = headers
19
+ self.status_code = status_code
20
+ self.body = body
21
+
22
+ def __str__(self) -> str:
23
+ return f"headers: {self.headers}, status_code: {self.status_code}, body: {self.body}"
@@ -0,0 +1,79 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+
5
+ import httpx
6
+ from .http_client import AsyncHttpClient, HttpClient
7
+
8
+
9
+ class BaseClientWrapper:
10
+ def __init__(
11
+ self,
12
+ *,
13
+ api_key: str,
14
+ headers: typing.Optional[typing.Dict[str, str]] = None,
15
+ base_url: str,
16
+ timeout: typing.Optional[float] = None,
17
+ ):
18
+ self.api_key = api_key
19
+ self._headers = headers
20
+ self._base_url = base_url
21
+ self._timeout = timeout
22
+
23
+ def get_headers(self) -> typing.Dict[str, str]:
24
+ headers: typing.Dict[str, str] = {
25
+ "User-Agent": "newscatcher-catchall-sdk/0.1.0",
26
+ "X-Fern-Language": "Python",
27
+ "X-Fern-SDK-Name": "newscatcher-catchall-sdk",
28
+ "X-Fern-SDK-Version": "0.1.0",
29
+ **(self.get_custom_headers() or {}),
30
+ }
31
+ headers["x-api-key"] = self.api_key
32
+ return headers
33
+
34
+ def get_custom_headers(self) -> typing.Optional[typing.Dict[str, str]]:
35
+ return self._headers
36
+
37
+ def get_base_url(self) -> str:
38
+ return self._base_url
39
+
40
+ def get_timeout(self) -> typing.Optional[float]:
41
+ return self._timeout
42
+
43
+
44
+ class SyncClientWrapper(BaseClientWrapper):
45
+ def __init__(
46
+ self,
47
+ *,
48
+ api_key: str,
49
+ headers: typing.Optional[typing.Dict[str, str]] = None,
50
+ base_url: str,
51
+ timeout: typing.Optional[float] = None,
52
+ httpx_client: httpx.Client,
53
+ ):
54
+ super().__init__(api_key=api_key, headers=headers, base_url=base_url, timeout=timeout)
55
+ self.httpx_client = HttpClient(
56
+ httpx_client=httpx_client,
57
+ base_headers=self.get_headers,
58
+ base_timeout=self.get_timeout,
59
+ base_url=self.get_base_url,
60
+ )
61
+
62
+
63
+ class AsyncClientWrapper(BaseClientWrapper):
64
+ def __init__(
65
+ self,
66
+ *,
67
+ api_key: str,
68
+ headers: typing.Optional[typing.Dict[str, str]] = None,
69
+ base_url: str,
70
+ timeout: typing.Optional[float] = None,
71
+ httpx_client: httpx.AsyncClient,
72
+ ):
73
+ super().__init__(api_key=api_key, headers=headers, base_url=base_url, timeout=timeout)
74
+ self.httpx_client = AsyncHttpClient(
75
+ httpx_client=httpx_client,
76
+ base_headers=self.get_headers,
77
+ base_timeout=self.get_timeout,
78
+ base_url=self.get_base_url,
79
+ )
@@ -0,0 +1,28 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import datetime as dt
4
+
5
+
6
+ def serialize_datetime(v: dt.datetime) -> str:
7
+ """
8
+ Serialize a datetime including timezone info.
9
+
10
+ Uses the timezone info provided if present, otherwise uses the current runtime's timezone info.
11
+
12
+ UTC datetimes end in "Z" while all other timezones are represented as offset from UTC, e.g. +05:00.
13
+ """
14
+
15
+ def _serialize_zoned_datetime(v: dt.datetime) -> str:
16
+ if v.tzinfo is not None and v.tzinfo.tzname(None) == dt.timezone.utc.tzname(None):
17
+ # UTC is a special case where we use "Z" at the end instead of "+00:00"
18
+ return v.isoformat().replace("+00:00", "Z")
19
+ else:
20
+ # Delegate to the typical +/- offset format
21
+ return v.isoformat()
22
+
23
+ if v.tzinfo is not None:
24
+ return _serialize_zoned_datetime(v)
25
+ else:
26
+ local_tz = dt.datetime.now().astimezone().tzinfo
27
+ localized_dt = v.replace(tzinfo=local_tz)
28
+ return _serialize_zoned_datetime(localized_dt)
@@ -0,0 +1,67 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ from typing import IO, Dict, List, Mapping, Optional, Tuple, Union, cast
4
+
5
+ # File typing inspired by the flexibility of types within the httpx library
6
+ # https://github.com/encode/httpx/blob/master/httpx/_types.py
7
+ FileContent = Union[IO[bytes], bytes, str]
8
+ File = Union[
9
+ # file (or bytes)
10
+ FileContent,
11
+ # (filename, file (or bytes))
12
+ Tuple[Optional[str], FileContent],
13
+ # (filename, file (or bytes), content_type)
14
+ Tuple[Optional[str], FileContent, Optional[str]],
15
+ # (filename, file (or bytes), content_type, headers)
16
+ Tuple[
17
+ Optional[str],
18
+ FileContent,
19
+ Optional[str],
20
+ Mapping[str, str],
21
+ ],
22
+ ]
23
+
24
+
25
+ def convert_file_dict_to_httpx_tuples(
26
+ d: Dict[str, Union[File, List[File]]],
27
+ ) -> List[Tuple[str, File]]:
28
+ """
29
+ The format we use is a list of tuples, where the first element is the
30
+ name of the file and the second is the file object. Typically HTTPX wants
31
+ a dict, but to be able to send lists of files, you have to use the list
32
+ approach (which also works for non-lists)
33
+ https://github.com/encode/httpx/pull/1032
34
+ """
35
+
36
+ httpx_tuples = []
37
+ for key, file_like in d.items():
38
+ if isinstance(file_like, list):
39
+ for file_like_item in file_like:
40
+ httpx_tuples.append((key, file_like_item))
41
+ else:
42
+ httpx_tuples.append((key, file_like))
43
+ return httpx_tuples
44
+
45
+
46
+ def with_content_type(*, file: File, default_content_type: str) -> File:
47
+ """
48
+ This function resolves to the file's content type, if provided, and defaults
49
+ to the default_content_type value if not.
50
+ """
51
+ if isinstance(file, tuple):
52
+ if len(file) == 2:
53
+ filename, content = cast(Tuple[Optional[str], FileContent], file) # type: ignore
54
+ return (filename, content, default_content_type)
55
+ elif len(file) == 3:
56
+ filename, content, file_content_type = cast(Tuple[Optional[str], FileContent, Optional[str]], file) # type: ignore
57
+ out_content_type = file_content_type or default_content_type
58
+ return (filename, content, out_content_type)
59
+ elif len(file) == 4:
60
+ filename, content, file_content_type, headers = cast( # type: ignore
61
+ Tuple[Optional[str], FileContent, Optional[str], Mapping[str, str]], file
62
+ )
63
+ out_content_type = file_content_type or default_content_type
64
+ return (filename, content, out_content_type, headers)
65
+ else:
66
+ raise ValueError(f"Unexpected tuple length: {len(file)}")
67
+ return (None, file, default_content_type)
@@ -0,0 +1,18 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ from typing import Any, Dict
4
+
5
+
6
+ class ForceMultipartDict(Dict[str, Any]):
7
+ """
8
+ A dictionary subclass that always evaluates to True in boolean contexts.
9
+
10
+ This is used to force multipart/form-data encoding in HTTP requests even when
11
+ the dictionary is empty, which would normally evaluate to False.
12
+ """
13
+
14
+ def __bool__(self) -> bool:
15
+ return True
16
+
17
+
18
+ FORCE_MULTIPART = ForceMultipartDict()