Python SDK

View as MarkdownOpen in Claude

We offer a Python SDK to make interacting with our APIs simple and predictable. It is available on PyPI here. Now you can get started with our APIs with just a few lines of code.

Install our docs MCP server

This documentation ships with a Docs MCP Server that gives any MCP-enabled agent a searchDocs tool to search every page here and get back relevant passages with source URLs — no API key required. Point your client at https://you.com/docs/_mcp/server. See the Docs MCP Server guide for setup and examples.

Quickstart

1

Get an API Key

Get one for free on the You.com platform.

2

Install the SDK

$pip install youdotcom

That’s it. You now have a comprehensive set of search results combining web and news sources.

What’s next?

The Web Search API offers filters that can help you find exactly what you need, whether you want to go broader or narrower. For example, to find recent information in the United States about renewable energy from the past week limited to 10 results per source type, either web or news, write:

1from youdotcom.models import Freshness, Country
2
3results = you.search.unified(
4 query="renewable energy",
5 count=10,
6 freshness=Freshness.WEEK,
7 country=Country.US,
8)

Learn more about the Web Search API in the Web Search API reference, and the Python SDK by visiting the open source repository on GitHub.

Response Structure

The Web Search API returns a SearchResponse object (see documentation):

An array of web result objects. Each object may include url, title, description, snippets, thumbnail_url, page_age, and favicon_url.

An array of news article objects. Each object may include url, title, description, thumbnail_url, and page_age.

Information about the search query and response, including query, search_uuid, and latency.

Error Handling

Always handle potential errors when making API requests:

1import os
2from youdotcom import You, errors
3
4api_key = os.getenv("YDC_API_KEY")
5
6try:
7 with You(api_key_auth=api_key) as you:
8 results = you.search.unified(query="your query")
9 print(results)
10except errors.YouError as e:
11 print(f"Search failed: {e.message}")
12 print(f"Status code: {e.status_code}")

Learn More