|
1 | 1 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
2 | 2 |
|
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from typing_extensions import override |
| 6 | + |
3 | 7 | from . import types |
4 | 8 | from ._types import NOT_GIVEN, Omit, NoneType, NotGiven, Transport, ProxiesTypes |
5 | 9 | from ._utils import file_from_path |
|
92 | 96 | except (TypeError, AttributeError): |
93 | 97 | # Some of our exported symbols are builtins which we can't set attributes for. |
94 | 98 | pass |
| 99 | + |
| 100 | +# ------ Module level client ------ |
| 101 | +import typing as _t |
| 102 | + |
| 103 | +import httpx as _httpx |
| 104 | + |
| 105 | +from ._base_client import DEFAULT_TIMEOUT, DEFAULT_MAX_RETRIES |
| 106 | + |
| 107 | +bearer_token: str | None = None |
| 108 | + |
| 109 | +base_url: str | _httpx.URL | None = None |
| 110 | + |
| 111 | +timeout: float | Timeout | None = DEFAULT_TIMEOUT |
| 112 | + |
| 113 | +max_retries: int = DEFAULT_MAX_RETRIES |
| 114 | + |
| 115 | +default_headers: _t.Mapping[str, str] | None = None |
| 116 | + |
| 117 | +default_query: _t.Mapping[str, object] | None = None |
| 118 | + |
| 119 | +http_client: _httpx.Client | None = None |
| 120 | + |
| 121 | + |
| 122 | +class _ModuleClient(ReplicateClient): |
| 123 | + # Note: we have to use type: ignores here as overriding class members |
| 124 | + # with properties is technically unsafe but it is fine for our use case |
| 125 | + |
| 126 | + @property # type: ignore |
| 127 | + @override |
| 128 | + def bearer_token(self) -> str | None: |
| 129 | + return bearer_token |
| 130 | + |
| 131 | + @bearer_token.setter # type: ignore |
| 132 | + def bearer_token(self, value: str | None) -> None: # type: ignore |
| 133 | + global bearer_token |
| 134 | + |
| 135 | + bearer_token = value |
| 136 | + |
| 137 | + @property |
| 138 | + @override |
| 139 | + def base_url(self) -> _httpx.URL: |
| 140 | + if base_url is not None: |
| 141 | + return _httpx.URL(base_url) |
| 142 | + |
| 143 | + return super().base_url |
| 144 | + |
| 145 | + @base_url.setter |
| 146 | + def base_url(self, url: _httpx.URL | str) -> None: |
| 147 | + super().base_url = url # type: ignore[misc] |
| 148 | + |
| 149 | + @property # type: ignore |
| 150 | + @override |
| 151 | + def timeout(self) -> float | Timeout | None: |
| 152 | + return timeout |
| 153 | + |
| 154 | + @timeout.setter # type: ignore |
| 155 | + def timeout(self, value: float | Timeout | None) -> None: # type: ignore |
| 156 | + global timeout |
| 157 | + |
| 158 | + timeout = value |
| 159 | + |
| 160 | + @property # type: ignore |
| 161 | + @override |
| 162 | + def max_retries(self) -> int: |
| 163 | + return max_retries |
| 164 | + |
| 165 | + @max_retries.setter # type: ignore |
| 166 | + def max_retries(self, value: int) -> None: # type: ignore |
| 167 | + global max_retries |
| 168 | + |
| 169 | + max_retries = value |
| 170 | + |
| 171 | + @property # type: ignore |
| 172 | + @override |
| 173 | + def _custom_headers(self) -> _t.Mapping[str, str] | None: |
| 174 | + return default_headers |
| 175 | + |
| 176 | + @_custom_headers.setter # type: ignore |
| 177 | + def _custom_headers(self, value: _t.Mapping[str, str] | None) -> None: # type: ignore |
| 178 | + global default_headers |
| 179 | + |
| 180 | + default_headers = value |
| 181 | + |
| 182 | + @property # type: ignore |
| 183 | + @override |
| 184 | + def _custom_query(self) -> _t.Mapping[str, object] | None: |
| 185 | + return default_query |
| 186 | + |
| 187 | + @_custom_query.setter # type: ignore |
| 188 | + def _custom_query(self, value: _t.Mapping[str, object] | None) -> None: # type: ignore |
| 189 | + global default_query |
| 190 | + |
| 191 | + default_query = value |
| 192 | + |
| 193 | + @property # type: ignore |
| 194 | + @override |
| 195 | + def _client(self) -> _httpx.Client: |
| 196 | + return http_client or super()._client |
| 197 | + |
| 198 | + @_client.setter # type: ignore |
| 199 | + def _client(self, value: _httpx.Client) -> None: # type: ignore |
| 200 | + global http_client |
| 201 | + |
| 202 | + http_client = value |
| 203 | + |
| 204 | + |
| 205 | +_client: ReplicateClient | None = None |
| 206 | + |
| 207 | + |
| 208 | +def _load_client() -> ReplicateClient: # type: ignore[reportUnusedFunction] |
| 209 | + global _client |
| 210 | + |
| 211 | + if _client is None: |
| 212 | + _client = _ModuleClient( |
| 213 | + bearer_token=bearer_token, |
| 214 | + base_url=base_url, |
| 215 | + timeout=timeout, |
| 216 | + max_retries=max_retries, |
| 217 | + default_headers=default_headers, |
| 218 | + default_query=default_query, |
| 219 | + http_client=http_client, |
| 220 | + ) |
| 221 | + return _client |
| 222 | + |
| 223 | + return _client |
| 224 | + |
| 225 | + |
| 226 | +def _reset_client() -> None: # type: ignore[reportUnusedFunction] |
| 227 | + global _client |
| 228 | + |
| 229 | + _client = None |
| 230 | + |
| 231 | + |
| 232 | +from ._module_client import ( |
| 233 | + models as models, |
| 234 | + accounts as accounts, |
| 235 | + hardware as hardware, |
| 236 | + webhooks as webhooks, |
| 237 | + trainings as trainings, |
| 238 | + collections as collections, |
| 239 | + deployments as deployments, |
| 240 | + predictions as predictions, |
| 241 | +) |
0 commit comments