> ## Documentation Index
> Fetch the complete documentation index at: https://relevanceai.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Python Helper Functions

> Natively Supported Helper Functions

This client provides an interface to interact with the Relevance API. It includes functions to run various steps, insert and retrieve data, and upload temporary files.

## **Functions**

### Insert data

```python Python theme={null}
insert_data(dataset_id: str, data: List[Dict[str, Any]])
```

Inserts data into a Relevance dataset.

**Arguments**

* `dataset_id`: The ID of the dataset to insert into.
* `data`: A list of dictionaries containing the data to insert.

**Returns**

* The response from the API as a JSON object.

### Retrieve data

```python Python theme={null}
retrieve_data(dataset_id: str, page_size: int = None, include_fields: List[str] = None)
```

Retrieves data from a Relevance dataset.

**Arguments**

* `dataset_id`: The ID of the dataset to retrieve from.
* `page_size`: The number of results to return per page (optional).
* `include_fields`: A list of fields to include in the response (optional).

**Returns**

* The response from the API as a JSON object.

### Retrieve All Data

```python Python theme={null}
retrieve_all(dataset_id: str, page_size: int = 1000, include_fields: List[str] = None) -> List[Dict[str, Any]]:
```

Retrieves all data from a Relevance dataset, paginated to handle large datasets.

**Arguments**

* `dataset_id`: The ID of the dataset to retrieve from.
* `page_size`: The number of results to return per page. Defaults to 1000 (optional).
* `include_fields`: A list of fields to include in the response. Defaults to None (optional).

**Returns**

* A list of dictionaries containing the retrieved data. Each dictionary represents a document from the dataset.

Example

### Upload a temporary file

```python Python theme={null}
insert_temp_file(file_path_or_bytes: str, ext: str = None)
```

Uploads a temporary file to Relevance.

**Arguments**

* `file_path_or_bytes`: The path to the file or the file contents as bytes.
* `ext`: The file extension (optional).

**Returns**

* A dictionary containing the download URL of the uploaded file.

### Prompt completion

```python Python theme={null}
prompt_completion(prompt: str, model: int = None)
```

Runs the `prompt_completion` step with the given prompt and model.

**Arguments**

* `prompt`: The prompt to complete.
* `model`: The model to use for completion (optional).

**Returns**

* The response from the API as a JSON object.

### Run a step

```python Python theme={null}
run_step(step_name: str, params: Dict[str, Any])
```

Runs a Relevance step with the given name and parameters.

**Arguments**

* `step_name`: The name of the step to run.
* `params`: A dictionary of parameters to pass to the step.

**Returns**

* The response from the API as a JSON object.

## **Classes**

### Integration

```python Python theme={null}
Integration(provider_name: str, account_id: str)
```

The `Integration` class provides a convenient way to make authenticated API calls to OAuth-connected services in your Python code. It automatically handles OAuth token management and makes authenticated requests to third-party APIs.

**Constructor Arguments**

* `provider_name`: The name of the OAuth provider/integration (e.g., `'dataforseo'`, `'hubspot'`, `'slack'`).
* `account_id`: The account ID from your OAuth account input. This is accessed via `params['your_oauth_input_name']` where `your_oauth_input_name` is the variable name of your OAuth account input.

**Methods**

#### api\_call()

```python Python theme={null}
integration.api_call(method: str, url: str, body: Dict[str, Any] = None, headers: Dict[str, str] = None, params: Dict[str, Any] = None)
```

Makes an authenticated HTTP request to the specified URL using the OAuth credentials associated with the integration.

**Arguments**

* `method`: The HTTP method to use (e.g., `'GET'`, `'POST'`, `'PUT'`, `'DELETE'`).
* `url`: The full URL endpoint to make the request to.
* `body`: Optional dictionary or list containing the request body (for POST, PUT, etc.). Supports both JSON objects (dictionaries) and JSON arrays (lists). Will be automatically serialized to JSON.
* `headers`: Optional dictionary of additional HTTP headers to include in the request.
* `params`: Optional dictionary of query parameters to append to the URL.

**Returns**

* The API response as a parsed JSON object (dictionary). The response is automatically parsed, so you can directly access the data without additional JSON parsing.

## **Usage Examples**

### Insert data

```python Python theme={null}
data = [{"field1": "value1", "field2": "value2"}, {"field1": "value3", "field2": "value4"}]
response = insert_data("my_dataset", data)
```

### Retrieve data

```python Python theme={null}
response = retrieve_data("my_dataset", page_size=10, include_fields=["field1", "field2"])
```

### Retrieve all

```python Python theme={null}
response = retrieve_all("my_dataset", page_size=500, include_fields=["field1", "field2"])
```

### Upload a temporary file

Note: Make sure to replace the `region` variable with your actual region.

```python Python theme={null}
file_path = "path/to/file.txt"
response = insert_temp_file(file_path)
```

### Prompt completion

```python Python theme={null}
response = prompt_completion("My prompt", model="openai-gpt35")
```

### Run a step

```python Python theme={null}
response = run_step("my_step", {"param1": "value1", "param2": "value2"})
```

### Integration

```python Python theme={null}
# Get OAuth account ID from input parameter
account_id = params['my_oauth_account']

# Create Integration instance
integration = Integration('google', account_id)

# Make authenticated API call with object body
response = integration.api_call(
    method='GET',
    url='https://www.googleapis.com/oauth2/v2/userinfo',
    params={'limit': 10}
)

# Access the parsed JSON response
user_info = response
```

### Integration with Array Body

```python Python theme={null}
# Example: Bulk update operation with array body
account_id = params['my_oauth_account']
integration = Integration('confluence', account_id)

# Make API call with array body
response = integration.api_call(
    method='PUT',
    url='https://your-domain.atlassian.net/wiki/api/v2/pages/123/properties',
    body=[
        {"key": "status", "value": "reviewed"},
        {"key": "priority", "value": "high"}
    ],
    headers={'accept': 'application/json'}
)
```
