| 1 | """API response object.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | from typing import Optional, Generic, Mapping, TypeVar |
| 5 | from pydantic import Field, StrictInt, StrictBytes, BaseModel |
| 6 | |
| 7 | T = TypeVar("T") |
| 8 | |
| 9 | class ApiResponse(BaseModel, Generic[T]): |
| 10 | """ |
| 11 | API response object |
| 12 | """ |
| 13 | |
| 14 | status_code: StrictInt = Field(description="HTTP status code") |
| 15 | headers: Optional[Mapping[str, str]] = Field(None, description="HTTP headers") |
| 16 | data: T = Field(description="Deserialized data given the data type") |
| 17 | raw_data: StrictBytes = Field(description="Raw data (HTTP response body)") |
| 18 | |
| 19 | model_config = { |
| 20 | "arbitrary_types_allowed": True |
| 21 | } |