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 | self._client_headers = httpx2.Headers() |
| 40 | """The entries of `headers` that came from the client rather than from the call.""" |
| 41 | |
| 42 | @property |
| 43 | def method(self) -> str: |
| 44 | return self.options.method |
| 45 | |
| 46 | @property |
| 47 | def url(self) -> str: |
| 48 | return self.options.url |
| 49 | |
| 50 | @property |
| 51 | def headers(self) -> Headers: |
| 52 | """The client's default headers merged with this call's headers, including credentials such as the API key. |
| 53 | |
| 54 | The client's header names are lowercase, and the call's keep their casing. |
| 55 | Leaving a client header out of `copy(headers=...)` still sends it; set it to `omit` to remove it. |
| 56 | """ |
| 57 | headers = self.options.headers |
| 58 | return headers if is_given(headers) else {} |
| 59 | |
| 60 | @property |
| 61 | def query_params(self) -> Query: |
| 62 | return self.options.params |
| 63 | |
| 64 | @property |
| 65 | def json(self) -> Body | None: |
| 66 | return self.options.json_data |
| 67 | |
| 68 | @property |
| 69 | def timeout(self) -> float | httpx2.Timeout | None | NotGiven: |
| 70 | return self.options.timeout |
| 71 | |
| 72 | @property |
no outgoing calls