# Python SDK

<figure><img src="https://github.com/oxylabs/oxylabs-ai-studio-py/raw/main/Ai-Studio2.png" alt=""><figcaption></figcaption></figure>

[![](https://camo.githubusercontent.com/ec456302fbdba5490012a0bc8d2739619d0e57dd8840197d06b33b9ea3b35bda/68747470733a2f2f646362616467652e6c696d65732e70696e6b2f6170692f7365727665722f5064733367426d4b4d483f7374796c653d666f722d7468652d6261646765267468656d653d646973636f7264)](https://discord.gg/Pds3gBmKMH) [![YouTube](https://camo.githubusercontent.com/1b748ffea39adfb777030373ce78d8bc07d3625a9039b324bcbc708a91f376c1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f596f75547562652d4f78796c6162732d7265643f7374796c653d666f722d7468652d6261646765266c6f676f3d796f7574756265266c6f676f436f6c6f723d7768697465)](https://www.youtube.com/@oxylabs)

We offer a simple Python SDK for seamlessly interacting with [Oxylabs AI Studio API](https://aistudio.oxylabs.io/) services, including AI-Scraper, AI-Crawler, AI-Browser-Agent, and other data extraction tools.

## Requirements

* python 3.10 and above
* AI Studio API key

## Installation

```
pip install oxylabs-ai-studio
```

## Usage

### Crawl (`AiCrawler.crawl`)

```python
from oxylabs_ai_studio.apps.ai_crawler import AiCrawler

crawler = AiCrawler(api_key="<API_KEY>")

url = "https://oxylabs.io"
result = crawler.crawl(
    url=url,
    user_prompt="Find all pages with proxy products pricing",
    output_format="markdown",
    render_javascript=False,
    return_sources_limit=3,
    geo_location="US",
)
print("Results:")
for item in result.data:
    print(item, "\n")
```

#### **Input parameters**

* `url` (str): Starting URL to crawl (**required**)
* `user_prompt` (str): Natural language prompt to guide extraction (**required**)
* `output_format` (Literal\["json", "markdown"]): Output format (default: "markdown")
* `schema` (dict | None): OpenAPI schema for structured extraction (required if output\_format is "json")
* `render_javascript` (bool): Render JavaScript (default: False)
* `return_sources_limit` (int): Max number of sources to return (default: 25)
* `geo_location` (str): proxy location in ISO2 format.

### Scrape (`AiScraper.scrape`)

```python
from oxylabs_ai_studio.apps.ai_scraper import AiScraper

scraper = AiScraper(api_key="<API_KEY>")

schema = scraper.generate_schema(prompt="want to parse developer, platform, type, price game title, genre (array) and description")
print(f"Generated schema: {schema}")

url = "https://sandbox.oxylabs.io/products/3"
result = scraper.scrape(
    url=url,
    output_format="json",
    schema=schema,
    render_javascript=False,
)
print(result)
```

#### **Input parameters**

* `url` (str): Target URL to scrape (**required**)
* `output_format` (Literal\["json", "markdown"]): Output format (default: "markdown")
* `schema` (dict | None): OpenAPI schema for structured extraction (required if output\_format is "json")
* `render_javascript` (bool): Render JavaScript (default: False)
* `geo_location` (str): proxy location in ISO2 format.

### Browser Agent (`BrowserAgent.run`)

```python
from oxylabs_ai_studio.apps.browser_agent import BrowserAgent

browser_agent = BrowserAgent(api_key="<API_KEY>")

schema = browser_agent.generate_schema(
    prompt="game name, platform, review stars and price"
)
print("schema: ", schema)

prompt = "Find if there is game 'super mario odyssey' in the store. If there is, find the price. Use search bar to find the game."
url = "https://sandbox.oxylabs.io/"
result = browser_agent.run(
    url=url,
    user_prompt=prompt,
    output_format="json",
    schema=schema,
)
print(result.data)
```

#### **Input parameters**

* `url` (str): Starting URL to browse (**required**)
* `user_prompt` (str): Natural language prompt for extraction (**required**)
* `output_format` (Literal\["json", "markdown", "html", "screenshot"]): Output format (default: "markdown")
* `schema` (dict | None): OpenAPI schema for structured extraction (required if output\_format is "json")
* `geo_location` (str): proxy location in ISO2 format.

### Search (`AiSearch.search`)

```python
from oxylabs_ai_studio.apps.ai_search import AiSearch


search = AiSearch(api_key="<API_KEY>")

query = "lasagna recipe"
result = search.search(
    query=query,
    limit=5,
    render_javascript=False,
    return_content=True,
)
print(result.data)
```

#### **Input parameters**

* `query` (str): What to search for (**required**)
* `limit` (int): Maximum number of results to return (default: 10, maximum: 50)
* `render_javascript` (bool): Render JavaScript (default: False)
* `return_content` (bool): Whether to return markdown contents in results (default: True)
* `geo_location` (str): search proxy location in ISO2 format.

#### Map (`AiMap.map`)

```python
from oxylabs_ai_studio.apps.ai_map import AiMap


ai_map = AiMap(api_key="<API_KEY>")
payload = {
    "url": "https://career.oxylabs.io",
    "user_prompt": "job ad pages",
    "return_sources_limit": 10,
    "geo_location": None,
    "render_javascript": False,
}
result = ai_map.map(**payload)
print(result.data)
```

#### **Input parameters**

* `url` (str): Starting URL to crawl (**required**)
* `user_prompt` (str): Natural language prompt to guide extraction (**required**)
* `render_javascript` (bool): Render JavaScript (default: False)
* `return_sources_limit` (int): Max number of sources to return (default: 25)
* `geo_location` (str): proxy location in ISO2 format.

### Usage examples

See the [examples](https://github.com/oxylabs/oxylabs-ai-studio-py/tree/main/examples) folder for usage examples of each method.&#x20;

Each method has a corresponding async version.


---

# 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://developers.oxylabs.io/scraping-solutions/ai-studio/integrations/python-sdk.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.
