from notte_sdk import NotteClientdef run(url: str, selector: str): """ Scrape data from a website. Args: url: The website URL selector: CSS selector for target element Returns: Extracted data """ client = NotteClient() with client.Session() as session: session.execute(type="goto", url=url) data = session.scrape(instructions=f"Extract content from {selector}") return {"url": url, "data": data}
from notte_sdk import NotteClientclient = NotteClient()function = client.Function( path="my_function.py", name="My Function", # Display name description="What this function does", # Description shared=False, # Private by default)
Parameters:
workflow_path (str, required): Path to your Python file
name (str, optional): Function display name
description (str, optional): What the function does
shared (bool, default=False): Whether function is publicly accessible
from notte_sdk import NotteClientfrom pydantic import BaseModelclass SearchParams(BaseModel): url: str query: str max_results: int = 10def run(params: SearchParams): # params is validated against SearchParams model client = NotteClient() # Use params.url, params.query, etc.
# Define your function (from your scraper_function.py)def run(url: str, selector: str) -> dict: # Your scraping logic here return {"url": url, "selector": selector}# Test with sample parametersresult = run(url="https://example.com", selector=".content")print(result)
from notte_sdk import NotteClientclient = NotteClient()# Load existing function with decryption key for local executionfunction = client.Function( function_id="func_abc123", decryption_key="your-decryption-key", # Required for local execution)# Run locally (not on cloud)result = function.run(local=True, url="https://example.com")print(result.result)
def run(url: str, max_retries: int = 3): """ Fetch data from a website with retries. Args: url: The website URL to scrape max_retries: Number of retry attempts on failure (default: 3) Returns: Dict with 'success' (bool) and 'data' (any) keys """ pass
from notte_sdk import NotteClientdef run(url: str): client = NotteClient() # Set session timeout with client.Session(idle_timeout_minutes=5) as session: session.execute(type="goto", url=url) data = session.scrape() return data
def run(url: str, count: int): # Validate inputs if not url.startswith("http"): return {"error": "Invalid URL format"} if count < 1 or count > 100: return {"error": "Count must be between 1 and 100"} # Proceed with automation pass