# Data Retrieval

**Module:** `sovai.get_data`

## Classes

### `ApiRequestHandler`

```python
class ApiRequestHandler
```

Centralized handler for API requests with robust error handling, automatic retry capability, and consistent response processing.

This class encapsulates all HTTP communication logic, providing:

* Consistent authentication and headers
* Configurable retry policies with exponential backoff
* Proper error handling and logging
* Timeout management

**Attributes**

* `base_url`
* `token`
* `verify_ssl`
* `max_retries`
* `backoff_factor`
* `timeout`
* `headers` (`Dict[str, str]`)
* `logger`

**Methods**

### `__init__()`

```python
def __init__(
    self,
    base_url: str,
    token: str,
    verify_ssl: bool = True,
    max_retries: int = 3,
    backoff_factor: float = 0.5,
    timeout: tuple = (5, 30),
    logger: Optional[logging.Logger] = None,
)
```

Initialize the API request handler.

**Parameters**

| Parameter  | Type  | Description                                                                                                                                                                                                                                                                                                                                                             |
| ---------- | ----- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `base_url` | `str` | Base URL for the API token: Authentication token verify\_ssl: Whether to verify SSL certificates max\_retries: Maximum number of retry attempts for failed requests backoff\_factor: Factor to determine wait time between retries timeout: Tuple of (connection timeout, read timeout) in seconds logger: Optional logger instance; uses module logger if not provided |

***

### `get()`

```python
def get(
    self,
    endpoint: str,
    params: Optional[Dict[str, Any]] = None,
    stream: bool = False,
    body: Optional[Dict[str, Any]] = None,
) -> requests.Response
```

Make a GET request to the API with proper error handling and retry logic.

**Parameters**

| Parameter  | Type  | Description                                                                                                   |
| ---------- | ----- | ------------------------------------------------------------------------------------------------------------- |
| `endpoint` | `str` | API endpoint path params: Query parameters stream: Whether to stream the response body: Optional request body |

**Returns**

requests.Response object

***

***

## Functions

### `data()`

```python
def data(
    endpoint: str,
    tickers: Optional[Union[str, List[str]]] = None,
    chart: Optional[str] = None,
    columns: Optional[Union[str, List[str]]] = None,
    version: Optional[str] = None,
    start_date: Optional[str] = None,
    end_date: Optional[str] = None,
    plot: bool = False,
    limit: Optional[int] = None,
    params: Optional[Dict[str, Any]] = None,
    body: Optional[Dict[str, Any]] = None,
    use_polars: bool = False,
    purge_cache: bool = False,
    parquet: bool = True,
    frequency: Optional[str] = None,
    verbose: bool = False,
    full_history: bool = False,
    source: Optional[str] = None,
) -> Union[DataFrameType, go.Figure, None]
```

Main function to retrieve data from the API. Caches results to disk in 'cache/' directory (Parquet for DataFrames, Pickle for Figures). Cache files older than 12 hours are automatically cleaned up.

**Parameters**

| Parameter      | Type                              | Description      |
| -------------- | --------------------------------- | ---------------- |
| `endpoint`     | `str`                             | —                |
| `tickers`      | `Optional[Union[str, List[str]]]` | Default: `None`  |
| `chart`        | `Optional[str]`                   | Default: `None`  |
| `columns`      | `Optional[Union[str, List[str]]]` | Default: `None`  |
| `version`      | `Optional[str]`                   | Default: `None`  |
| `start_date`   | `Optional[str]`                   | Default: `None`  |
| `end_date`     | `Optional[str]`                   | Default: `None`  |
| `plot`         | `bool`                            | Default: `False` |
| `limit`        | `Optional[int]`                   | Default: `None`  |
| `params`       | `Optional[Dict[str, Any]]`        | Default: `None`  |
| `body`         | `Optional[Dict[str, Any]]`        | Default: `None`  |
| `use_polars`   | `bool`                            | Default: `False` |
| `purge_cache`  | `bool`                            | Default: `False` |
| `parquet`      | `bool`                            | Default: `True`  |
| `frequency`    | `Optional[str]`                   | Default: `None`  |
| `verbose`      | `bool`                            | Default: `False` |
| `full_history` | `bool`                            | Default: `False` |
| `source`       | `Optional[str]`                   | Default: `None`  |

**Returns:** `Union[DataFrameType, go.Figure, None]`

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sov.ai/api-reference/data.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
