crewai-scrapingrabbit 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ test:
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ matrix:
16
+ include:
17
+ - python: "3.11"
18
+ crewai: "crewai==0.100.*" # oldest supported
19
+ - python: "3.13"
20
+ crewai: "crewai" # newest
21
+ env:
22
+ CREWAI_DISABLE_TELEMETRY: "true"
23
+ steps:
24
+ - uses: actions/checkout@v4
25
+ - uses: actions/setup-python@v5
26
+ with:
27
+ python-version: ${{ matrix.python }}
28
+ - run: python -m pip install . "${{ matrix.crewai }}"
29
+ - run: python -m unittest discover -s tests
@@ -0,0 +1,45 @@
1
+ name: Publish to PyPI
2
+
3
+ # Push a version tag (for example v0.1.0 after bumping `version` in pyproject.toml) and this publishes that commit.
4
+ # No PyPI token is stored: PyPI trusts this workflow through "trusted publishing" (OIDC), set once on pypi.org
5
+ # (repo scrapingrabbit/crewai-scrapingrabbit, workflow publish.yml, environment pypi).
6
+ on:
7
+ push:
8
+ tags: ["v*"]
9
+
10
+ permissions:
11
+ contents: read
12
+
13
+ jobs:
14
+ build:
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+ - uses: actions/setup-python@v5
19
+ with:
20
+ python-version: "3.12"
21
+ - name: Tag must match pyproject.toml
22
+ run: |
23
+ PKG="v$(python -c "import tomllib;print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")"
24
+ if [ "$GITHUB_REF_NAME" != "$PKG" ]; then echo "Tag $GITHUB_REF_NAME does not match pyproject.toml $PKG"; exit 1; fi
25
+ - run: python -m pip install build twine .
26
+ - run: python -m unittest discover -s tests
27
+ - run: python -m build
28
+ - run: python -m twine check --strict dist/*
29
+ - uses: actions/upload-artifact@v4
30
+ with:
31
+ name: dist
32
+ path: dist/
33
+
34
+ publish:
35
+ needs: build
36
+ runs-on: ubuntu-latest
37
+ environment: pypi
38
+ permissions:
39
+ id-token: write
40
+ steps:
41
+ - uses: actions/download-artifact@v4
42
+ with:
43
+ name: dist
44
+ path: dist/
45
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,6 @@
1
+ __pycache__/
2
+ *.pyc
3
+ dist/
4
+ .venv/
5
+ *.egg-info/
6
+ .env
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ScrapingRabbit
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,80 @@
1
+ Metadata-Version: 2.5
2
+ Name: crewai-scrapingrabbit
3
+ Version: 0.1.0
4
+ Summary: CrewAI tools for the ScrapingRabbit web data API: YouTube transcripts and comments, TikTok, Instagram, X, Amazon, Google and SEO data for your crews.
5
+ Project-URL: Homepage, https://scrapingrabbit.com
6
+ Project-URL: Documentation, https://scrapingrabbit.com/docs
7
+ Project-URL: Repository, https://github.com/scrapingrabbit/crewai-scrapingrabbit
8
+ Project-URL: Issues, https://github.com/scrapingrabbit/crewai-scrapingrabbit/issues
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: agents,crewai,crewai-tools,instagram,scraping,seo,tiktok,youtube-transcript
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
15
+ Requires-Python: >=3.10
16
+ Requires-Dist: crewai>=0.100.0
17
+ Requires-Dist: scrapingrabbit<1.0.0,>=0.2.0
18
+ Description-Content-Type: text/markdown
19
+
20
+ # crewai-scrapingrabbit
21
+
22
+ CrewAI tools for the [ScrapingRabbit](https://scrapingrabbit.com) web data API: YouTube transcripts and comments, TikTok, Instagram, X, Amazon, Google and SEO data for your crews.
23
+
24
+ - Every API endpoint as a CrewAI tool, with typed, described arguments.
25
+ - API refusals come back to the agent as text it can act on.
26
+ - You pay credits only when a call returns data. Failed calls are free.
27
+ - New accounts get 100 free credits and a first key, no card needed: [scrapingrabbit.com/login](https://scrapingrabbit.com/login).
28
+
29
+ ## Install
30
+
31
+ ```bash
32
+ pip install crewai-scrapingrabbit
33
+ export SCRAPINGRABBIT_API_KEY=sr_live_...
34
+ ```
35
+
36
+ ## Use
37
+
38
+ The crew also needs a model key for CrewAI itself (`OPENAI_API_KEY` by default, or set `llm=` on the agent).
39
+
40
+ ```python
41
+ from crewai import Agent, Crew, Task
42
+ from crewai_scrapingrabbit import scrapingrabbit_tools
43
+
44
+ researcher = Agent(
45
+ role="Video researcher",
46
+ goal="Summarise YouTube videos accurately",
47
+ backstory="You read transcripts before you write.",
48
+ tools=scrapingrabbit_tools(include=["youtube_transcript", "youtube_tag_extractor"]),
49
+ )
50
+ task = Task(
51
+ description="Summarise https://www.youtube.com/watch?v=dQw4w9WgXcQ in five bullet points.",
52
+ expected_output="Five bullet points",
53
+ agent=researcher,
54
+ )
55
+ print(Crew(agents=[researcher], tasks=[task]).kickoff())
56
+ ```
57
+
58
+ Leave out `include` to get every endpoint. Names come from `scrapingrabbit.ENDPOINTS`:
59
+
60
+ ```python
61
+ from scrapingrabbit import ENDPOINTS
62
+ print([e["name"] for e in ENDPOINTS])
63
+ ```
64
+
65
+ Each tool returns the answer's data as JSON text, cut at 60,000 characters (change with `max_chars=`).
66
+
67
+ ## Also available
68
+
69
+ [LangChain tools](https://github.com/scrapingrabbit/langchain-scrapingrabbit) · [Python client](https://github.com/scrapingrabbit/scrapingrabbit-python) · [Node.js client](https://github.com/scrapingrabbit/scrapingrabbit-node) · [MCP server](https://github.com/scrapingrabbit/scrapingrabbit-mcp)
70
+
71
+ ## Develop
72
+
73
+ ```bash
74
+ pip install -e .
75
+ python -m unittest discover -s tests # runs the tools against a local fake API
76
+ ```
77
+
78
+ ## License
79
+
80
+ MIT
@@ -0,0 +1,61 @@
1
+ # crewai-scrapingrabbit
2
+
3
+ CrewAI tools for the [ScrapingRabbit](https://scrapingrabbit.com) web data API: YouTube transcripts and comments, TikTok, Instagram, X, Amazon, Google and SEO data for your crews.
4
+
5
+ - Every API endpoint as a CrewAI tool, with typed, described arguments.
6
+ - API refusals come back to the agent as text it can act on.
7
+ - You pay credits only when a call returns data. Failed calls are free.
8
+ - New accounts get 100 free credits and a first key, no card needed: [scrapingrabbit.com/login](https://scrapingrabbit.com/login).
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ pip install crewai-scrapingrabbit
14
+ export SCRAPINGRABBIT_API_KEY=sr_live_...
15
+ ```
16
+
17
+ ## Use
18
+
19
+ The crew also needs a model key for CrewAI itself (`OPENAI_API_KEY` by default, or set `llm=` on the agent).
20
+
21
+ ```python
22
+ from crewai import Agent, Crew, Task
23
+ from crewai_scrapingrabbit import scrapingrabbit_tools
24
+
25
+ researcher = Agent(
26
+ role="Video researcher",
27
+ goal="Summarise YouTube videos accurately",
28
+ backstory="You read transcripts before you write.",
29
+ tools=scrapingrabbit_tools(include=["youtube_transcript", "youtube_tag_extractor"]),
30
+ )
31
+ task = Task(
32
+ description="Summarise https://www.youtube.com/watch?v=dQw4w9WgXcQ in five bullet points.",
33
+ expected_output="Five bullet points",
34
+ agent=researcher,
35
+ )
36
+ print(Crew(agents=[researcher], tasks=[task]).kickoff())
37
+ ```
38
+
39
+ Leave out `include` to get every endpoint. Names come from `scrapingrabbit.ENDPOINTS`:
40
+
41
+ ```python
42
+ from scrapingrabbit import ENDPOINTS
43
+ print([e["name"] for e in ENDPOINTS])
44
+ ```
45
+
46
+ Each tool returns the answer's data as JSON text, cut at 60,000 characters (change with `max_chars=`).
47
+
48
+ ## Also available
49
+
50
+ [LangChain tools](https://github.com/scrapingrabbit/langchain-scrapingrabbit) · [Python client](https://github.com/scrapingrabbit/scrapingrabbit-python) · [Node.js client](https://github.com/scrapingrabbit/scrapingrabbit-node) · [MCP server](https://github.com/scrapingrabbit/scrapingrabbit-mcp)
51
+
52
+ ## Develop
53
+
54
+ ```bash
55
+ pip install -e .
56
+ python -m unittest discover -s tests # runs the tools against a local fake API
57
+ ```
58
+
59
+ ## License
60
+
61
+ MIT
@@ -0,0 +1,4 @@
1
+ """CrewAI tools for the ScrapingRabbit web data API."""
2
+ from .tools import ScrapingRabbitTool, scrapingrabbit_tools
3
+
4
+ __all__ = ["ScrapingRabbitTool", "scrapingrabbit_tools"]
@@ -0,0 +1,89 @@
1
+ """One CrewAI tool per ScrapingRabbit endpoint, built from the SDK's ENDPOINTS list.
2
+
3
+ A new API endpoint shows up here after `pip install -U scrapingrabbit`; nothing in this package lists endpoints by hand.
4
+ """
5
+ import json
6
+ from typing import Any, Dict, List, Optional, Type
7
+
8
+ from crewai.tools import BaseTool
9
+ from pydantic import BaseModel, Field, PrivateAttr, create_model
10
+ from scrapingrabbit import ENDPOINTS, ScrapingRabbit, ScrapingRabbitError
11
+
12
+ # Long answers (a full transcript, a big search page) are cut here so one call cannot flood the model's context.
13
+ DEFAULT_MAX_CHARS = 60_000
14
+ TOOL_PREFIX = "scrapingrabbit_"
15
+ # Every refusal this package returns ends with this, so the cache check can recognise it.
16
+ REFUSAL_SUFFIX = " (failed calls are not charged)"
17
+
18
+
19
+ def _cache_unless_refused(_arguments: Any = None, result: Any = None) -> bool:
20
+ """CrewAI's cache hook: keep answers, never keep a refusal (a rate limit or timeout may pass on retry)."""
21
+ return not (isinstance(result, str) and result.endswith(REFUSAL_SUFFIX))
22
+
23
+
24
+ def _input_model(endpoint: Dict[str, Any]) -> Type[BaseModel]:
25
+ fields: Dict[str, Any] = {}
26
+ for param in endpoint["params"]:
27
+ if param["required"]:
28
+ fields[param["name"]] = (str, Field(..., description=param["description"]))
29
+ else:
30
+ fields[param["name"]] = (Optional[str], Field(None, description=param["description"]))
31
+ model_name = "".join(part.capitalize() for part in endpoint["name"].split("_")) + "Input"
32
+ return create_model(model_name, **fields)
33
+
34
+
35
+ def _as_text(data: Any, max_chars: int) -> str:
36
+ text = json.dumps(data, ensure_ascii=False)
37
+ if len(text) > max_chars:
38
+ return f"{text[:max_chars]}\n[cut at {max_chars} characters]"
39
+ return text
40
+
41
+
42
+ class ScrapingRabbitTool(BaseTool):
43
+ """Calls one ScrapingRabbit endpoint. Refusals are returned as text so the agent can adjust, not raised."""
44
+
45
+ name: str
46
+ description: str
47
+ args_schema: Type[BaseModel]
48
+ endpoint: str
49
+ max_chars: int = DEFAULT_MAX_CHARS
50
+ _client: Any = PrivateAttr()
51
+
52
+ def __init__(self, client: Any, endpoint: Dict[str, Any], max_chars: int = DEFAULT_MAX_CHARS, **kwargs: Any):
53
+ super().__init__(
54
+ name=TOOL_PREFIX + endpoint["name"],
55
+ description=endpoint["description"],
56
+ args_schema=_input_model(endpoint),
57
+ endpoint=endpoint["name"],
58
+ max_chars=max_chars,
59
+ cache_function=kwargs.pop("cache_function", _cache_unless_refused),
60
+ **kwargs,
61
+ )
62
+ self._client = client
63
+
64
+ def _run(self, **kwargs: Any) -> str:
65
+ method = getattr(self._client, self.endpoint)
66
+ try:
67
+ data = method(**{name: value for name, value in kwargs.items() if value is not None})
68
+ except ScrapingRabbitError as error:
69
+ return f"{error.code}: {error.message}{REFUSAL_SUFFIX}"
70
+ return _as_text(data, self.max_chars)
71
+
72
+
73
+ def scrapingrabbit_tools(
74
+ api_key: Optional[str] = None,
75
+ include: Optional[List[str]] = None,
76
+ max_chars: int = DEFAULT_MAX_CHARS,
77
+ client: Optional[Any] = None,
78
+ ) -> List[BaseTool]:
79
+ """Every ScrapingRabbit endpoint as a CrewAI tool (or only those named in `include`).
80
+
81
+ Reads SCRAPINGRABBIT_API_KEY unless `api_key` or a configured `client` is given. Names are in scrapingrabbit.ENDPOINTS.
82
+ """
83
+ known = {endpoint["name"] for endpoint in ENDPOINTS}
84
+ if include is not None:
85
+ unknown = sorted(set(include) - known)
86
+ if unknown:
87
+ raise ValueError(f"Unknown ScrapingRabbit endpoints: {', '.join(unknown)}. Valid names are in scrapingrabbit.ENDPOINTS.")
88
+ client = client or ScrapingRabbit(api_key=api_key)
89
+ return [ScrapingRabbitTool(client, endpoint, max_chars) for endpoint in ENDPOINTS if include is None or endpoint["name"] in include]
@@ -0,0 +1,27 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "crewai-scrapingrabbit"
7
+ version = "0.1.0"
8
+ description = "CrewAI tools for the ScrapingRabbit web data API: YouTube transcripts and comments, TikTok, Instagram, X, Amazon, Google and SEO data for your crews."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ requires-python = ">=3.10"
12
+ dependencies = ["crewai>=0.100.0", "scrapingrabbit>=0.2.0,<1.0.0"]
13
+ keywords = ["crewai", "crewai-tools", "agents", "scraping", "youtube-transcript", "tiktok", "instagram", "seo"]
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "Operating System :: OS Independent",
17
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
18
+ ]
19
+
20
+ [project.urls]
21
+ Homepage = "https://scrapingrabbit.com"
22
+ Documentation = "https://scrapingrabbit.com/docs"
23
+ Repository = "https://github.com/scrapingrabbit/crewai-scrapingrabbit"
24
+ Issues = "https://github.com/scrapingrabbit/crewai-scrapingrabbit/issues"
25
+
26
+ [tool.hatch.build.targets.wheel]
27
+ packages = ["crewai_scrapingrabbit"]
@@ -0,0 +1,90 @@
1
+ """Runs the tools through the real scrapingrabbit client against a local HTTP server that plays the API."""
2
+ import json
3
+ import threading
4
+ import unittest
5
+ from http.server import BaseHTTPRequestHandler, HTTPServer
6
+ from urllib.parse import parse_qs, urlparse
7
+
8
+ from scrapingrabbit import ENDPOINTS, ScrapingRabbit
9
+
10
+ from crewai_scrapingrabbit import scrapingrabbit_tools
11
+
12
+ REQUESTS = []
13
+
14
+
15
+ class Handler(BaseHTTPRequestHandler):
16
+ def do_GET(self):
17
+ url = urlparse(self.path)
18
+ REQUESTS.append({"path": url.path, "query": parse_qs(url.query), "key": self.headers.get("x-api-key")})
19
+ if parse_qs(url.query).get("url") == ["nocaptions"]:
20
+ status, body = 404, {"success": False, "code": "UPSTREAM_NOT_FOUND", "message": "This video has no captions"}
21
+ else:
22
+ status, body = 200, {"success": True, "data": {"path": url.path, "big": "x" * 500}}
23
+ payload = json.dumps(body).encode()
24
+ self.send_response(status)
25
+ self.send_header("content-type", "application/json")
26
+ self.send_header("content-length", str(len(payload)))
27
+ self.end_headers()
28
+ self.wfile.write(payload)
29
+
30
+ def log_message(self, *args):
31
+ pass
32
+
33
+
34
+ class CrewAITests(unittest.TestCase):
35
+ @classmethod
36
+ def setUpClass(cls):
37
+ cls.server = HTTPServer(("127.0.0.1", 0), Handler)
38
+ threading.Thread(target=cls.server.serve_forever, daemon=True).start()
39
+ cls.client = ScrapingRabbit("sr_live_testkey", base_url=f"http://127.0.0.1:{cls.server.server_port}/v1", max_retries=0)
40
+
41
+ @classmethod
42
+ def tearDownClass(cls):
43
+ cls.server.shutdown()
44
+
45
+ def setUp(self):
46
+ REQUESTS.clear()
47
+
48
+ def tools(self, **kwargs):
49
+ return {tool.name: tool for tool in scrapingrabbit_tools(client=self.client, **kwargs)}
50
+
51
+ def test_one_tool_per_endpoint_with_param_descriptions(self):
52
+ tools = self.tools()
53
+ self.assertEqual(len(tools), len(ENDPOINTS))
54
+ schema = tools["scrapingrabbit_youtube_comment_extractor"].args_schema.model_json_schema()
55
+ self.assertEqual(schema["required"], ["url"])
56
+ self.assertIn("next_page_token", schema["properties"])
57
+ self.assertTrue(schema["properties"]["url"]["description"])
58
+
59
+ def test_tool_call_sends_only_given_params_and_returns_json_text(self):
60
+ result = self.tools()["scrapingrabbit_youtube_comment_extractor"].run(url="https://youtu.be/abc")
61
+ self.assertEqual(REQUESTS[0]["path"], "/v1/youtube/comments")
62
+ self.assertEqual(REQUESTS[0]["query"], {"url": ["https://youtu.be/abc"]})
63
+ self.assertEqual(REQUESTS[0]["key"], "sr_live_testkey")
64
+ self.assertEqual(json.loads(result)["path"], "/v1/youtube/comments")
65
+
66
+ def test_refusal_is_returned_as_text(self):
67
+ result = self.tools()["scrapingrabbit_youtube_transcript"].run(url="nocaptions")
68
+ self.assertEqual(result, "UPSTREAM_NOT_FOUND: This video has no captions (failed calls are not charged)")
69
+
70
+ def test_refusals_are_not_cached_but_answers_are(self):
71
+ # CrewAI caches tool results when crew caching is on (the default in older versions); a rate limit or
72
+ # timeout must not be replayed from cache for the rest of the run.
73
+ tool = self.tools()["scrapingrabbit_youtube_transcript"]
74
+ refusal = tool.run(url="nocaptions")
75
+ answer = tool.run(url="https://youtu.be/abc")
76
+ self.assertFalse(tool.cache_function({"url": "nocaptions"}, refusal))
77
+ self.assertTrue(tool.cache_function({"url": "https://youtu.be/abc"}, answer))
78
+
79
+ def test_long_answers_are_cut(self):
80
+ result = self.tools(max_chars=100)["scrapingrabbit_account_credits"].run()
81
+ self.assertTrue(result.endswith("[cut at 100 characters]"))
82
+
83
+ def test_include_limits_tools_and_rejects_unknown_names(self):
84
+ self.assertEqual(list(self.tools(include=["youtube_transcript"])), ["scrapingrabbit_youtube_transcript"])
85
+ with self.assertRaises(ValueError):
86
+ self.tools(include=["no_such_endpoint"])
87
+
88
+
89
+ if __name__ == "__main__":
90
+ unittest.main()