A view over the request that the client is about to execute. Treat instances as immutable; use `copy()` to derive a modified request.
| 13 | |
| 14 | |
| 15 | class APIRequest: |
| 16 | """A view over the request that the client is about to execute. |
| 17 | |
| 18 | Treat instances as immutable; use `copy()` to derive a modified request. |
| 19 | """ |
| 20 | |
| 21 | def __init__( |
| 22 | self, |
| 23 | *, |
| 24 | options: FinalRequestOptions, |
| 25 | cast_to: Any, |
| 26 | stream: bool = False, |
| 27 | stream_cls: type[Any] | None = None, |
| 28 | retries_taken: int = 0, |
| 29 | ) -> None: |
| 30 | self.options = options |
| 31 | self.cast_to = cast_to |
| 32 | self.stream = stream |
| 33 | self.stream_cls = stream_cls |
| 34 | self.retries_taken = retries_taken |
| 35 | """The number of retries the SDK has already taken for this call. |
| 36 | |
| 37 | `0` on the first attempt; the middleware chain is invoked once per HTTP attempt. |
| 38 | """ |
| 39 | |
| 40 | @property |
| 41 | def method(self) -> str: |
| 42 | return self.options.method |
| 43 | |
| 44 | @property |
| 45 | def url(self) -> str: |
| 46 | return self.options.url |
| 47 | |
| 48 | @property |
| 49 | def headers(self) -> Headers: |
| 50 | headers = self.options.headers |
| 51 | return headers if is_given(headers) else {} |
| 52 | |
| 53 | @property |
| 54 | def query_params(self) -> Query: |
| 55 | return self.options.params |
| 56 | |
| 57 | @property |
| 58 | def json(self) -> Body | None: |
| 59 | return self.options.json_data |
| 60 | |
| 61 | @property |
| 62 | def timeout(self) -> float | httpx.Timeout | None | NotGiven: |
| 63 | return self.options.timeout |
| 64 | |
| 65 | @property |
| 66 | def max_retries(self) -> int | NotGiven: |
| 67 | return self.options.max_retries |
| 68 | |
| 69 | def copy( |
| 70 | self, |
| 71 | *, |
| 72 | method: str | NotGiven = not_given, |
no outgoing calls