# Initialize the Dappier SDK
app = Dappier()
```

Replace `<YOUR_API_KEY>` with your actual API key, which you can get from your [Dappier Account](https://platform.dappier.com/profile/api-keys).

***

## Real-Time Search

Perform a real-time search for live data:

```python Python theme={null}
response = app.search_real_time_data(
    query="What is the stock price of Apple?",
    ai_model_id="am_01j06ytn18ejftedz6dyhz2b15"
)
```

## Parameters (Real Time Search)

### `query` (string):

* A natural language query representing the information being searched for in real time.

### `ai_model_id` (string):

* The ID of the AI model to be used for real-time data search.
* This must be a valid model ID from the [Dappier Marketplace](https://marketplace.dappier.com/).

***

## AI Recommendations

Retrieve AI-powered content recommendations based on a query:

```python Python theme={null}
response = app.get_ai_recommendations(
    query="latest trending news",
    data_model_id="dm_01jagy9nqaeer9hxx8z1sk1jx6",
    similarity_top_k=5,
    ref="techcrunch.com",
    num_articles_ref=2,
    search_algorithm="most_recent"
)
```

## Parameters (AI Recommendations)

### `query` (string):

* A natural language query or URL.

### `data_model_id` (string):

* The ID of the data model to be used for recommendations.
* This must be a valid model ID from the [Dappier Marketplace](https://marketplace.dappier.com/).

### `similarity_top_k` (integer):

* The number of articles to return (default is 9).

### `ref` (string):

* The domain of the site from which the recommendations should come.
* Example: `techcrunch.com`.

### `num_articles_ref` (integer):

* Specifies how many articles should be guaranteed to match the domain specified in `ref`.
* Use this to ensure a set number of articles from the desired domain appear in the results.

### `search_algorithm` (string):

* Options: `"most_recent"` or `"semantic"`.
* `"semantic"` (default): Contextual matching of the query to retrieve articles.
* `"most_recent"`: Retrieves articles sorted by the most recent publication date.

You can select a specific Data model from the [Dappier Marketplace](https://marketplace.dappier.com/).

***

## Async Functionality

Dappier SDK supports asynchronous operations for better performance.

### Async Real Time Search:

```python Python theme={null}
import asyncio
from dappier import DappierAsync

async def fetch_real_time_data(query):
    dp_client = DappierAsync(api_key=os.environ["DAPPIER_API_KEY"])
    async with dp_client as client:
        response = await client.search_real_time_data_async(
            query=query,
            ai_model_id="am_01j06ytn18ejftedz6dyhz2b15"
        )

        if response is None:
            raise Exception("An error occurred while retrieving the response.")
        return response.message

query = "What is the stock price of Apple?"
result = asyncio.run(fetch_real_time_data(query))
print(result)
```

## Parameters (Real Time Search)

### `query` (string):

* A natural language query representing the information being searched for in real time.

### `ai_model_id` (string):

* The ID of the AI model to be used for real-time data search.
* This must be a valid model ID from the [Dappier Marketplace](https://marketplace.dappier.com/).

***

### Async AI Recommendations:

```python Python theme={null}
import asyncio
from dappier import DappierAsync

async def fetch_ai_recommendations(query):
    dp_client = DappierAsync(api_key=os.environ["DAPPIER_API_KEY"])
    async with dp_client as client:
        response = await client.get_ai_recommendations_async(
            query=query,
            data_model_id="dm_01jagy9nqaeer9hxx8z1sk1jx6",
            similarity_top_k=5,
            ref="techcrunch.com",
            num_articles_ref=2,
            search_algorithm="most_recent"
        )

        if response is None or response.status != "success":
            raise Exception("An error occurred while retrieving the response.")

        return response.results

query = "latest trending news"
result = asyncio.run(fetch_ai_recommendations(query))
print(result)
```

You can select a specific Data model from the [Dappier Marketplace](https://marketplace.dappier.com/).

The async SDK version improves performance, especially for large-scale requests.

## Parameters (AI Recommendations)

### `query` (string):

* A natural language query or URL.

### `data_model_id` (string):

* The ID of the data model to be used for recommendations.
* This must be a valid model ID from the [Dappier Marketplace](https://marketplace.dappier.com/).

### `similarity_top_k` (integer):

* The number of articles to return (default is 9).

### `ref` (string):

* The domain of the site from which the recommendations should come.
* Example: `techcrunch.com`.

### `num_articles_ref` (integer):

* Specifies how many articles should be guaranteed to match the domain specified in `ref`.
* Use this to ensure a set number of articles from the desired domain appear in the results.

### `search_algorithm` (string):

* Options: `"most_recent"` or `"semantic"`.
* `"semantic"` (default): Contextual matching of the query to retrieve articles.
* `"most_recent"`: Retrieves articles sorted by the most recent publication date.