Skip to content

Commit 4405ebe

Browse files
committed
feat: use Literal for crawler types in Apify tool
1 parent 19500c7 commit 4405ebe

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/strands_tools/apify.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
import json
5858
import logging
5959
import os
60-
from typing import Any, Dict, List, Optional
60+
from typing import Any, Dict, List, Literal, Optional, get_args
6161
from urllib.parse import urlparse
6262

6363
from rich.panel import Panel
@@ -84,7 +84,8 @@
8484
DEFAULT_DATASET_ITEMS_LIMIT = 100
8585

8686
WEBSITE_CONTENT_CRAWLER = "apify/website-content-crawler"
87-
WEBSITE_CONTENT_CRAWLER_TYPES = ("playwright:adaptive", "playwright:firefox", "cheerio")
87+
CrawlerType = Literal["playwright:adaptive", "playwright:firefox", "cheerio"]
88+
WEBSITE_CONTENT_CRAWLER_TYPES = get_args(CrawlerType)
8889

8990

9091
# --- Helper functions ---
@@ -322,7 +323,7 @@ def scrape_url(
322323
self,
323324
url: str,
324325
timeout_secs: int = DEFAULT_SCRAPE_TIMEOUT_SECS,
325-
crawler_type: str = "cheerio",
326+
crawler_type: CrawlerType = "cheerio",
326327
) -> str:
327328
"""Scrape a single URL using Website Content Crawler and return markdown."""
328329
self._validate_url(url)
@@ -608,7 +609,7 @@ def apify_run_task_and_get_dataset(
608609
def apify_scrape_url(
609610
url: str,
610611
timeout_secs: int = DEFAULT_SCRAPE_TIMEOUT_SECS,
611-
crawler_type: str = "cheerio",
612+
crawler_type: CrawlerType = "cheerio",
612613
) -> Dict[str, Any]:
613614
"""Scrape a single URL and return its content as markdown.
614615

0 commit comments

Comments
 (0)