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

# Google

> Search Google, Images, News, and Maps

## Overview

Search Google for web results, images, news, and places through a simple Python interface.

```python theme={null}
from ziet.integrations import google

# Search Google
results = google.search("best restaurants in SF")

# Search images
images = google.images("golden gate bridge")

# Search news
news = google.news("latest AI developments")

# Search maps/places
places = google.maps("coffee shops", location="San Francisco")
```

## How It Works

### Default (Ziet's Keys)

No setup required - start searching immediately:

```python theme={null}
from ziet.integrations import google

results = google.search("machine learning")
```

**Free tier**: 100 searches/day

### Bring Your Own Keys

For higher limits:

1. Get API key from [Google Cloud Console](https://console.cloud.google.com)
2. Get Search Engine ID from [Programmable Search Engine](https://programmablesearchengine.google.com)
3. Add both to [Ziet Dashboard](https://dashboard.ziet.ai/integrations) → **Google**

Your code stays the same - Ziet uses your keys automatically.

## Methods

### search()

Search Google for web results:

```python theme={null}
results = google.search(
    query="python tutorials",
    num_results=10
)
```

**Parameters**:

* `query` (string, required): Search query
* `num_results` (int, default 10): Number of results (max 100)

**Returns**:

```python theme={null}
[
    {
        "title": "Learn Python - Tutorial",
        "url": "https://example.com/python",
        "snippet": "Complete Python tutorial for beginners...",
        "position": 1
    },
    ...
]
```

**Example**:

```python theme={null}
from ziet import Action, memory
from ziet.integrations import google

@Action(
    id="search_python",
    name="Search Python",
    description="Search for Python tutorials"
)
def search_python() -> None:
    results = google.search("python tutorials", num_results=10)
    memory.add(key="search_results", value=results)
```

### images()

Search Google Images:

```python theme={null}
images = google.images(
    query="golden gate bridge",
    num_results=10
)
```

**Returns**:

```python theme={null}
[
    {
        "title": "Golden Gate Bridge",
        "url": "https://example.com/image.jpg",
        "thumbnail": "https://example.com/thumb.jpg",
        "width": 1920,
        "height": 1080
    },
    ...
]
```

### news()

Search Google News:

```python theme={null}
news = google.news(
    query="artificial intelligence",
    num_results=10
)
```

**Returns**:

```python theme={null}
[
    {
        "title": "Latest AI Breakthrough",
        "url": "https://news.example.com/article",
        "snippet": "Scientists announce major advancement...",
        "source": "Tech News",
        "published": "2 hours ago"
    },
    ...
]
```

### maps()

Search Google Maps/Places:

```python theme={null}
places = google.maps(
    query="coffee shops",
    location="San Francisco, CA"
)
```

**Returns**:

```python theme={null}
[
    {
        "name": "Blue Bottle Coffee",
        "address": "66 Mint St, San Francisco, CA 94103",
        "rating": 4.5,
        "reviews": 1234,
        "phone": "+1 510-653-3394",
        "hours": "Open until 6:00 PM"
    },
    ...
]
```

## Complete Example

```python theme={null}
from ziet import Action, Agent, memory
from ziet.integrations import google, openai

@Action(
    id="search_topic",
    name="Search Topic",
    description="Search Google for a topic"
)
def search_topic(topic: str) -> None:
    results = google.search(topic, num_results=10)
    memory.add(key="search_results", value=results)

@Action(
    id="get_news",
    name="Get News",
    description="Get latest news on topic"
)
def get_news(topic: str) -> None:
    news = google.news(topic, num_results=5)
    memory.add(key="news_results", value=news)

@Action(
    id="summarize_findings",
    name="Summarize Findings",
    description="Summarize research findings"
)
def summarize_findings() -> None:
    search = memory.get("search_results")
    news = memory.get("news_results")
    
    prompt = f"Summarize this research:\n\nWeb: {search}\n\nNews: {news}"
    summary = openai.chat([{"role": "user", "content": prompt}])
    
    memory.add(key="final_summary", value=summary)

@Agent(
    id="research_agent",
    name="ResearchAgent",
    instructions="""
    Research a topic comprehensively:
    1. Search Google for web results
    2. Get latest news
    3. Summarize all findings
    Store everything in memory for later retrieval.
    """,
    actions=["search_topic", "get_news", "summarize_findings"]
)
class ResearchAgent:
    pass
```

## Best Practices

<AccordionGroup>
  <Accordion title="Cache results" icon="database">
    Avoid redundant searches:

    ```python theme={null}
    from ziet import memory

    # Check cache first
    cached = memory.get(f"search_{query}")
    if cached:
        return

    # Search and cache
    results = google.search(query)
    memory.add(key=f"search_{query}", value=results)
    ```
  </Accordion>

  <Accordion title="Filter results" icon="filter">
    Post-process for better quality:

    ```python theme={null}
    results = google.search("python tutorials")

    # Filter by domain
    official = [r for r in results if "python.org" in r["url"]]

    # Filter by keywords
    advanced = [r for r in results if "advanced" in r["title"].lower()]
    ```
  </Accordion>

  <Accordion title="Handle errors" icon="shield">
    ```python theme={null}
    from ziet import Action, memory
    from ziet.integrations import google

    @Action(
        id="safe_search",
        name="Safe Search",
        description="Search with error handling",
        retries=2
    )
    def safe_search(query: str) -> None:
        try:
            results = google.search(query)
            memory.add(key="results", value=results)
        except Exception as e:
            memory.add(key="error", value=str(e))
            memory.add(key="results", value=[])
    ```
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Apify" icon="spider-web">
    Scrape search results for detailed data
  </Card>

  <Card title="OpenAI" icon="openai">
    Summarize search results with AI
  </Card>

  <Card title="Memory" icon="database" href="/core/memory">
    Cache and store search results
  </Card>

  <Card title="Actions" icon="bolt" href="/core/actions">
    Build search actions
  </Card>
</CardGroup>
